Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 Dec 1995 21:50:48 -0800 (PST)
From:      Julian Elischer <julian@ref.tfs.com>
To:        wine-new@amscons.com
Cc:        hackers@freebsd.org, ports@freebsd.org
Subject:   Slightly better patch for FreeBSD readdir() fix
Message-ID:  <199512020550.VAA00807@ref.tfs.com>

next in thread | raw e-mail | index | archive | help
Here is a slightly better patch to dos_fs.c in WINE.

the last one was basically the same but had a couple of
unreferenced variables in certain cases.. 

I've also cleaned it up a bit

#-------cut here-------------
*** dos_fs.c.orig	Fri Nov 24 04:59:40 1995
--- dos_fs.c	Fri Dec  1 18:47:21 1995
***************
*** 858,901 ****
      strncpy(dirname, unixdirname, len);
      dirname[len] = 0;
      unixdirname = strrchr(unixdirname, '/') + 1;
-     if ((ds = opendir(dirname)) == NULL)
-         return NULL;
  
      dp = DosDirs;
      while (dp)
      {
!         if (dp->inuse)
              break;
          if (strcmp(dp->unixpath, dirname) == 0)
              break;
          dp = dp->next;
      }
      if (!dp)
      {
          dp = xmalloc(sizeof(struct dosdirent));
          dp->next = DosDirs;
          DosDirs = dp;
      }
      
      strncpy(dp->filemask, unixdirname, 12);
      dp->filemask[12] = 0;
      dprintf_dosfs(stddeb,"DOS_opendir: %s / %s\n", unixdirname, dirname);
  
-     dp->inuse = 1;
      strcpy(dp->unixpath, dirname);
      dp->entnum = 0;
  
-     if ((dp->telldirnum=telldir(ds)) == -1)
-     {
-         dp->inuse = 0;
- 	closedir(ds);
- 	return NULL;
-     }
-     if (closedir(ds) == -1) 
-     {
-         dp->inuse = 0;
-         return NULL;
-     }
      return dp;
  }
  
--- 858,916 ----
      strncpy(dirname, unixdirname, len);
      dirname[len] = 0;
      unixdirname = strrchr(unixdirname, '/') + 1;
  
      dp = DosDirs;
+     /* try reuse it if we have already done this directory.. odd */
      while (dp)
      {
!         if (!dp->inuse) /* I think this test was reversed before */
! 	{
!     	    dp->inuse = 1;
! 	    dp->ds == NULL;
              break;
+ 	}
          if (strcmp(dp->unixpath, dirname) == 0)
+ 	{
              break;
+ 	}
          dp = dp->next;
      }
      if (!dp)
      {
          dp = xmalloc(sizeof(struct dosdirent));
+ 	dp->ds = NULL;
+     	dp->inuse = 1;
          dp->next = DosDirs;
          DosDirs = dp;
      }
+     if (! dp->ds)
+     {
+         if ((dp->ds = ds = opendir(dirname)) == NULL)
+ 	{
+             dp->inuse = 0;
+             return NULL;
+ 	}
+     }
+     else
+     {
+       ds = dp->ds;
+       rewinddir(dp->ds);
+     }
+ #ifdef NEEDSEEK
+     if ((dp->telldirnum=telldir(ds)) == -1)
+     {
+ 	DOS_closedir(dp);
+ 	return NULL;
+     }
+ #endif
      
      strncpy(dp->filemask, unixdirname, 12);
      dp->filemask[12] = 0;
      dprintf_dosfs(stddeb,"DOS_opendir: %s / %s\n", unixdirname, dirname);
  
      strcpy(dp->unixpath, dirname);
      dp->entnum = 0;
  
      return dp;
  }
  
***************
*** 908,921 ****
  	DIR	*ds;
  
  	if (!de->inuse)
  		return NULL;
! 	if (!(ds=opendir(de->unixpath))) return NULL;
  	seekdir(ds,de->telldirnum); /* returns no error value. strange */
     
!         if (de->search_attribute & FA_LABEL)  {	
  	    int drive;
  	    de->search_attribute &= ~FA_LABEL; /* don't find it again */
! 	    for(drive = 0; drive < MAX_DOS_DRIVES; drive++) {
  		if (DosDrives[drive].rootdir != NULL &&
  		    strcmp(DosDrives[drive].rootdir, de->unixpath) == 0)
  		{
--- 923,952 ----
  	DIR	*ds;
  
  	if (!de->inuse)
+ 	{
+ 	    printf("DOS_readdir(): something closed the dir early (1)\n");
  		return NULL;
! 	}
! 	if ( ! de->ds ) 
! 	{
! 	    printf("DOS_readdir(): something closed the dir badly (1)\n");
! 	    if (!(de->ds = ds =opendir(de->unixpath))) return NULL;
! 	}
! 	else
! 	{
! 	   ds = de->ds;
! 	}
! #ifdef NEEDSEEK
  	seekdir(ds,de->telldirnum); /* returns no error value. strange */
+ #endif
     
! 	/* Special case for when asked to get a label */
!         if (de->search_attribute & FA_LABEL)
! 	{	
  	    int drive;
  	    de->search_attribute &= ~FA_LABEL; /* don't find it again */
! 	    for(drive = 0; drive < MAX_DOS_DRIVES; drive++)
! 	    {
  		if (DosDrives[drive].rootdir != NULL &&
  		    strcmp(DosDrives[drive].rootdir, de->unixpath) == 0)
  		{
***************
*** 926,935 ****
  	    }
  	}
      
  	do {
  	    if ((d = readdir(ds)) == NULL)  {
  		de->telldirnum=telldir(ds);
! 		closedir(ds);
  		return NULL;
  	    }
  
--- 957,968 ----
  	    }
  	}
      
+ 	/* Keep looking at directory entries till we find what we want */
  	do {
  	    if ((d = readdir(ds)) == NULL)  {
+ #ifdef NEEDSEEK
  		de->telldirnum=telldir(ds);
! #endif
  		return NULL;
  	    }
  
***************
*** 954,966 ****
  	de->filesize = st.st_size;
  	de->filetime = st.st_mtime;
  
  	de->telldirnum = telldir(ds);
! 	closedir(ds);
  	return de;
  }
  
  void DOS_closedir(struct dosdirent *de)
  {
  	if (de && de->inuse)
  		de->inuse = 0;
  }
--- 987,1006 ----
  	de->filesize = st.st_size;
  	de->filetime = st.st_mtime;
  
+ #ifdef NEEDSEEK
  	de->telldirnum = telldir(ds);
! #endif
  	return de;
  }
  
  void DOS_closedir(struct dosdirent *de)
  {
+ 
+ 	if ( de->ds )
+ 	{
+ 		closedir (de->ds);
+ 		de->ds = NULL;
+ 	}
  	if (de && de->inuse)
  		de->inuse = 0;
  }
#------------------end of patch----------------




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199512020550.VAA00807>