Re: opendir() failes with trailing \

David L Norris <[email protected]>
Newsgroups gmane.comp.video.gimp.windows.devel
Message-ID <[email protected]>
On Mon, 2002-09-02 at 03:05, Cameron Gregory wrote:
> So, then opendir files on "plugins" and all the other dirs...
> My only guess is the current version uses a different opendir()??
> tor: any insight there?

stat() on Win32 doesn't work like one might expect; I'd dare say it's
broken.  Could this be the cause?  Incidentally, I'd love to know how to
work around stat() problems on Win32.


Here's what the native Win32 stat() function does (WinXP, VC70):

E:\projects>stat C:\
directory 1
file 0

E:\projects>stat C:\windows
directory 1
file 0

E:\projects>stat C:\windows\
directory 0
file 0

E:\projects>stat N:\
directory 1
file 0

E:\projects>stat N:\www
directory 1
file 0

E:\projects>stat N:\www\
directory 0
file 0

E:\projects>stat \\daneel\public
directory 0
file 0

E:\projects>stat \\daneel\public\
directory 1
file 0


Test Code:

#include <stdio.h>
#include <sys/stat.h>

int     isdirectory(char *path)
{
    struct stat stbuf;

    if (stat(path, &stbuf))
        return 0;
    return ((stbuf.st_mode & S_IFMT) == S_IFDIR) ? 1 : 0;
}

int     isfile(char *path)
{
    struct stat stbuf;

    if (stat(path, &stbuf))
        return 0;
    return ((stbuf.st_mode & S_IFMT) == S_IFREG) ? 1 : 0;
}

int main(int argc, char **argv)
{
    printf("directory %d\n", isdirectory( argv[1] ));
    printf("file %d\n", isfile( argv[1] ));
}


-- 
 David Norris
  Dave's Web - http://www.webaugur.com/dave/
  Augury Net - http://augur.homeip.net/
  ICQ - 412039
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.