Defuzzied one entry
[midnight-commander.git] / pc / dirent_nt.c
blobd45800b71b15f6c82a545eb646700f0e65873210
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <windows.h>
9 #include <errno.h>
10 #include "dirent.h"
12 DIR *opendir (const char * a_dir)
14 int err;
15 WIN32_FIND_DATA wfd;
16 DIR* dd_dir = (DIR*) malloc (sizeof(DIR));
18 char *c_dir = malloc (strlen(a_dir) + 4);
19 strcpy (c_dir, a_dir);
20 strcat (c_dir, "\\*");
22 dd_dir->d_handle = FindFirstFile (c_dir, &wfd);
23 if (dd_dir->d_handle == INVALID_HANDLE_VALUE) {
24 err = GetLastError();
25 switch (err) {
26 case ERROR_NO_MORE_FILES:
27 case ERROR_FILE_NOT_FOUND:
28 case ERROR_PATH_NOT_FOUND:
29 errno = ENOENT;
30 break;
31 case ERROR_NOT_ENOUGH_MEMORY:
32 errno = ENOMEM;
33 break;
34 default:
35 errno = EINVAL;
36 break;
38 free(dd_dir);
39 return NULL;
41 dd_dir->d_attr = (wfd.dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
42 ? 0 : wfd.dwFileAttributes;
44 dd_dir->d_time = dd_dir->d_date = 10;
45 dd_dir->d_size = wfd.nFileSizeLow;
46 strcpy (dd_dir->d_name, wfd.cFileName);
47 dd_dir->d_first = 1;
49 free (c_dir);
50 return dd_dir;
53 DIR *readdir( DIR * dd_dir)
55 int err;
56 WIN32_FIND_DATA wfd;
58 if (dd_dir->d_first) {
59 dd_dir->d_first = 0;
60 return dd_dir;
63 if(!FindNextFile (dd_dir->d_handle, &wfd)) {
64 err = GetLastError();
65 switch (err) {
66 case ERROR_NO_MORE_FILES:
67 case ERROR_FILE_NOT_FOUND:
68 case ERROR_PATH_NOT_FOUND:
69 errno = ENOENT;
70 break;
71 case ERROR_NOT_ENOUGH_MEMORY:
72 errno = ENOMEM;
73 break;
74 default:
75 errno = EINVAL;
76 break;
78 return NULL;
80 dd_dir->d_attr = (wfd.dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
81 ? 0 : wfd.dwFileAttributes;
83 dd_dir->d_time = dd_dir->d_date = 10;
84 dd_dir->d_size = wfd.nFileSizeLow;
85 strcpy (dd_dir->d_name, wfd.cFileName);
86 return dd_dir;
89 int closedir (DIR *dd_dir)
91 FindClose(dd_dir->d_handle);
92 free (dd_dir);
93 return 1;