Index: src/blob.c ================================================================== --- src/blob.c +++ src/blob.c @@ -792,11 +792,11 @@ } nName = file_simplify_name(zName, nName, 0); for(i=1; i #ifdef _WIN32 # include #endif +#ifdef __CYGWIN__ +# include +# define CP_UTF8 65001 + __declspec(dllimport) extern __stdcall int WideCharToMultiByte(int, int, + const char *, int, const char *, int, const char *, const char *); + __declspec(dllimport) extern __stdcall int MultiByteToWideChar(int, int, + const char *, int, wchar_t*, int); +#endif #ifdef _WIN32 /* ** Translate MBCS to UTF-8. Return a pointer to the translated text. ** Call fossil_mbcs_free() to deallocate any memory used to store the @@ -42,19 +50,20 @@ ** any memory used to hold the translation */ void fossil_mbcs_free(char *zOld){ sqlite3_free(zOld); } +#endif /* _WIN32 */ /* ** Translate Unicode text into UTF-8. ** Return a pointer to the translated text. ** Call fossil_unicode_free() to deallocate any memory used to store the ** returned pointer when done. */ char *fossil_unicode_to_utf8(const void *zUnicode){ -#ifdef _WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0); char *zUtf = sqlite3_malloc( nByte ); if( zUtf==0 ){ return 0; } @@ -69,11 +78,11 @@ ** Translate UTF-8 to unicode for use in system calls. Return a pointer to the ** translated text.. Call fossil_unicode_free() to deallocate any memory ** used to store the returned pointer when done. */ void *fossil_utf8_to_unicode(const char *zUtf8){ -#ifdef _WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0); wchar_t *zUnicode = sqlite3_malloc( nByte * 2 ); if( zUnicode==0 ){ return 0; } @@ -87,17 +96,16 @@ /* ** Deallocate any memory that was previously allocated by ** fossil_unicode_to_utf8(). */ void fossil_unicode_free(void *pOld){ -#ifdef _WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) sqlite3_free(pOld); #else fossil_free(pOld); #endif } -#endif /* _WIN32 */ #if defined(__APPLE__) && !defined(WITHOUT_ICONV) # include #endif @@ -160,17 +168,17 @@ ** Call fossil_filename_free() to deallocate any memory used to store the ** returned pointer when done. */ void *fossil_utf8_to_filename(const char *zUtf8){ #ifdef _WIN32 - int nByte = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0); - wchar_t *zUnicode = sqlite3_malloc( nByte * 2 ); + int nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, 0, 0); + wchar_t *zUnicode = sqlite3_malloc( nChar * 2 ); wchar_t *wUnicode = zUnicode; if( zUnicode==0 ){ return 0; } - MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nByte); + MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, nChar); while( *wUnicode != '\0' ){ if( *wUnicode == '/' ){ *wUnicode = '\\'; } ++wUnicode; @@ -178,22 +186,31 @@ return zUnicode; #elif defined(__CYGWIN__) char *zPath, *p; if( fossil_isalpha(zUtf8[0]) && (zUtf8[1]==':') && (zUtf8[2]=='\\' || zUtf8[2]=='/')) { - int n = strlen(zUtf8); - zPath = fossil_malloc( n+10 ); - memcpy(zPath, "/cygdrive/", 10); - zPath[10] = zUtf8[0]; - memcpy(zPath+11, zUtf8+2, n-1); + /* win32 absolute path starting with drive specifier. */ + int nByte; + wchar_t zUnicode[2000]; + wchar_t *wUnicode = zUnicode; + MultiByteToWideChar(CP_UTF8, 0, zUtf8, -1, zUnicode, count(zUnicode)); + while( *wUnicode != '\0' ){ + if( *wUnicode == '/' ){ + *wUnicode = '\\'; + } + ++wUnicode; + } + nByte = cygwin_conv_path(CCP_WIN_W_TO_POSIX, zUnicode, NULL, 0); + zPath = fossil_malloc(nByte); + cygwin_conv_path(CCP_WIN_W_TO_POSIX, zUnicode, zPath, nByte); } else { zPath = fossil_strdup(zUtf8); - } - zUtf8 = p = zPath; - while( (*p = *zUtf8++) != 0){ - if (*p++ == '\\' ) { - p[-1] = '/'; + zUtf8 = p = zPath; + while( (*p = *zUtf8++) != 0){ + if (*p++ == '\\' ) { + p[-1] = '/'; + } } } return zPath; #elif defined(__APPLE__) && !defined(WITHOUT_ICONV) return fossil_strdup(zUtf8);