#86 dirent.c

closed-fixed
nobody
2001-09-09
2001-08-23
Danny Smith
No

2001-08-23 Danny Smith
<dannysmith@users.sourceforge.net>

\* 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.

Discussion

  • Danny Smith
    Danny Smith
    2001-08-29

    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

     
  • Danny Smith
    Danny Smith
    2001-08-29

     
    Attachments
  • Danny Smith
    Danny Smith
    2001-09-07

    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 <dannysmith@users.sourceforge.net>

    \* 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;
    }

     
  • Danny Smith
    Danny Smith
    2001-09-09

    • status: open --> closed-fixed
     
  • Danny Smith
    Danny Smith
    2001-09-09

    Logged In: YES
    user_id=11494

    I have committed to SF CVS.