1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Start reading the entries of a directory.
4 Copyright (C) 2006-2014 Free Software Foundation, Inc.
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
29 /* Override opendir(), to keep track of the open file descriptors.
30 Needed because there is a function dirfd(). */
36 # include "dirent-private.h"
37 # include "filename.h"
46 opendir (const char *dir_name)
52 dirp = opendir (dir_name);
58 char dir_name_mask[MAX_PATH + 1 + 1 + 1];
61 WIN32_FIND_DATA entry;
62 struct gl_directory *dirp;
64 if (dir_name[0] == '\0')
70 /* Make the dir_name absolute, so that we continue reading the same
71 directory if the current directory changed between this opendir()
72 call and a subsequent rewinddir() call. */
73 if (!GetFullPathName (dir_name, MAX_PATH, dir_name_mask, NULL))
80 "*" and "*.*" appear to be equivalent. */
84 p = dir_name_mask + strlen (dir_name_mask);
85 if (p > dir_name_mask && !ISSLASH (p[-1]))
91 /* Start searching the directory. */
93 current = FindFirstFile (dir_name_mask, &entry);
94 if (current == INVALID_HANDLE_VALUE)
96 switch (GetLastError ())
98 case ERROR_FILE_NOT_FOUND:
101 case ERROR_PATH_NOT_FOUND:
104 case ERROR_DIRECTORY:
107 case ERROR_ACCESS_DENIED:
116 /* Allocate the result. */
118 (struct gl_directory *)
119 malloc (offsetof (struct gl_directory, dir_name_mask[0])
120 + strlen (dir_name_mask) + 1);
123 if (current != INVALID_HANDLE_VALUE)
128 dirp->status = status;
129 dirp->current = current;
131 memcpy (&dirp->entry, &entry, sizeof (WIN32_FIND_DATA));
132 strcpy (dirp->dir_name_mask, dir_name_mask);
138 int fd = dirfd (dirp);
139 if (0 <= fd && _gl_register_fd (fd, dir_name) != fd)
141 int saved_errno = errno;