diff options
author | blythe%netscape.com <devnull@localhost> | 2002-02-06 22:46:56 +0000 |
---|---|---|
committer | blythe%netscape.com <devnull@localhost> | 2002-02-06 22:46:56 +0000 |
commit | 74b6a679ac1b0e10f83e5907a150784ef687d401 (patch) | |
tree | cd00cba688450425682e90f215b8a8fbdfe569be | |
parent | e2654805a55fe4162441245ace95ad4d1125f0cf (diff) | |
download | nspr-hg-74b6a679ac1b0e10f83e5907a150784ef687d401.tar.gz |
wide character conversions for file io
-rw-r--r-- | pr/include/md/_win32_unicode.h | 11 | ||||
-rw-r--r-- | pr/include/md/_wince.h | 1 | ||||
-rw-r--r-- | pr/src/md/windows/w32unicode.c | 31 | ||||
-rw-r--r-- | pr/src/md/windows/w95io.c | 91 |
4 files changed, 124 insertions, 10 deletions
diff --git a/pr/include/md/_win32_unicode.h b/pr/include/md/_win32_unicode.h index 71e16e7b..b302e2c4 100644 --- a/pr/include/md/_win32_unicode.h +++ b/pr/include/md/_win32_unicode.h @@ -48,4 +48,15 @@ */ LPWSTR _PR_MD_MALLOC_A2W(LPCSTR inString); +/* + * _PR_MD_A2W + * + * Non-mallocing/faster version to return a wide char string based on the + * ANSI (multi byte, ansi code page) string passed in. + * + * NOTE: inWideStringChars is number of wide characters in outWideString, + * NOT the number of bytes.... + */ +LPWSTR _PR_MD_A2W(LPCSTR inString, LPWSTR outWideString, int inWideStringChars); + #endif /* nspr_win32_unicode_h___ */ diff --git a/pr/include/md/_wince.h b/pr/include/md/_wince.h index f62fd96b..3f245068 100644 --- a/pr/include/md/_wince.h +++ b/pr/include/md/_wince.h @@ -121,6 +121,7 @@ struct _MDSegment { struct _MDDir { HANDLE d_hdl; WIN32_FIND_DATA d_entry; + CHAR cFileNameA[ MAX_PATH ]; PRBool firstEntry; /* Is this the entry returned * by FindFirstFile()? */ PRUint32 magic; /* for debugging */ diff --git a/pr/src/md/windows/w32unicode.c b/pr/src/md/windows/w32unicode.c index c36c87f2..467fed06 100644 --- a/pr/src/md/windows/w32unicode.c +++ b/pr/src/md/windows/w32unicode.c @@ -69,7 +69,7 @@ LPWSTR _PR_MD_MALLOC_A2W(LPCSTR inString) { int neededWChars = 0; - neededWChars = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (inString), -1, NULL, 0); + neededWChars = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, inString, -1, NULL, 0); if(0 < neededWChars) { LPWSTR wstr = NULL; @@ -79,7 +79,7 @@ LPWSTR _PR_MD_MALLOC_A2W(LPCSTR inString) { int convertRes = 0; - convertRes = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (inString), -1, wstr, neededWChars); + convertRes = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, inString, -1, wstr, neededWChars); if(0 == convertRes) { PR_Free(wstr); @@ -95,6 +95,33 @@ LPWSTR _PR_MD_MALLOC_A2W(LPCSTR inString) return retval; } +/* + * _PR_MD_A2W + * + * Non-mallocing version to return a wide char string based on the + * ANSI (multi byte, ansi code page) string passed in. + * + * NOTE: inWideStringChars is number of wide characters in outWideString, + * NOT the number of bytes.... + */ +LPWSTR _PR_MD_A2W(LPCSTR inString, LPWSTR outWideString, int inWideStringChars) +{ + LPWSTR retval = outWideString; + + if(NULL != outWideString) + { + int convertRes = 0; + + convertRes = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, inString, -1, outWideString, inWideStringChars); + if(0 == convertRes) + { + retval = NULL; + } + } + + return retval; +} + #if defined(WINCE) /* diff --git a/pr/src/md/windows/w95io.c b/pr/src/md/windows/w95io.c index 2527ca97..772c44b8 100644 --- a/pr/src/md/windows/w95io.c +++ b/pr/src/md/windows/w95io.c @@ -462,7 +462,19 @@ _MD_CloseFile(PRInt32 osfd) /* --- DIR IO ------------------------------------------------------------ */ +#if !defined(WINCE) #define GetFileFromDIR(d) (d)->d_entry.cFileName +#else +char* GetFileFromDIR(_MDDir* d) +{ + char* retval = NULL; + + WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, d->d_entry.cFileName, -1, d->cFileNameA, sizeof(d->cFileNameA), NULL, NULL); + retval = d->cFileNameA; + + return retval; +} +#endif #define FileIsHidden(d) ((d)->d_entry.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) void FlipSlashes(char *cp, int len) @@ -532,17 +544,16 @@ _PR_MD_OPEN_DIR(_MDDir *d, const char *name) d->d_hdl = FindFirstFile( filename, &(d->d_entry) ); #else { - LPWSTR ceFilename = _PR_MD_MALLOC_A2W(filename); + WCHAR ceFileName[MAX_PATH]; + LPWSTR ceResult = _PR_MD_A2W(filename, ceFileName, MAX_PATH); - if(NULL != ceFilename) + if(NULL != ceResult) { - d->d_hdl = FindFirstFile( ceFilename, &(d->d_entry) ); - PR_Free(ceFilename); + d->d_hdl = FindFirstFile( ceFileName, &(d->d_entry) ); } else { - PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); - return PR_FAILURE; + d->d_hdl = INVALID_HANDLE_VALUE; } } #endif @@ -568,7 +579,11 @@ _PR_MD_READ_DIR(_MDDir *d, PRIntn flags) d->firstEntry = PR_FALSE; rv = 1; } else { +#if !defined(WINCE) + rv = FindNextFile(d->d_hdl, &(d->d_entry)); +#else rv = FindNextFile(d->d_hdl, &(d->d_entry)); +#endif } if (rv == 0) { break; @@ -810,11 +825,13 @@ IsRootDirectory(char *fn, size_t buflen) return PR_TRUE; } +#if !defined(WINCE) if (isalpha(fn[0]) && fn[1] == ':' && _PR_IS_SLASH(fn[2]) && fn[3] == '\0') { rv = GetDriveType(fn) > 1 ? PR_TRUE : PR_FALSE; return rv; } +#endif /* The UNC root directory */ @@ -846,6 +863,7 @@ IsRootDirectory(char *fn, size_t buflen) if (_PR_IS_SLASH(*p) && p[1] != '\0') { return PR_FALSE; } +#if !defined(WINCE) if (*p == '\0') { /* * GetDriveType() doesn't work correctly if the @@ -865,6 +883,12 @@ IsRootDirectory(char *fn, size_t buflen) if (slashAdded) { *--p = '\0'; } +#else + /* + * Assume the path as root. + */ + rv = PR_TRUE; +#endif } return rv; } @@ -885,15 +909,39 @@ _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info) * FindFirstFile() expands wildcard characters. So * we make sure the pathname contains no wildcard. */ - if (NULL != _mbspbrk(fn, "?*")) { + if (NULL != +#if !defined(WINCE) + _mbspbrk(fn, "?*") +#else + strpbrk(fn, "?*") +#endif + ) { PR_SetError(PR_FILE_NOT_FOUND_ERROR, 0); return -1; } +#if !defined(WINCE) hFindFile = FindFirstFile(fn, &findFileData); +#else + { + WCHAR ceFileName[MAX_PATH + 1]; + LPWSTR ceResult = _PR_MD_A2W(fn, ceFileName, sizeof(ceFileName) / sizeof(WCHAR)); + + if(NULL != ceResult) + { + hFindFile = FindFirstFile(ceFileName, &findFileData); + } + else + { + hFindFile = INVALID_HANDLE_VALUE; + } + } +#endif if (INVALID_HANDLE_VALUE == hFindFile) { DWORD len; +#if !defined(WINCE) char *filePart; +#endif /* * FindFirstFile() does not work correctly on root directories. @@ -907,12 +955,23 @@ _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info) * If the pathname does not contain ., \, and /, it cannot be * a root directory or a pathname that ends in a slash. */ - if (NULL == _mbspbrk(fn, ".\\/")) { + if (NULL == +#if !defined(WINCE) + _mbspbrk(fn, ".\\/") +#else + strpbrk(fn, ".\\/") +#endif + ) { _PR_MD_MAP_OPENDIR_ERROR(GetLastError()); return -1; } +#if !defined(WINCE) len = GetFullPathName(fn, sizeof(pathbuf), pathbuf, &filePart); +#else + strncpy(pathbuf, fn, sizeof(pathbuf)); + len = strlen(pathbuf); +#endif if (0 == len) { _PR_MD_MAP_OPENDIR_ERROR(GetLastError()); return -1; @@ -936,7 +995,23 @@ _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info) return -1; } else { pathbuf[len - 1] = '\0'; +#if !defined(WINCE) hFindFile = FindFirstFile(pathbuf, &findFileData); +#else + { + WCHAR ceFileName[MAX_PATH + 1]; + LPWSTR ceResult = _PR_MD_A2W(pathbuf, ceFileName, sizeof(ceFileName) / sizeof(WCHAR)); + + if(NULL != ceResult) + { + hFindFile = FindFirstFile(ceFileName, &findFileData); + } + else + { + hFindFile = INVALID_HANDLE_VALUE; + } + } +#endif if (INVALID_HANDLE_VALUE == hFindFile) { _PR_MD_MAP_OPENDIR_ERROR(GetLastError()); return -1; |