Updated footer comment
[pazpar2-moved-to-github.git] / src / dirent.c
1 /* This file is part of Pazpar2.
2    Copyright (C) 2006-2009 Index Data
3
4 Pazpar2 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 Pazpar2 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 /* almost identical to dirent.c of Zebra. */
22
23 #if HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <assert.h>
28 #ifdef WIN32
29 #include <io.h>
30 #endif
31 #include <string.h>
32 #include <stdlib.h>
33
34 #include "direntz.h"
35
36 #ifdef WIN32
37
38 struct DIR {
39     HANDLE handle;
40     WIN32_FIND_DATA find_data;
41     struct dirent entry;
42 };
43
44 DIR *opendir (const char *name)
45 {
46     char fullName[MAX_PATH+1];
47     DIR *dd = malloc (sizeof(*dd));
48
49     if (!dd)
50         return NULL;
51     strcpy (fullName, name);
52     strcat (fullName, "\\*.*");
53     dd->handle = FindFirstFile(fullName, &dd->find_data);
54     return dd;
55 }
56                                                           
57 struct dirent *readdir (DIR *dd)
58 {
59     if (dd->handle == INVALID_HANDLE_VALUE)
60         return NULL;
61     strcpy (dd->entry.d_name, dd->find_data.cFileName);
62     if (!FindNextFile(dd->handle, &dd->find_data))
63     {
64         FindClose (dd->handle);
65         dd->handle = INVALID_HANDLE_VALUE;
66     }
67     return &dd->entry;
68 }
69
70 void closedir(DIR *dd)
71 {
72     if (dd->handle != INVALID_HANDLE_VALUE)
73         FindClose (dd->handle);
74     if (dd)
75         free (dd);
76 }
77
78 #endif
79
80 /*
81  * Local variables:
82  * c-basic-offset: 4
83  * c-file-style: "Stroustrup"
84  * indent-tabs-mode: nil
85  * End:
86  * vim: shiftwidth=4 tabstop=8 expandtab
87  */
88