ZOOM: expire times set for redis/memcached YAZ-772
[yaz-moved-to-github.git] / src / dirent.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
5
6 /** \file
7     \brief Implement opendir/readdir/closedir on Windows
8 */
9
10 #if HAVE_CONFIG_H
11 #include <config.h>
12 #endif
13
14 #include <assert.h>
15 #ifdef WIN32
16 #include <io.h>
17 #endif
18 #include <string.h>
19 #include <stdlib.h>
20
21 #include <yaz/dirent.h>
22
23 #ifdef WIN32
24
25 struct DIR {
26     HANDLE handle;
27     WIN32_FIND_DATA find_data;
28     struct dirent entry;
29 };
30
31 DIR *opendir(const char *name)
32 {
33     char fullName[MAX_PATH+1];
34     DIR *dd = malloc(sizeof(*dd));
35
36     if (!dd)
37         return NULL;
38     strcpy(fullName, name);
39     strcat(fullName, "\\*.*");
40     dd->handle = FindFirstFile(fullName, &dd->find_data);
41     return dd;
42 }
43
44 struct dirent *readdir(DIR *dd)
45 {
46     if (dd->handle == INVALID_HANDLE_VALUE)
47         return NULL;
48     strcpy(dd->entry.d_name, dd->find_data.cFileName);
49     if (!FindNextFile(dd->handle, &dd->find_data))
50     {
51         FindClose(dd->handle);
52         dd->handle = INVALID_HANDLE_VALUE;
53     }
54     return &dd->entry;
55 }
56
57 void closedir(DIR *dd)
58 {
59     if (dd->handle != INVALID_HANDLE_VALUE)
60         FindClose(dd->handle);
61     if (dd)
62         free(dd);
63 }
64
65 #endif
66
67 /*
68  * Local variables:
69  * c-basic-offset: 4
70  * c-file-style: "Stroustrup"
71  * indent-tabs-mode: nil
72  * End:
73  * vim: shiftwidth=4 tabstop=8 expandtab
74  */
75