Typos and due casts. As for the latter. It's "safe" to cast as below,

because "wrong" casts will either be optimized away or never performed.
This commit is contained in:
Andy Polyakov 2004-07-25 16:48:28 +00:00
parent 8611934352
commit da2ee71de5

View File

@ -41,6 +41,10 @@
# define FindNextFile FindNextFileW # define FindNextFile FindNextFileW
#endif #endif
#ifndef NAME_MAX
#define NAME_MAX 255
#endif
struct LP_dir_context_st struct LP_dir_context_st
{ {
WIN32_FIND_DATA ctx; WIN32_FIND_DATA ctx;
@ -73,7 +77,7 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
{ {
TCHAR *wdir = NULL; TCHAR *wdir = NULL;
/* len_0 denotes string length *with* trailing 0 */ /* len_0 denotes string length *with* trailing 0 */
size_t index = 0,len_0 = strlen(direcory) + 1; size_t index = 0,len_0 = strlen(directory) + 1;
wdir = (TCHAR *)malloc(len_0 * sizeof(TCHAR)); wdir = (TCHAR *)malloc(len_0 * sizeof(TCHAR));
if (wdir == NULL) if (wdir == NULL)
@ -85,7 +89,7 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
} }
#ifdef LP_MULTIBYTE_AVAILABLE #ifdef LP_MULTIBYTE_AVAILABLE
if (!MultiByteToWideChar(CP_ACP, 0, directory, len_0, wdir, len_0)) if (!MultiByteToWideChar(CP_ACP, 0, directory, len_0, (WCHAR *)wdir, len_0))
#endif #endif
for (index = 0; index < len_0; index++) for (index = 0; index < len_0; index++)
wdir[index] = (TCHAR)directory[index]; wdir[index] = (TCHAR)directory[index];
@ -95,7 +99,7 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
free(wdir); free(wdir);
} }
else else
(*ctx)->handle = FindFirstFile(directory, &(*ctx)->ctx); (*ctx)->handle = FindFirstFile((TCHAR *)directory, &(*ctx)->ctx);
if ((*ctx)->handle == INVALID_HANDLE_VALUE) if ((*ctx)->handle == INVALID_HANDLE_VALUE)
{ {
@ -107,7 +111,7 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
} }
else else
{ {
if (FindNextFile((*ctx)->handle, (*ctx)->ctx) == FALSE) if (FindNextFile((*ctx)->handle, &(*ctx)->ctx) == FALSE)
{ {
return 0; return 0;
} }
@ -118,18 +122,18 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
TCHAR *wdir = (*ctx)->ctx.cFileName; TCHAR *wdir = (*ctx)->ctx.cFileName;
size_t index, len_0 = 0; size_t index, len_0 = 0;
while (wdir[len] && len < (sizeof((*ctx)->entry_name) - 1)) len_0++; while (wdir[len_0] && len_0 < (sizeof((*ctx)->entry_name) - 1)) len_0++;
len_0++; len_0++;
#ifdef LP_MULTIBYTE_AVAILABLE #ifdef LP_MULTIBYTE_AVAILABLE
if (!WideCharToMultiByte(CP_ACP, 0, wdir, len_0, (*ctx)->entry_name, if (!WideCharToMultiByte(CP_ACP, 0, (WCHAR *)wdir, len_0, (*ctx)->entry_name,
sizeof((*ctx)->entry_name), NULL, 0)) sizeof((*ctx)->entry_name), NULL, 0))
#endif #endif
for (index = 0; index < len_0; index++) for (index = 0; index < len_0; index++)
(*ctx)->entry_name[index] = (char)wdir[index]; (*ctx)->entry_name[index] = (char)wdir[index];
} }
else else
strncpy((*ctx)->entry_name, (*ctx)->ctx.cFileName, strncpy((*ctx)->entry_name, (const char *)(*ctx)->ctx.cFileName,
sizeof((*ctx)->entry_name)-1); sizeof((*ctx)->entry_name)-1);
(*ctx)->entry_name[sizeof((*ctx)->entry_name)-1] = '\0'; (*ctx)->entry_name[sizeof((*ctx)->entry_name)-1] = '\0';