From owner-freebsd-hackers Fri Dec 1 21:51:26 1995 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id VAA22745 for hackers-outgoing; Fri, 1 Dec 1995 21:51:26 -0800 Received: from ref.tfs.com (ref.tfs.com [140.145.254.251]) by freefall.freebsd.org (8.6.12/8.6.6) with ESMTP id VAA22714 ; Fri, 1 Dec 1995 21:51:10 -0800 Received: (from julian@localhost) by ref.tfs.com (8.6.12/8.6.9) id VAA00807; Fri, 1 Dec 1995 21:50:48 -0800 From: Julian Elischer Message-Id: <199512020550.VAA00807@ref.tfs.com> Subject: Slightly better patch for FreeBSD readdir() fix To: wine-new@amscons.com Date: Fri, 1 Dec 1995 21:50:48 -0800 (PST) Cc: hackers@freebsd.org, ports@freebsd.org X-Mailer: ELM [version 2.4 PL24] Content-Type: text Content-Length: 5016 Sender: owner-hackers@freebsd.org Precedence: bulk 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----------------