| | @@ -154,37 +154,38 @@ |
| 154 | 154 | |
| 155 | 155 | #ifdef __cplusplus |
| 156 | 156 | extern "C" { |
| 157 | 157 | #endif |
| 158 | 158 | |
| 159 | | -typedef struct dirent |
| 159 | +typedef struct _wdirent |
| 160 | 160 | { |
| 161 | 161 | WCHAR d_name[MAX_PATH + 1]; /* File name */ |
| 162 | 162 | size_t d_namlen; /* Length of name without \0 */ |
| 163 | 163 | int d_type; /* File type */ |
| 164 | | -} dirent; |
| 164 | +} _wdirent; |
| 165 | 165 | |
| 166 | 166 | |
| 167 | | -typedef struct DIR |
| 167 | +typedef struct _WDIR |
| 168 | 168 | { |
| 169 | | - dirent curentry; /* Current directory entry */ |
| 169 | + _wdirent curentry; /* Current directory entry */ |
| 170 | 170 | WIN32_FIND_DATAW find_data; /* Private file data */ |
| 171 | 171 | int cached; /* True if data is valid */ |
| 172 | 172 | HANDLE search_handle; /* Win32 search handle */ |
| 173 | 173 | WCHAR patt[MAX_PATH + 3]; /* Initial directory name */ |
| 174 | | -} DIR; |
| 174 | +} _WDIR; |
| 175 | 175 | |
| 176 | 176 | |
| 177 | 177 | /* Forward declarations */ |
| 178 | | -static DIR *opendir(const WCHAR *dirname); |
| 179 | | -static struct dirent *readdir(DIR *dirp); |
| 180 | | -static int closedir(DIR *dirp); |
| 181 | | -static void rewinddir(DIR* dirp); |
| 178 | +static _WDIR *_wopendir(const WCHAR *dirname); |
| 179 | +static struct _wdirent *_wreaddir(_WDIR *dirp); |
| 180 | +static int _wclosedir(_WDIR *dirp); |
| 181 | +static void _wrewinddir(_WDIR* dirp); |
| 182 | 182 | |
| 183 | 183 | |
| 184 | 184 | /* Use the new safe string functions introduced in Visual Studio 2005 */ |
| 185 | 185 | #if defined(_MSC_VER) && _MSC_VER >= 1400 |
| 186 | + |
| 186 | 187 | # define DIRENT_STRNCPY(dest,src,size) wcsncpy_s((dest),(size),(src),_TRUNCATE) |
| 187 | 188 | #else |
| 188 | 189 | # define DIRENT_STRNCPY(dest,src,size) wcsncpy((dest),(src),(size)) |
| 189 | 190 | #endif |
| 190 | 191 | |
| | @@ -199,13 +200,13 @@ |
| 199 | 200 | /***************************************************************************** |
| 200 | 201 | * Open directory stream DIRNAME for read and return a pointer to the |
| 201 | 202 | * internal working area that is used to retrieve individual directory |
| 202 | 203 | * entries. |
| 203 | 204 | */ |
| 204 | | -static DIR *opendir(const WCHAR *dirname) |
| 205 | +static _WDIR *_wopendir(const WCHAR *dirname) |
| 205 | 206 | { |
| 206 | | - DIR *dirp; |
| 207 | + _WDIR *dirp; |
| 207 | 208 | |
| 208 | 209 | /* ensure that the resulting search pattern will be a valid file name */ |
| 209 | 210 | if (dirname == NULL) { |
| 210 | 211 | DIRENT_SET_ERRNO (ENOENT); |
| 211 | 212 | return NULL; |
| | @@ -213,12 +214,12 @@ |
| 213 | 214 | if (wcslen (dirname) + 3 >= MAX_PATH) { |
| 214 | 215 | DIRENT_SET_ERRNO (ENAMETOOLONG); |
| 215 | 216 | return NULL; |
| 216 | 217 | } |
| 217 | 218 | |
| 218 | | - /* construct new DIR structure */ |
| 219 | | - dirp = (DIR*) malloc (sizeof (struct DIR)); |
| 219 | + /* construct new _WDIR structure */ |
| 220 | + dirp = (_WDIR*) malloc (sizeof (struct _WDIR)); |
| 220 | 221 | if (dirp != NULL) { |
| 221 | 222 | int error; |
| 222 | 223 | |
| 223 | 224 | /* |
| 224 | 225 | * Convert relative directory name to an absolute one. This |
| | @@ -262,17 +263,17 @@ |
| 262 | 263 | return dirp; |
| 263 | 264 | } |
| 264 | 265 | |
| 265 | 266 | |
| 266 | 267 | /***************************************************************************** |
| 267 | | - * Read a directory entry, and return a pointer to a dirent structure |
| 268 | + * Read a directory entry, and return a pointer to a _wdirent structure |
| 268 | 269 | * containing the name of the entry in d_name field. Individual directory |
| 269 | 270 | * entries returned by this very function include regular files, |
| 270 | 271 | * sub-directories, pseudo-directories "." and "..", but also volume labels, |
| 271 | 272 | * hidden files and system files may be returned. |
| 272 | 273 | */ |
| 273 | | -static struct dirent *readdir(DIR *dirp) |
| 274 | +static struct _wdirent *_wreaddir(_WDIR *dirp) |
| 274 | 275 | { |
| 275 | 276 | DWORD attr; |
| 276 | 277 | if (dirp == NULL) { |
| 277 | 278 | /* directory stream did not open */ |
| 278 | 279 | DIRENT_SET_ERRNO (EBADF); |
| | @@ -318,14 +319,14 @@ |
| 318 | 319 | } |
| 319 | 320 | |
| 320 | 321 | |
| 321 | 322 | /***************************************************************************** |
| 322 | 323 | * Close directory stream opened by opendir() function. Close of the |
| 323 | | - * directory stream invalidates the DIR structure as well as any previously |
| 324 | + * directory stream invalidates the _WDIR structure as well as any previously |
| 324 | 325 | * read directory entry. |
| 325 | 326 | */ |
| 326 | | -static int closedir(DIR *dirp) |
| 327 | +static int _wclosedir(_WDIR *dirp) |
| 327 | 328 | { |
| 328 | 329 | if (dirp == NULL) { |
| 329 | 330 | /* invalid directory stream */ |
| 330 | 331 | DIRENT_SET_ERRNO (EBADF); |
| 331 | 332 | return -1; |
| | @@ -347,11 +348,11 @@ |
| 347 | 348 | * beginning of the directory. It also causes the directory stream to refer |
| 348 | 349 | * to the current state of the corresponding directory, as a call to opendir() |
| 349 | 350 | * would have done. If dirp does not refer to a directory stream, the effect |
| 350 | 351 | * is undefined. |
| 351 | 352 | */ |
| 352 | | -static void rewinddir(DIR* dirp) |
| 353 | +static void _wrewinddir(_WDIR* dirp) |
| 353 | 354 | { |
| 354 | 355 | if (dirp != NULL) { |
| 355 | 356 | /* release search handle */ |
| 356 | 357 | if (dirp->search_handle != INVALID_HANDLE_VALUE) { |
| 357 | 358 | FindClose (dirp->search_handle); |
| 358 | 359 | |