| | @@ -1,8 +1,8 @@ |
| 1 | 1 | /* |
| 2 | 2 | * Dirent interface for Microsoft Visual Studio |
| 3 | | - * Version 1.21 |
| 3 | + * Version 1.22 |
| 4 | 4 | * |
| 5 | 5 | * Copyright (C) 2006-2012 Toni Ronkko |
| 6 | 6 | * This file is part of dirent. Dirent may be freely distributed |
| 7 | 7 | * under the MIT license. For all details and documentation, see |
| 8 | 8 | * https://github.com/tronkko/dirent |
| | @@ -9,25 +9,20 @@ |
| 9 | 9 | */ |
| 10 | 10 | #ifndef DIRENT_H |
| 11 | 11 | #define DIRENT_H |
| 12 | 12 | |
| 13 | 13 | /* |
| 14 | | - * Define architecture flags so we don't need to include windows.h. |
| 15 | | - * Avoiding windows.h makes it simpler to use windows sockets in conjunction |
| 16 | | - * with dirent.h. |
| 14 | + * Include windows.h without Windows Sockets 1.1 to prevent conflicts with |
| 15 | + * Windows Sockets 2.0. |
| 17 | 16 | */ |
| 18 | | -#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_IX86) |
| 19 | | -# define _X86_ |
| 17 | +#ifndef WIN32_LEAN_AND_MEAN |
| 18 | +# define WIN32_LEAN_AND_MEAN |
| 20 | 19 | #endif |
| 21 | | -#if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_AMD64) |
| 22 | | -#define _AMD64_ |
| 23 | | -#endif |
| 20 | +#include <windows.h> |
| 24 | 21 | |
| 25 | 22 | #include <stdio.h> |
| 26 | 23 | #include <stdarg.h> |
| 27 | | -#include <windef.h> |
| 28 | | -#include <winbase.h> |
| 29 | 24 | #include <wchar.h> |
| 30 | 25 | #include <string.h> |
| 31 | 26 | #include <stdlib.h> |
| 32 | 27 | #include <malloc.h> |
| 33 | 28 | #include <sys/types.h> |
| | @@ -344,23 +339,38 @@ |
| 344 | 339 | /* Reset _WDIR structure */ |
| 345 | 340 | dirp->handle = INVALID_HANDLE_VALUE; |
| 346 | 341 | dirp->patt = NULL; |
| 347 | 342 | dirp->cached = 0; |
| 348 | 343 | |
| 349 | | - /* Compute the length of full path plus zero terminator */ |
| 350 | | - n = GetFullPathNameW (dirname, 0, NULL, NULL); |
| 344 | + /* Compute the length of full path plus zero terminator |
| 345 | + * |
| 346 | + * Note that on WinRT there's no way to convert relative paths |
| 347 | + * into absolute paths, so just assume its an absolute path. |
| 348 | + */ |
| 349 | +# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) |
| 350 | + n = wcslen(dirname); |
| 351 | +# else |
| 352 | + n = GetFullPathNameW (dirname, 0, NULL, NULL); |
| 353 | +# endif |
| 351 | 354 | |
| 352 | 355 | /* Allocate room for absolute directory name and search pattern */ |
| 353 | 356 | dirp->patt = (wchar_t*) malloc (sizeof (wchar_t) * n + 16); |
| 354 | 357 | if (dirp->patt) { |
| 355 | 358 | |
| 356 | 359 | /* |
| 357 | 360 | * Convert relative directory name to an absolute one. This |
| 358 | 361 | * allows rewinddir() to function correctly even when current |
| 359 | 362 | * working directory is changed between opendir() and rewinddir(). |
| 363 | + * |
| 364 | + * Note that on WinRT there's no way to convert relative paths |
| 365 | + * into absolute paths, so just assume its an absolute path. |
| 360 | 366 | */ |
| 361 | | - n = GetFullPathNameW (dirname, n, dirp->patt, NULL); |
| 367 | +# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) |
| 368 | + wcsncpy_s(dirp->patt, n+1, dirname, n); |
| 369 | +# else |
| 370 | + n = GetFullPathNameW (dirname, n, dirp->patt, NULL); |
| 371 | +# endif |
| 362 | 372 | if (n > 0) { |
| 363 | 373 | wchar_t *p; |
| 364 | 374 | |
| 365 | 375 | /* Append search pattern \* to the directory name */ |
| 366 | 376 | p = dirp->patt + n; |
| | @@ -538,11 +548,13 @@ |
| 538 | 548 | _WDIR *dirp) |
| 539 | 549 | { |
| 540 | 550 | WIN32_FIND_DATAW *datap; |
| 541 | 551 | |
| 542 | 552 | /* Open directory and retrieve the first entry */ |
| 543 | | - dirp->handle = FindFirstFileW (dirp->patt, &dirp->data); |
| 553 | + dirp->handle = FindFirstFileExW( |
| 554 | + dirp->patt, FindExInfoStandard, &dirp->data, |
| 555 | + FindExSearchNameMatch, NULL, 0); |
| 544 | 556 | if (dirp->handle != INVALID_HANDLE_VALUE) { |
| 545 | 557 | |
| 546 | 558 | /* a directory entry is now waiting in memory */ |
| 547 | 559 | datap = &dirp->data; |
| 548 | 560 | dirp->cached = 1; |
| | @@ -869,11 +881,11 @@ |
| 869 | 881 | n = sizeInBytes - 1; |
| 870 | 882 | } |
| 871 | 883 | mbstr[n] = '\0'; |
| 872 | 884 | } |
| 873 | 885 | |
| 874 | | - /* Lenght of resulting multi-bytes string WITH zero-terminator */ |
| 886 | + /* Length of resulting multi-bytes string WITH zero-terminator */ |
| 875 | 887 | if (pReturnValue) { |
| 876 | 888 | *pReturnValue = n + 1; |
| 877 | 889 | } |
| 878 | 890 | |
| 879 | 891 | /* Success */ |
| 880 | 892 | |