Multiple registers (alpha early)
[idzebra-moved-to-github.git] / util / dirent.c
1 /*
2  * Copyright (C) 1997-1999, Index Data
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: dirent.c,v $
7  * Revision 1.4  2002-04-04 14:14:14  adam
8  * Multiple registers (alpha early)
9  *
10  * Revision 1.3  1999/02/02 14:51:38  adam
11  * Updated WIN32 code specific sections. Changed header.
12  *
13  * Revision 1.2  1997/09/17 12:19:24  adam
14  * Zebra version corresponds to YAZ version 1.4.
15  * Changed Zebra server so that it doesn't depend on global common_resource.
16  *
17  * 
18  *
19  * This utility implements a opendir/readdir/close on Windows.
20  */
21
22 #ifdef WIN32
23 #include <assert.h>
24 #include <io.h>
25 #include <string.h>
26 #include <stdlib.h>
27
28 #include <direntz.h>
29
30 struct DIR {
31     HANDLE handle;
32     WIN32_FIND_DATA find_data;
33     struct dirent entry;
34 };
35
36 DIR *opendir (const char *name)
37 {
38     char fullName[MAX_PATH+1];
39     DIR *dd = malloc (sizeof(*dd));
40
41     if (!dd)
42         return NULL;
43     strcpy (fullName, name);
44     strcat (fullName, "\\*.*");
45     dd->handle = FindFirstFile(fullName, &dd->find_data);
46     return dd;
47 }
48                                                           
49 struct dirent *readdir (DIR *dd)
50 {
51     if (dd->handle == INVALID_HANDLE_VALUE)
52         return NULL;
53     strcpy (dd->entry.d_name, dd->find_data.cFileName);
54     if (!FindNextFile(dd->handle, &dd->find_data))
55     {
56         FindClose (dd->handle);
57         dd->handle = INVALID_HANDLE_VALUE;
58     }
59     return &dd->entry;
60 }
61
62 void closedir(DIR *dd)
63 {
64     if (dd->handle != INVALID_HANDLE_VALUE)
65         FindClose (dd->handle);
66     if (dd)
67         free (dd);
68 }
69
70 #endif
71
72 int zebra_is_abspath (const char *p)
73 {
74     if (*p == '/')
75         return 1;
76 #ifdef WIN32
77     if (*p == '\\')
78         return 1;
79     if (*p && p[1] == ':' && isalpha(*p))
80         return 1;
81 #endif
82     return 0;
83 }