From: <no...@so...> - 2001-09-09 21:29:12
|
Patches item #454717, was opened at 2001-08-23 14:23 You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=302435&aid=454717&group_id=2435 Category: runtime Group: None >Status: Closed >Resolution: Fixed Priority: 5 Submitted By: Danny Smith (dannysmith) Assigned to: Nobody/Anonymous (nobody) Summary: dirent.c Initial Comment: 2001-08-23 Danny Smith <dan...@us...> * dirent.c: Merge in code from PD dirent.c version included with gcc-2.95 (Michael Rendell <{uunet,utai} michael@garfield>) Define macros DISABLE_HARD_ERRORS, ENABLE_HARD_ERRORS to disable SEM dialogs, conditioned by definition of __DIRENT_SHOW_SEM. (opendir): Use. (readdir): Use. (opendir): Strip trailing slash or backslash from dir name, unless it is a DOS root dir. ---------------------------------------------------------------------- >Comment By: Danny Smith (dannysmith) Date: 2001-09-09 14:29 Message: Logged In: YES user_id=11494 I have committed to SF CVS. ---------------------------------------------------------------------- Comment By: Danny Smith (dannysmith) Date: 2001-09-07 15:41 Message: Logged In: YES user_id=11494 I'be reduced patch this to just a single change Use GetFileAttributes rather stat to check dir status. This is cheaper and is less sensistive to trailing backslashes. Hiding the SE message box *within* opendir,readdir is probably not a good idea. Often it would be more efficient to do it only once outside multiple calls to these functions. If users want to disable the OS message box, that is there job. Some users will not want to. ChangeLog 2001-09-08 Danny Smith <dan...@us...> * dirent.c (opendir): Use GetFileAttributes rather than stat to determine if dir. --- dirent.c.orig Tue Jun 05 12:26:30 2001 +++ dirent.c Thu Sep 06 21:12:54 2001 @@ -20,10 +20,12 @@ #include <string.h> #include <io.h> #include <direct.h> -#include <sys/stat.h> #include <dirent.h> +#define WIN32_LEAN_AND_MEAN +#include <windows.h> /* for GetFileAttributes */ + #define SUFFIX "*" #define SLASH "\" @@ -37,7 +39,7 @@ DIR * opendir (const char *szPath) { DIR *nd; - struct _stat statDir; + unsigned int rc; errno = 0; @@ -54,15 +56,16 @@ opendir (const char *szPath) } /* Attempt to determine if the given path really is a directory. */ - if (_stat (szPath, &statDir)) + rc = GetFileAttributes(szPath); + if (rc == -1) { - /* Error, stat should have set an error value. */ + /* call GetLastError for more error info */ + errno = ENOENT; return (DIR *) 0; } - - if (!S_ISDIR (statDir.st_mode)) + if (!(rc & FILE_ATTRIBUTE_DIRECTORY)) { - /* Error, stat reports not a directory. */ + /* Error, entry exists but not a directory. */ errno = ENOTDIR; return (DIR *) 0; } ---------------------------------------------------------------------- Comment By: Danny Smith (dannysmith) Date: 2001-08-28 19:54 Message: Logged In: YES user_id=11494 I have simplified dirent.c to use GetFileAttributes rather than stat to check if pathname arg is a directory. My tests indicate that this is less sensitive to trailing slashes and backslashes than stat. It even works on logical drive names (eg D:, D:/, D:\ all give same result) I would appreciate if some could test on w9x or WinMe. I am also uploading a test app (listdir.c) to test the modified dirent.c ---------------------------------------------------------------------- You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=302435&aid=454717&group_id=2435 |