Fossil SCM
allow MSVC build without -DUNICODE as well
Commit
eede5db7c37727a04c222d321c970383c4284a9e
Parent
ebe241b4df7f606…
1 file changed
+41
-22
+41
-22
| --- win/include/dirent.h | ||
| +++ win/include/dirent.h | ||
| @@ -85,10 +85,11 @@ | ||
| 85 | 85 | #include <string.h> |
| 86 | 86 | #include <stdlib.h> |
| 87 | 87 | #include <sys/types.h> |
| 88 | 88 | #include <sys/stat.h> |
| 89 | 89 | #include <errno.h> |
| 90 | +#include <tchar.h> | |
| 90 | 91 | |
| 91 | 92 | /* Entries missing from MSVC 6.0 */ |
| 92 | 93 | #if !defined(FILE_ATTRIBUTE_DEVICE) |
| 93 | 94 | # define FILE_ATTRIBUTE_DEVICE 0x40 |
| 94 | 95 | #endif |
| @@ -152,40 +153,49 @@ | ||
| 152 | 153 | |
| 153 | 154 | #ifdef __cplusplus |
| 154 | 155 | extern "C" { |
| 155 | 156 | #endif |
| 156 | 157 | |
| 158 | +#ifdef UNICODE | |
| 159 | +# define dirent _wdirent | |
| 160 | +# define opendir _wopendir | |
| 161 | +# define readdir _wreaddir | |
| 162 | +# define closedir _wclosedir | |
| 163 | +# define DIR _WDIR | |
| 164 | +#else | |
| 165 | +# define wchar_t char | |
| 166 | +#endif | |
| 157 | 167 | |
| 158 | -typedef struct _wdirent | |
| 168 | +typedef struct dirent | |
| 159 | 169 | { |
| 160 | 170 | wchar_t d_name[MAX_PATH + 1]; /* File name */ |
| 161 | 171 | size_t d_namlen; /* Length of name without \0 */ |
| 162 | 172 | int d_type; /* File type */ |
| 163 | -} _wdirent; | |
| 173 | +} dirent; | |
| 164 | 174 | |
| 165 | 175 | |
| 166 | -typedef struct _WDIR | |
| 176 | +typedef struct DIR | |
| 167 | 177 | { |
| 168 | - _wdirent curentry; /* Current directory entry */ | |
| 169 | - WIN32_FIND_DATAW find_data; /* Private file data */ | |
| 178 | + dirent curentry; /* Current directory entry */ | |
| 179 | + WIN32_FIND_DATA find_data; /* Private file data */ | |
| 170 | 180 | int cached; /* True if data is valid */ |
| 171 | 181 | HANDLE search_handle; /* Win32 search handle */ |
| 172 | 182 | wchar_t patt[MAX_PATH + 3]; /* Initial directory name */ |
| 173 | -} _WDIR; | |
| 183 | +} DIR; | |
| 174 | 184 | |
| 175 | 185 | |
| 176 | 186 | /* Forward declarations */ |
| 177 | -static _WDIR *_wopendir(const wchar_t *dirname); | |
| 178 | -static struct _wdirent *_wreaddir(_WDIR *dirp); | |
| 179 | -static int _wclosedir(_WDIR *dirp); | |
| 187 | +static DIR *opendir(const wchar_t *dirname); | |
| 188 | +static struct dirent *readdir(DIR *dirp); | |
| 189 | +static int closedir(DIR *dirp); | |
| 180 | 190 | |
| 181 | 191 | |
| 182 | 192 | /* Use the new safe string functions introduced in Visual Studio 2005 */ |
| 183 | 193 | #if defined(_MSC_VER) && _MSC_VER >= 1400 |
| 184 | -# define DIRENT_STRNCPY(dest,src,size) wcsncpy_s((dest),(size),(src),_TRUNCATE) | |
| 194 | +# define DIRENT_STRNCPY(dest,src,size) _tcsncpy_s((dest),(size),(src),_TRUNCATE) | |
| 185 | 195 | #else |
| 186 | -# define DIRENT_STRNCPY(dest,src,size) wcsncpy((dest),(src),(size)) | |
| 196 | +# define DIRENT_STRNCPY(dest,src,size) _tcsncpy((dest),(src),(size)) | |
| 187 | 197 | #endif |
| 188 | 198 | |
| 189 | 199 | /* Set errno variable */ |
| 190 | 200 | #if defined(_MSC_VER) |
| 191 | 201 | #define DIRENT_SET_ERRNO(x) _set_errno (x) |
| @@ -197,47 +207,47 @@ | ||
| 197 | 207 | /***************************************************************************** |
| 198 | 208 | * Open directory stream DIRNAME for read and return a pointer to the |
| 199 | 209 | * internal working area that is used to retrieve individual directory |
| 200 | 210 | * entries. |
| 201 | 211 | */ |
| 202 | -static _WDIR *_wopendir(const wchar_t *dirname) | |
| 212 | +static DIR *opendir(const wchar_t *dirname) | |
| 203 | 213 | { |
| 204 | - _WDIR *dirp; | |
| 214 | + DIR *dirp; | |
| 205 | 215 | |
| 206 | 216 | /* ensure that the resulting search pattern will be a valid file name */ |
| 207 | 217 | if (dirname == NULL) { |
| 208 | 218 | DIRENT_SET_ERRNO (ENOENT); |
| 209 | 219 | return NULL; |
| 210 | 220 | } |
| 211 | - if (wcslen (dirname) + 3 >= MAX_PATH) { | |
| 221 | + if (_tcslen (dirname) + 3 >= MAX_PATH) { | |
| 212 | 222 | DIRENT_SET_ERRNO (ENAMETOOLONG); |
| 213 | 223 | return NULL; |
| 214 | 224 | } |
| 215 | 225 | |
| 216 | 226 | /* construct new DIR structure */ |
| 217 | - dirp = (_WDIR*) malloc (sizeof (struct _WDIR)); | |
| 227 | + dirp = (DIR*) malloc (sizeof (struct DIR)); | |
| 218 | 228 | if (dirp != NULL) { |
| 219 | 229 | int error; |
| 220 | 230 | |
| 221 | 231 | /* |
| 222 | 232 | * Convert relative directory name to an absolute one. This |
| 223 | 233 | * allows rewinddir() to function correctly when the current working |
| 224 | 234 | * directory is changed between opendir() and rewinddir(). |
| 225 | 235 | */ |
| 226 | - if (GetFullPathNameW (dirname, MAX_PATH, dirp->patt, NULL)) { | |
| 236 | + if (GetFullPathName (dirname, MAX_PATH, dirp->patt, NULL)) { | |
| 227 | 237 | wchar_t *p; |
| 228 | 238 | |
| 229 | 239 | /* append the search pattern "\\*\0" to the directory name */ |
| 230 | - p = wcschr (dirp->patt, '\0'); | |
| 240 | + p = _tcschr (dirp->patt, '\0'); | |
| 231 | 241 | if (dirp->patt < p && *(p-1) != '\\' && *(p-1) != ':') { |
| 232 | 242 | *p++ = '\\'; |
| 233 | 243 | } |
| 234 | 244 | *p++ = '*'; |
| 235 | 245 | *p = '\0'; |
| 236 | 246 | |
| 237 | 247 | /* open directory stream and retrieve the first entry */ |
| 238 | - dirp->search_handle = FindFirstFileW (dirp->patt, &dirp->find_data); | |
| 248 | + dirp->search_handle = FindFirstFile (dirp->patt, &dirp->find_data); | |
| 239 | 249 | if (dirp->search_handle != INVALID_HANDLE_VALUE) { |
| 240 | 250 | /* a directory entry is now waiting in memory */ |
| 241 | 251 | dirp->cached = 1; |
| 242 | 252 | error = 0; |
| 243 | 253 | } else { |
| @@ -266,11 +276,11 @@ | ||
| 266 | 276 | * containing the name of the entry in d_name field. Individual directory |
| 267 | 277 | * entries returned by this very function include regular files, |
| 268 | 278 | * sub-directories, pseudo-directories "." and "..", but also volume labels, |
| 269 | 279 | * hidden files and system files may be returned. |
| 270 | 280 | */ |
| 271 | -static struct _wdirent *_wreaddir(_WDIR *dirp) | |
| 281 | +static struct dirent *readdir(DIR *dirp) | |
| 272 | 282 | { |
| 273 | 283 | DWORD attr; |
| 274 | 284 | if (dirp == NULL) { |
| 275 | 285 | /* directory stream did not open */ |
| 276 | 286 | DIRENT_SET_ERRNO (EBADF); |
| @@ -284,11 +294,11 @@ | ||
| 284 | 294 | } else { |
| 285 | 295 | /* get the next directory entry from stream */ |
| 286 | 296 | if (dirp->search_handle == INVALID_HANDLE_VALUE) { |
| 287 | 297 | return NULL; |
| 288 | 298 | } |
| 289 | - if (FindNextFileW (dirp->search_handle, &dirp->find_data) == FALSE) { | |
| 299 | + if (FindNextFile (dirp->search_handle, &dirp->find_data) == FALSE) { | |
| 290 | 300 | /* the very last entry has been processed or an error occured */ |
| 291 | 301 | FindClose (dirp->search_handle); |
| 292 | 302 | dirp->search_handle = INVALID_HANDLE_VALUE; |
| 293 | 303 | return NULL; |
| 294 | 304 | } |
| @@ -299,11 +309,11 @@ | ||
| 299 | 309 | dirp->find_data.cFileName, |
| 300 | 310 | sizeof(dirp->curentry.d_name)/sizeof(dirp->curentry.d_name[0]) ); |
| 301 | 311 | dirp->curentry.d_name[MAX_PATH] = '\0'; |
| 302 | 312 | |
| 303 | 313 | /* compute the length of name */ |
| 304 | - dirp->curentry.d_namlen = wcslen (dirp->curentry.d_name); | |
| 314 | + dirp->curentry.d_namlen = _tcslen (dirp->curentry.d_name); | |
| 305 | 315 | |
| 306 | 316 | /* determine file type */ |
| 307 | 317 | attr = dirp->find_data.dwFileAttributes; |
| 308 | 318 | if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) { |
| 309 | 319 | dirp->curentry.d_type = DT_CHR; |
| @@ -319,11 +329,11 @@ | ||
| 319 | 329 | /***************************************************************************** |
| 320 | 330 | * Close directory stream opened by opendir() function. Close of the |
| 321 | 331 | * directory stream invalidates the DIR structure as well as any previously |
| 322 | 332 | * read directory entry. |
| 323 | 333 | */ |
| 324 | -static int _wclosedir(_WDIR *dirp) | |
| 334 | +static int closedir(DIR *dirp) | |
| 325 | 335 | { |
| 326 | 336 | if (dirp == NULL) { |
| 327 | 337 | /* invalid directory stream */ |
| 328 | 338 | DIRENT_SET_ERRNO (EBADF); |
| 329 | 339 | return -1; |
| @@ -338,10 +348,19 @@ | ||
| 338 | 348 | /* release directory structure */ |
| 339 | 349 | free (dirp); |
| 340 | 350 | return 0; |
| 341 | 351 | } |
| 342 | 352 | |
| 353 | +#ifdef UNICODE | |
| 354 | +# undef dirent | |
| 355 | +# undef opendir | |
| 356 | +# undef readdir | |
| 357 | +# undef closedir | |
| 358 | +# undef DIR | |
| 359 | +#else | |
| 360 | +# undef wchar_t | |
| 361 | +#endif | |
| 343 | 362 | |
| 344 | 363 | #ifdef __cplusplus |
| 345 | 364 | } |
| 346 | 365 | #endif |
| 347 | 366 | #endif /*DIRENT_H*/ |
| 348 | 367 |
| --- win/include/dirent.h | |
| +++ win/include/dirent.h | |
| @@ -85,10 +85,11 @@ | |
| 85 | #include <string.h> |
| 86 | #include <stdlib.h> |
| 87 | #include <sys/types.h> |
| 88 | #include <sys/stat.h> |
| 89 | #include <errno.h> |
| 90 | |
| 91 | /* Entries missing from MSVC 6.0 */ |
| 92 | #if !defined(FILE_ATTRIBUTE_DEVICE) |
| 93 | # define FILE_ATTRIBUTE_DEVICE 0x40 |
| 94 | #endif |
| @@ -152,40 +153,49 @@ | |
| 152 | |
| 153 | #ifdef __cplusplus |
| 154 | extern "C" { |
| 155 | #endif |
| 156 | |
| 157 | |
| 158 | typedef struct _wdirent |
| 159 | { |
| 160 | wchar_t d_name[MAX_PATH + 1]; /* File name */ |
| 161 | size_t d_namlen; /* Length of name without \0 */ |
| 162 | int d_type; /* File type */ |
| 163 | } _wdirent; |
| 164 | |
| 165 | |
| 166 | typedef struct _WDIR |
| 167 | { |
| 168 | _wdirent curentry; /* Current directory entry */ |
| 169 | WIN32_FIND_DATAW find_data; /* Private file data */ |
| 170 | int cached; /* True if data is valid */ |
| 171 | HANDLE search_handle; /* Win32 search handle */ |
| 172 | wchar_t patt[MAX_PATH + 3]; /* Initial directory name */ |
| 173 | } _WDIR; |
| 174 | |
| 175 | |
| 176 | /* Forward declarations */ |
| 177 | static _WDIR *_wopendir(const wchar_t *dirname); |
| 178 | static struct _wdirent *_wreaddir(_WDIR *dirp); |
| 179 | static int _wclosedir(_WDIR *dirp); |
| 180 | |
| 181 | |
| 182 | /* Use the new safe string functions introduced in Visual Studio 2005 */ |
| 183 | #if defined(_MSC_VER) && _MSC_VER >= 1400 |
| 184 | # define DIRENT_STRNCPY(dest,src,size) wcsncpy_s((dest),(size),(src),_TRUNCATE) |
| 185 | #else |
| 186 | # define DIRENT_STRNCPY(dest,src,size) wcsncpy((dest),(src),(size)) |
| 187 | #endif |
| 188 | |
| 189 | /* Set errno variable */ |
| 190 | #if defined(_MSC_VER) |
| 191 | #define DIRENT_SET_ERRNO(x) _set_errno (x) |
| @@ -197,47 +207,47 @@ | |
| 197 | /***************************************************************************** |
| 198 | * Open directory stream DIRNAME for read and return a pointer to the |
| 199 | * internal working area that is used to retrieve individual directory |
| 200 | * entries. |
| 201 | */ |
| 202 | static _WDIR *_wopendir(const wchar_t *dirname) |
| 203 | { |
| 204 | _WDIR *dirp; |
| 205 | |
| 206 | /* ensure that the resulting search pattern will be a valid file name */ |
| 207 | if (dirname == NULL) { |
| 208 | DIRENT_SET_ERRNO (ENOENT); |
| 209 | return NULL; |
| 210 | } |
| 211 | if (wcslen (dirname) + 3 >= MAX_PATH) { |
| 212 | DIRENT_SET_ERRNO (ENAMETOOLONG); |
| 213 | return NULL; |
| 214 | } |
| 215 | |
| 216 | /* construct new DIR structure */ |
| 217 | dirp = (_WDIR*) malloc (sizeof (struct _WDIR)); |
| 218 | if (dirp != NULL) { |
| 219 | int error; |
| 220 | |
| 221 | /* |
| 222 | * Convert relative directory name to an absolute one. This |
| 223 | * allows rewinddir() to function correctly when the current working |
| 224 | * directory is changed between opendir() and rewinddir(). |
| 225 | */ |
| 226 | if (GetFullPathNameW (dirname, MAX_PATH, dirp->patt, NULL)) { |
| 227 | wchar_t *p; |
| 228 | |
| 229 | /* append the search pattern "\\*\0" to the directory name */ |
| 230 | p = wcschr (dirp->patt, '\0'); |
| 231 | if (dirp->patt < p && *(p-1) != '\\' && *(p-1) != ':') { |
| 232 | *p++ = '\\'; |
| 233 | } |
| 234 | *p++ = '*'; |
| 235 | *p = '\0'; |
| 236 | |
| 237 | /* open directory stream and retrieve the first entry */ |
| 238 | dirp->search_handle = FindFirstFileW (dirp->patt, &dirp->find_data); |
| 239 | if (dirp->search_handle != INVALID_HANDLE_VALUE) { |
| 240 | /* a directory entry is now waiting in memory */ |
| 241 | dirp->cached = 1; |
| 242 | error = 0; |
| 243 | } else { |
| @@ -266,11 +276,11 @@ | |
| 266 | * containing the name of the entry in d_name field. Individual directory |
| 267 | * entries returned by this very function include regular files, |
| 268 | * sub-directories, pseudo-directories "." and "..", but also volume labels, |
| 269 | * hidden files and system files may be returned. |
| 270 | */ |
| 271 | static struct _wdirent *_wreaddir(_WDIR *dirp) |
| 272 | { |
| 273 | DWORD attr; |
| 274 | if (dirp == NULL) { |
| 275 | /* directory stream did not open */ |
| 276 | DIRENT_SET_ERRNO (EBADF); |
| @@ -284,11 +294,11 @@ | |
| 284 | } else { |
| 285 | /* get the next directory entry from stream */ |
| 286 | if (dirp->search_handle == INVALID_HANDLE_VALUE) { |
| 287 | return NULL; |
| 288 | } |
| 289 | if (FindNextFileW (dirp->search_handle, &dirp->find_data) == FALSE) { |
| 290 | /* the very last entry has been processed or an error occured */ |
| 291 | FindClose (dirp->search_handle); |
| 292 | dirp->search_handle = INVALID_HANDLE_VALUE; |
| 293 | return NULL; |
| 294 | } |
| @@ -299,11 +309,11 @@ | |
| 299 | dirp->find_data.cFileName, |
| 300 | sizeof(dirp->curentry.d_name)/sizeof(dirp->curentry.d_name[0]) ); |
| 301 | dirp->curentry.d_name[MAX_PATH] = '\0'; |
| 302 | |
| 303 | /* compute the length of name */ |
| 304 | dirp->curentry.d_namlen = wcslen (dirp->curentry.d_name); |
| 305 | |
| 306 | /* determine file type */ |
| 307 | attr = dirp->find_data.dwFileAttributes; |
| 308 | if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) { |
| 309 | dirp->curentry.d_type = DT_CHR; |
| @@ -319,11 +329,11 @@ | |
| 319 | /***************************************************************************** |
| 320 | * Close directory stream opened by opendir() function. Close of the |
| 321 | * directory stream invalidates the DIR structure as well as any previously |
| 322 | * read directory entry. |
| 323 | */ |
| 324 | static int _wclosedir(_WDIR *dirp) |
| 325 | { |
| 326 | if (dirp == NULL) { |
| 327 | /* invalid directory stream */ |
| 328 | DIRENT_SET_ERRNO (EBADF); |
| 329 | return -1; |
| @@ -338,10 +348,19 @@ | |
| 338 | /* release directory structure */ |
| 339 | free (dirp); |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | |
| 344 | #ifdef __cplusplus |
| 345 | } |
| 346 | #endif |
| 347 | #endif /*DIRENT_H*/ |
| 348 |
| --- win/include/dirent.h | |
| +++ win/include/dirent.h | |
| @@ -85,10 +85,11 @@ | |
| 85 | #include <string.h> |
| 86 | #include <stdlib.h> |
| 87 | #include <sys/types.h> |
| 88 | #include <sys/stat.h> |
| 89 | #include <errno.h> |
| 90 | #include <tchar.h> |
| 91 | |
| 92 | /* Entries missing from MSVC 6.0 */ |
| 93 | #if !defined(FILE_ATTRIBUTE_DEVICE) |
| 94 | # define FILE_ATTRIBUTE_DEVICE 0x40 |
| 95 | #endif |
| @@ -152,40 +153,49 @@ | |
| 153 | |
| 154 | #ifdef __cplusplus |
| 155 | extern "C" { |
| 156 | #endif |
| 157 | |
| 158 | #ifdef UNICODE |
| 159 | # define dirent _wdirent |
| 160 | # define opendir _wopendir |
| 161 | # define readdir _wreaddir |
| 162 | # define closedir _wclosedir |
| 163 | # define DIR _WDIR |
| 164 | #else |
| 165 | # define wchar_t char |
| 166 | #endif |
| 167 | |
| 168 | typedef struct dirent |
| 169 | { |
| 170 | wchar_t d_name[MAX_PATH + 1]; /* File name */ |
| 171 | size_t d_namlen; /* Length of name without \0 */ |
| 172 | int d_type; /* File type */ |
| 173 | } dirent; |
| 174 | |
| 175 | |
| 176 | typedef struct DIR |
| 177 | { |
| 178 | dirent curentry; /* Current directory entry */ |
| 179 | WIN32_FIND_DATA find_data; /* Private file data */ |
| 180 | int cached; /* True if data is valid */ |
| 181 | HANDLE search_handle; /* Win32 search handle */ |
| 182 | wchar_t patt[MAX_PATH + 3]; /* Initial directory name */ |
| 183 | } DIR; |
| 184 | |
| 185 | |
| 186 | /* Forward declarations */ |
| 187 | static DIR *opendir(const wchar_t *dirname); |
| 188 | static struct dirent *readdir(DIR *dirp); |
| 189 | static int closedir(DIR *dirp); |
| 190 | |
| 191 | |
| 192 | /* Use the new safe string functions introduced in Visual Studio 2005 */ |
| 193 | #if defined(_MSC_VER) && _MSC_VER >= 1400 |
| 194 | # define DIRENT_STRNCPY(dest,src,size) _tcsncpy_s((dest),(size),(src),_TRUNCATE) |
| 195 | #else |
| 196 | # define DIRENT_STRNCPY(dest,src,size) _tcsncpy((dest),(src),(size)) |
| 197 | #endif |
| 198 | |
| 199 | /* Set errno variable */ |
| 200 | #if defined(_MSC_VER) |
| 201 | #define DIRENT_SET_ERRNO(x) _set_errno (x) |
| @@ -197,47 +207,47 @@ | |
| 207 | /***************************************************************************** |
| 208 | * Open directory stream DIRNAME for read and return a pointer to the |
| 209 | * internal working area that is used to retrieve individual directory |
| 210 | * entries. |
| 211 | */ |
| 212 | static DIR *opendir(const wchar_t *dirname) |
| 213 | { |
| 214 | DIR *dirp; |
| 215 | |
| 216 | /* ensure that the resulting search pattern will be a valid file name */ |
| 217 | if (dirname == NULL) { |
| 218 | DIRENT_SET_ERRNO (ENOENT); |
| 219 | return NULL; |
| 220 | } |
| 221 | if (_tcslen (dirname) + 3 >= MAX_PATH) { |
| 222 | DIRENT_SET_ERRNO (ENAMETOOLONG); |
| 223 | return NULL; |
| 224 | } |
| 225 | |
| 226 | /* construct new DIR structure */ |
| 227 | dirp = (DIR*) malloc (sizeof (struct DIR)); |
| 228 | if (dirp != NULL) { |
| 229 | int error; |
| 230 | |
| 231 | /* |
| 232 | * Convert relative directory name to an absolute one. This |
| 233 | * allows rewinddir() to function correctly when the current working |
| 234 | * directory is changed between opendir() and rewinddir(). |
| 235 | */ |
| 236 | if (GetFullPathName (dirname, MAX_PATH, dirp->patt, NULL)) { |
| 237 | wchar_t *p; |
| 238 | |
| 239 | /* append the search pattern "\\*\0" to the directory name */ |
| 240 | p = _tcschr (dirp->patt, '\0'); |
| 241 | if (dirp->patt < p && *(p-1) != '\\' && *(p-1) != ':') { |
| 242 | *p++ = '\\'; |
| 243 | } |
| 244 | *p++ = '*'; |
| 245 | *p = '\0'; |
| 246 | |
| 247 | /* open directory stream and retrieve the first entry */ |
| 248 | dirp->search_handle = FindFirstFile (dirp->patt, &dirp->find_data); |
| 249 | if (dirp->search_handle != INVALID_HANDLE_VALUE) { |
| 250 | /* a directory entry is now waiting in memory */ |
| 251 | dirp->cached = 1; |
| 252 | error = 0; |
| 253 | } else { |
| @@ -266,11 +276,11 @@ | |
| 276 | * containing the name of the entry in d_name field. Individual directory |
| 277 | * entries returned by this very function include regular files, |
| 278 | * sub-directories, pseudo-directories "." and "..", but also volume labels, |
| 279 | * hidden files and system files may be returned. |
| 280 | */ |
| 281 | static struct dirent *readdir(DIR *dirp) |
| 282 | { |
| 283 | DWORD attr; |
| 284 | if (dirp == NULL) { |
| 285 | /* directory stream did not open */ |
| 286 | DIRENT_SET_ERRNO (EBADF); |
| @@ -284,11 +294,11 @@ | |
| 294 | } else { |
| 295 | /* get the next directory entry from stream */ |
| 296 | if (dirp->search_handle == INVALID_HANDLE_VALUE) { |
| 297 | return NULL; |
| 298 | } |
| 299 | if (FindNextFile (dirp->search_handle, &dirp->find_data) == FALSE) { |
| 300 | /* the very last entry has been processed or an error occured */ |
| 301 | FindClose (dirp->search_handle); |
| 302 | dirp->search_handle = INVALID_HANDLE_VALUE; |
| 303 | return NULL; |
| 304 | } |
| @@ -299,11 +309,11 @@ | |
| 309 | dirp->find_data.cFileName, |
| 310 | sizeof(dirp->curentry.d_name)/sizeof(dirp->curentry.d_name[0]) ); |
| 311 | dirp->curentry.d_name[MAX_PATH] = '\0'; |
| 312 | |
| 313 | /* compute the length of name */ |
| 314 | dirp->curentry.d_namlen = _tcslen (dirp->curentry.d_name); |
| 315 | |
| 316 | /* determine file type */ |
| 317 | attr = dirp->find_data.dwFileAttributes; |
| 318 | if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) { |
| 319 | dirp->curentry.d_type = DT_CHR; |
| @@ -319,11 +329,11 @@ | |
| 329 | /***************************************************************************** |
| 330 | * Close directory stream opened by opendir() function. Close of the |
| 331 | * directory stream invalidates the DIR structure as well as any previously |
| 332 | * read directory entry. |
| 333 | */ |
| 334 | static int closedir(DIR *dirp) |
| 335 | { |
| 336 | if (dirp == NULL) { |
| 337 | /* invalid directory stream */ |
| 338 | DIRENT_SET_ERRNO (EBADF); |
| 339 | return -1; |
| @@ -338,10 +348,19 @@ | |
| 348 | /* release directory structure */ |
| 349 | free (dirp); |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | #ifdef UNICODE |
| 354 | # undef dirent |
| 355 | # undef opendir |
| 356 | # undef readdir |
| 357 | # undef closedir |
| 358 | # undef DIR |
| 359 | #else |
| 360 | # undef wchar_t |
| 361 | #endif |
| 362 | |
| 363 | #ifdef __cplusplus |
| 364 | } |
| 365 | #endif |
| 366 | #endif /*DIRENT_H*/ |
| 367 |