IDZEBRA  2.2.7
dirent.c
Go to the documentation of this file.
1 /* This file is part of the Zebra server.
2  Copyright (C) Index Data
3 
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8 
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 
18 */
19 
20 
21 
22 #if HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25 #include <ctype.h>
26 #include <assert.h>
27 #ifdef WIN32
28 #include <io.h>
29 #endif
30 #include <string.h>
31 #include <stdlib.h>
32 
33 #include <direntz.h>
34 
35 #ifdef WIN32
36 
37 struct DIR {
38  HANDLE handle;
39  WIN32_FIND_DATA find_data;
40  struct dirent entry;
41 };
42 
43 DIR *opendir (const char *name)
44 {
45  char fullName[MAX_PATH+1];
46  DIR *dd = malloc (sizeof(*dd));
47 
48  if (!dd)
49  return NULL;
50  strcpy (fullName, name);
51  strcat (fullName, "\\*.*");
52  dd->handle = FindFirstFile(fullName, &dd->find_data);
53  return dd;
54 }
55 
56 struct dirent *readdir (DIR *dd)
57 {
58  if (dd->handle == INVALID_HANDLE_VALUE)
59  return NULL;
60  strcpy (dd->entry.d_name, dd->find_data.cFileName);
61  if (!FindNextFile(dd->handle, &dd->find_data))
62  {
63  FindClose (dd->handle);
64  dd->handle = INVALID_HANDLE_VALUE;
65  }
66  return &dd->entry;
67 }
68 
69 void closedir(DIR *dd)
70 {
71  if (dd->handle != INVALID_HANDLE_VALUE)
72  FindClose (dd->handle);
73  if (dd)
74  free (dd);
75 }
76 
77 #endif
78 
79 /*
80  * Local variables:
81  * c-basic-offset: 4
82  * c-file-style: "Stroustrup"
83  * indent-tabs-mode: nil
84  * End:
85  * vim: shiftwidth=4 tabstop=8 expandtab
86  */
87