Multi register works with record paths and data1 profile path
[idzebra-moved-to-github.git] / util / dirent.c
1 /*
2  * Copyright (C) 1997-2002, Index Data
3  * All rights reserved.
4  *
5  * $Id: dirent.c,v 1.5 2002-04-04 20:50:37 adam Exp $
6  *
7  * This utility implements a opendir/readdir/close on Windows.
8  */
9
10 #include <ctype.h>
11 #include <assert.h>
12 #ifdef WIN32
13 #include <io.h>
14 #endif
15 #include <string.h>
16 #include <stdlib.h>
17
18 #include <direntz.h>
19
20 #ifdef WIN32
21
22 struct DIR {
23     HANDLE handle;
24     WIN32_FIND_DATA find_data;
25     struct dirent entry;
26 };
27
28 DIR *opendir (const char *name)
29 {
30     char fullName[MAX_PATH+1];
31     DIR *dd = malloc (sizeof(*dd));
32
33     if (!dd)
34         return NULL;
35     strcpy (fullName, name);
36     strcat (fullName, "\\*.*");
37     dd->handle = FindFirstFile(fullName, &dd->find_data);
38     return dd;
39 }
40                                                           
41 struct dirent *readdir (DIR *dd)
42 {
43     if (dd->handle == INVALID_HANDLE_VALUE)
44         return NULL;
45     strcpy (dd->entry.d_name, dd->find_data.cFileName);
46     if (!FindNextFile(dd->handle, &dd->find_data))
47     {
48         FindClose (dd->handle);
49         dd->handle = INVALID_HANDLE_VALUE;
50     }
51     return &dd->entry;
52 }
53
54 void closedir(DIR *dd)
55 {
56     if (dd->handle != INVALID_HANDLE_VALUE)
57         FindClose (dd->handle);
58     if (dd)
59         free (dd);
60 }
61
62 #endif
63