1 /* Read the next entry of a directory.
2 Copyright (C) 2011-2017 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
25 #include "dirent-private.h"
31 struct dirent
*result
;
33 /* There is no need to add code to produce entries for "." and "..".
34 According to the POSIX:2008 section "4.12 Pathname Resolution"
35 <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html>
36 "." and ".." are syntactic entities.
38 "If entries for dot or dot-dot exist, one entry shall be returned
39 for dot and one entry shall be returned for dot-dot; otherwise,
40 they shall not be returned." */
45 /* End of directory already reached. */
50 if (!FindNextFile (dirp
->current
, &dirp
->entry
))
52 switch (GetLastError ())
54 case ERROR_NO_MORE_FILES
:
70 if (dirp
->entry
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
72 else if (dirp
->entry
.dwFileAttributes
& FILE_ATTRIBUTE_REPARSE_POINT
)
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 /* Devices like COM1, LPT1, NUL would also have the attributes 0x20 but
86 they cannot occur here. */
91 /* Reuse the memory of dirp->entry for the result. */
94 ((char *) dirp
->entry
.cFileName
- offsetof (struct dirent
, d_name
[0]));
95 result
->d_type
= type
;