1 /* Read the next entry of a directory.
2 Copyright (C) 2011-2024 Free Software Foundation, Inc.
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 This file 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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
25 #if GNULIB_defined_DIR
26 # include "dirent-private.h"
29 /* Don't assume that UNICODE is not defined. */
31 #define FindNextFile FindNextFileA
37 #if HAVE_DIRENT_H /* equivalent to HAVE_READDIR */
38 return readdir (dirp
->real_dirp
);
41 struct dirent
*result
;
43 /* There is no need to add code to produce entries for "." and "..".
44 According to the POSIX:2008 section "4.12 Pathname Resolution"
45 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html>
46 "." and ".." are syntactic entities.
48 "If entries for dot or dot-dot exist, one entry shall be returned
49 for dot and one entry shall be returned for dot-dot; otherwise,
50 they shall not be returned." */
55 /* End of directory already reached. */
60 if (!FindNextFile (dirp
->current
, &dirp
->entry
))
62 switch (GetLastError ())
64 case ERROR_NO_MORE_FILES
:
80 if (dirp
->entry
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
82 else if (dirp
->entry
.dwFileAttributes
& FILE_ATTRIBUTE_REPARSE_POINT
)
84 else if ((dirp
->entry
.dwFileAttributes
85 & ~(FILE_ATTRIBUTE_READONLY
86 | FILE_ATTRIBUTE_HIDDEN
87 | FILE_ATTRIBUTE_SYSTEM
88 | FILE_ATTRIBUTE_ARCHIVE
89 | FILE_ATTRIBUTE_NORMAL
90 | FILE_ATTRIBUTE_TEMPORARY
91 | FILE_ATTRIBUTE_SPARSE_FILE
92 | FILE_ATTRIBUTE_COMPRESSED
93 | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
94 | FILE_ATTRIBUTE_ENCRYPTED
)) == 0)
95 /* Devices like COM1, LPT1, NUL would also have the attributes 0x20 but
96 they cannot occur here. */
101 /* Reuse the memory of dirp->entry for the result. */
104 ((char *) dirp
->entry
.cFileName
- offsetof (struct dirent
, d_name
[0]));
105 result
->d_type
= type
;