This source file includes following definitions.
- readdir
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <config.h>
18
19
20 #include <dirent.h>
21
22 #include <errno.h>
23 #include <stddef.h>
24
25 #include "dirent-private.h"
26
27
28 #undef FindNextFile
29 #define FindNextFile FindNextFileA
30
31 struct dirent *
32 readdir (DIR *dirp)
33 {
34 char type;
35 struct dirent *result;
36
37
38
39
40
41
42
43
44
45
46 switch (dirp->status)
47 {
48 case -2:
49
50 return NULL;
51 case -1:
52 break;
53 case 0:
54 if (!FindNextFile (dirp->current, &dirp->entry))
55 {
56 switch (GetLastError ())
57 {
58 case ERROR_NO_MORE_FILES:
59 dirp->status = -2;
60 return NULL;
61 default:
62 errno = EIO;
63 return NULL;
64 }
65 }
66 break;
67 default:
68 errno = dirp->status;
69 return NULL;
70 }
71
72 dirp->status = 0;
73
74 if (dirp->entry.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
75 type = DT_DIR;
76 else if (dirp->entry.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
77 type = DT_LNK;
78 else if ((dirp->entry.dwFileAttributes
79 & ~(FILE_ATTRIBUTE_READONLY
80 | FILE_ATTRIBUTE_HIDDEN
81 | FILE_ATTRIBUTE_SYSTEM
82 | FILE_ATTRIBUTE_ARCHIVE
83 | FILE_ATTRIBUTE_NORMAL
84 | FILE_ATTRIBUTE_TEMPORARY
85 | FILE_ATTRIBUTE_SPARSE_FILE
86 | FILE_ATTRIBUTE_COMPRESSED
87 | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
88 | FILE_ATTRIBUTE_ENCRYPTED)) == 0)
89
90
91 type = DT_REG;
92 else
93 type = DT_UNKNOWN;
94
95
96 result =
97 (struct dirent *)
98 ((char *) dirp->entry.cFileName - offsetof (struct dirent, d_name[0]));
99 result->d_type = type;
100
101 return result;
102 }