5 /* ----------------------------------------------------- */
10 #include <sys/types.h>
27 char d_name
[MAX_PATH
];
38 static DIR *opendir(char *pSpec
)
40 DIR *pDir
= malloc(sizeof *pDir
);
41 char *longer_string
= malloc((strlen(pSpec
) + 3) * sizeof *longer_string
);
43 strcpy(longer_string
, pSpec
);
44 strcat(longer_string
, "/*");
45 pDir
->hFind
= FindFirstFile(longer_string
, &pDir
->wfd
);
47 pDir
->valid
= pDir
->hFind
!= INVALID_HANDLE_VALUE
;
51 static void closedir(DIR * pDir
)
53 if (pDir
->hFind
!= INVALID_HANDLE_VALUE
)
54 FindClose(pDir
->hFind
);
58 static struct dirent
*readdir(DIR *pDir
)
62 strcpy(pDir
->de
.d_name
, pDir
->wfd
.cFileName
);
63 pDir
->de
.d_type
= (pDir
->wfd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) != 0 ? DT_DIR
: 0;
64 pDir
->valid
= FindNextFile(pDir
->hFind
, &pDir
->wfd
);
72 int mkdir(const char *path
, mode_t mode
)
74 /* returns zero on sucess */
75 LPCTSTR lpPathName
= path
;
76 LPSECURITY_ATTRIBUTES lpSecurityAttributes
= NULL
;
77 return (CreateDirectory(lpPathName
, lpSecurityAttributes
) != 0);
82 #if defined(__CYGWIN__) || defined(sun) || defined(__sun)
83 int isDirectory(struct dirent
*dp
, char *path
);
86 /*fstat( dp->d_fd, &st );*/
87 stat(pathString
, &st
);
88 return ( (st
.st_mode
& S_IFMT
) == S_IFDIR
);
91 int isDirectory(struct dirent
*dp
, char *path
)
93 return (dp
->d_type
== DT_DIR
);
97 /* ----------------------------------------------------- */
106 DirEnum
*DirEnum_new(void)
108 DirEnum
*self
= calloc(1, sizeof(DirEnum
));
112 void DirEnum_free(DirEnum
*self
)
114 if (self
->path
) free(self
->path
);
118 void DirEnum_setPath_(DirEnum
*self
, char *s
)
120 self
->path
= strcpy(realloc(self
->path
, strlen(s
) + 1), s
);
121 self
->dir
= opendir(s
);
124 char *DirEnum_setNext_(DirEnum
*self
, char *s
)
126 self
->next
= strcpy(realloc(self
->next
, strlen(s
) + 1), s
);
130 char *DirEnum_next(DirEnum
*self
)
132 struct direct
*dp
= readdir(dirp
);
135 char *name
= dp
.d_name
;