Reading a directory

Posted by paleman on Stack Overflow See other posts from Stack Overflow or by paleman
Published on 2010-03-20T20:17:07Z Indexed on 2010/03/20 20:21 UTC
Read the original article Hit count: 124

Filed under:
|

Hi, I'm trying to solve exercise from K&R, it's about reading directories.This task is system dependent because it uses system calls.In the book example authors say that their example is written for Version 7 and System V UNIX systems and that they used the directory information in the header < sys/dir.h>,which looks like this:

#ifndef DIRSIZ
#define DIRSIZ 14
#endif
struct direct {    /* directory entry */
    ino_t d_ino;           /* inode number */
    char d_name[DIRSIZ];   /* long name does not have '\0' */
};

On this system they use 'struct direct' combined with 'read' function to retrieve a directory entry, which consist of file name and inode number.

.....
struct direct dirbuf;    /* local directory structure */
while(read(dp->fd, (char *) &dirbuf, sizeof(dirbuf)
               == sizeof(dirbuf) {
    .....
}
.....

I suppose this works fine on UNIX and Linux systems, but what I want to do is modify this so it works on Windows XP.
Is there some structure in Windows like 'struct direct' so I can use it with 'read' function and if there is what is the header name where it is defined?
Or maybe Windows requires completely different approach?

© Stack Overflow or respective owner

Related posts about c

    Related posts about Windows