Annotation of parser3/src/lib/ltdl/lt__dirent.c, revision 1.2
1.1 moko 1: /* lt__dirent.c -- internal directory entry scanning interface
2:
1.2 ! moko 3: Copyright (C) 2001, 2004, 2011-2019, 2021-2024 Free Software
! 4: Foundation, Inc.
1.1 moko 5: Written by Bob Friesenhahn, 2001
6:
7: NOTE: The canonical source of this file is maintained with the
8: GNU Libtool package. Report bugs to bug-libtool@gnu.org.
9:
10: GNU Libltdl is free software; you can redistribute it and/or
11: modify it under the terms of the GNU Lesser General Public
12: License as published by the Free Software Foundation; either
13: version 2 of the License, or (at your option) any later version.
14:
15: As a special exception to the GNU Lesser General Public License,
16: if you distribute this file as part of a program or library that
17: is built using GNU Libtool, you may include this file under the
18: same distribution terms that you use for the rest of that program.
19:
20: GNU Libltdl is distributed in the hope that it will be useful,
21: but WITHOUT ANY WARRANTY; without even the implied warranty of
22: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23: GNU Lesser General Public License for more details.
24:
25: You should have received a copy of the GNU Lesser General Public
1.2 ! moko 26: License along with GNU Libltdl. If not, see <https://www.gnu.org/licenses/>.
1.1 moko 27: */
28:
29: #include "lt__private.h"
30:
31: #include <assert.h>
32:
33: #include "lt__dirent.h"
34:
1.2 ! moko 35: #if defined __WINDOWS__
1.1 moko 36:
37: void
38: closedir (DIR *entry)
39: {
40: assert (entry != (DIR *) NULL);
41: FindClose (entry->hSearch);
1.2 ! moko 42: free (entry);
1.1 moko 43: }
44:
45:
46: DIR *
47: opendir (const char *path)
48: {
49: char file_spec[LT_FILENAME_MAX];
50: DIR *entry;
51:
52: assert (path != (char *) 0);
53: if (lt_strlcpy (file_spec, path, sizeof file_spec) >= sizeof file_spec
54: || lt_strlcat (file_spec, "\\", sizeof file_spec) >= sizeof file_spec)
55: return (DIR *) 0;
56: entry = (DIR *) malloc (sizeof(DIR));
57: if (entry != (DIR *) 0)
58: {
59: entry->firsttime = TRUE;
60: entry->hSearch = FindFirstFile (file_spec, &entry->Win32FindData);
61:
62: if (entry->hSearch == INVALID_HANDLE_VALUE)
63: {
64: if (lt_strlcat (file_spec, "\\*.*", sizeof file_spec) < sizeof file_spec)
65: {
66: entry->hSearch = FindFirstFile (file_spec, &entry->Win32FindData);
67: }
68:
69: if (entry->hSearch == INVALID_HANDLE_VALUE)
70: {
71: entry = (free (entry), (DIR *) 0);
72: }
73: }
74: }
75:
76: return entry;
77: }
78:
79:
80: struct dirent *
81: readdir (DIR *entry)
82: {
83: int status;
84:
85: if (entry == (DIR *) 0)
86: return (struct dirent *) 0;
87:
88: if (!entry->firsttime)
89: {
90: status = FindNextFile (entry->hSearch, &entry->Win32FindData);
91: if (status == 0)
92: return (struct dirent *) 0;
93: }
94:
95: entry->firsttime = FALSE;
96: if (lt_strlcpy (entry->file_info.d_name, entry->Win32FindData.cFileName,
97: sizeof entry->file_info.d_name) >= sizeof entry->file_info.d_name)
98: return (struct dirent *) 0;
99: entry->file_info.d_namlen = strlen (entry->file_info.d_name);
100:
101: return &entry->file_info;
102: }
103:
1.2 ! moko 104: #endif /*defined __WINDOWS__*/
E-mail: