| 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 |
struct dirent * |
| 28 |
readdir (DIR *dirp) |
| 29 |
{ |
| 30 |
char type; |
| 31 |
struct dirent *result; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
switch (dirp->status) |
| 43 |
{ |
| 44 |
case -2: |
| 45 |
|
| 46 |
return NULL; |
| 47 |
case -1: |
| 48 |
break; |
| 49 |
case 0: |
| 50 |
if (!FindNextFile (dirp->current, &dirp->entry)) |
| 51 |
{ |
| 52 |
switch (GetLastError ()) |
| 53 |
{ |
| 54 |
case ERROR_NO_MORE_FILES: |
| 55 |
dirp->status = -2; |
| 56 |
return NULL; |
| 57 |
default: |
| 58 |
errno = EIO; |
| 59 |
return NULL; |
| 60 |
} |
| 61 |
} |
| 62 |
break; |
| 63 |
default: |
| 64 |
errno = dirp->status; |
| 65 |
return NULL; |
| 66 |
} |
| 67 |
|
| 68 |
dirp->status = 0; |
| 69 |
|
| 70 |
if (dirp->entry.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
| 71 |
type = DT_DIR; |
| 72 |
else if (dirp->entry.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) |
| 73 |
type = DT_LNK; |
| 74 |
else if ((dirp->entry.dwFileAttributes |
| 75 |
& ~(FILE_ATTRIBUTE_READONLY |
| 76 |
| FILE_ATTRIBUTE_HIDDEN |
| 77 |
| FILE_ATTRIBUTE_SYSTEM |
| 78 |
| FILE_ATTRIBUTE_ARCHIVE |
| 79 |
| FILE_ATTRIBUTE_NORMAL |
| 80 |
| FILE_ATTRIBUTE_TEMPORARY |
| 81 |
| FILE_ATTRIBUTE_SPARSE_FILE |
| 82 |
| FILE_ATTRIBUTE_COMPRESSED |
| 83 |
| FILE_ATTRIBUTE_NOT_CONTENT_INDEXED |
| 84 |
| FILE_ATTRIBUTE_ENCRYPTED)) == 0) |
| 85 |
|
| 86 |
|
| 87 |
type = DT_REG; |
| 88 |
else |
| 89 |
type = DT_UNKNOWN; |
| 90 |
|
| 91 |
|
| 92 |
result = |
| 93 |
(struct dirent *) |
| 94 |
((char *) dirp->entry.cFileName - offsetof (struct dirent, d_name[0])); |
| 95 |
result->d_type = type; |
| 96 |
|
| 97 |
return result; |
| 98 |
} |