dirent.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. <dirent.h> -- definitions for POSIX-compatible directory access
  3. * The code here is forced by the interface, and is not subject to
  4. * copyright, constituting the only possible expression of the
  5. * algorithm in this format.
  6. */
  7. #define DIRBLKSIZ 512 /* size of directory block */
  8. #ifdef WINDOWSNT
  9. #define MAXNAMLEN 255
  10. #else /* not WINDOWSNT */
  11. #define MAXNAMLEN 15 /* maximum filename length */
  12. #endif /* not WINDOWSNT */
  13. /* NOTE: MAXNAMLEN must be one less than a multiple of 4 */
  14. struct dirent /* data from readdir() */
  15. {
  16. long d_ino; /* inode number of entry */
  17. unsigned short d_reclen; /* length of this record */
  18. unsigned short d_namlen; /* length of string in d_name */
  19. #if __MINGW_MAJOR_VERSION >= 4
  20. /* MinGW.org runtime 4.x introduces a modified layout of
  21. 'struct dirent', which makes it binary incompatible with
  22. previous versions. To add insult to injury, the MinGW
  23. startup code calls 'readdir', which is implemented in
  24. w32.c. So we need to define the same layout of this struct
  25. as the MinGW runtime does, or else command-line globbing
  26. will be broken. (Versions of MinGW runtime after 4.0 are
  27. supposed not to call 'readdir' from startup code, but we
  28. had better be safe than sorry.) */
  29. unsigned d_type; /* File attributes */
  30. /* The next 3 fields are declared 'time_t' in the MinGW 4.0
  31. headers, but 'time_t' is by default a 64-bit type in 4.x,
  32. and presumably the libmingwex library was compiled using
  33. that default definition. So we must use 64-bit types here,
  34. even though our time_t is a 32-bit type. What a mess! */
  35. __int64 d_time_create;
  36. __int64 d_time_access; /* always midnight local time */
  37. __int64 d_time_write;
  38. _fsize_t d_size;
  39. #endif
  40. char d_name[MAXNAMLEN * 4 + 1]; /* name of file */
  41. };
  42. typedef struct
  43. {
  44. int dd_fd; /* file descriptor */
  45. int dd_loc; /* offset in block */
  46. int dd_size; /* amount of valid data */
  47. char dd_buf[DIRBLKSIZ]; /* directory block */
  48. } DIR; /* stream data from opendir() */
  49. extern DIR *opendir (const char *);
  50. extern struct dirent *readdir (DIR *);
  51. extern void seekdir (DIR *, long);
  52. extern void closedir (DIR *);
  53. #define rewinddir( dirp ) seekdir( dirp, 0L )