| | @@ -42,11 +42,11 @@ |
| 42 | 42 | |
| 43 | 43 | /* |
| 44 | 44 | ** After translating from UTF8 to MBCS, invoke this routine to deallocate |
| 45 | 45 | ** any memory used to hold the translation |
| 46 | 46 | */ |
| 47 | | -void fossil_mbcs_free(void *zOld){ |
| 47 | +void fossil_mbcs_free(char *zOld){ |
| 48 | 48 | #ifdef _WIN32 |
| 49 | 49 | sqlite3_free(zOld); |
| 50 | 50 | #else |
| 51 | 51 | /* No-op on unix */ |
| 52 | 52 | #endif |
| | @@ -56,11 +56,11 @@ |
| 56 | 56 | ** Translate Unicode text into UTF8. |
| 57 | 57 | ** Return a pointer to the translated text. |
| 58 | 58 | ** Call fossil_unicode_free() to deallocate any memory used to store the |
| 59 | 59 | ** returned pointer when done. |
| 60 | 60 | */ |
| 61 | | -char *fossil_unicode_to_utf8(const void *zUnicode){ |
| 61 | +char *fossil_unicode_to_utf8(const char *zUnicode){ |
| 62 | 62 | #ifdef _WIN32 |
| 63 | 63 | int nByte = WideCharToMultiByte(CP_UTF8, 0, zUnicode, -1, 0, 0, 0, 0); |
| 64 | 64 | char *zUtf = sqlite3_malloc( nByte ); |
| 65 | 65 | if( zUtf==0 ){ |
| 66 | 66 | return 0; |
| | @@ -111,11 +111,11 @@ |
| 111 | 111 | ** Translate text from the filename character set into |
| 112 | 112 | ** to precomposed UTF8. Return a pointer to the translated text. |
| 113 | 113 | ** Call fossil_filename_free() to deallocate any memory used to store the |
| 114 | 114 | ** returned pointer when done. |
| 115 | 115 | */ |
| 116 | | -char *fossil_filename_to_utf8(const void *zFilename){ |
| 116 | +char *fossil_filename_to_utf8(const char *zFilename){ |
| 117 | 117 | #if defined(_WIN32) |
| 118 | 118 | int nByte = WideCharToMultiByte(CP_UTF8, 0, zFilename, -1, 0, 0, 0, 0); |
| 119 | 119 | char *zUtf = sqlite3_malloc( nByte ); |
| 120 | 120 | if( zUtf==0 ){ |
| 121 | 121 | return 0; |
| | @@ -126,18 +126,22 @@ |
| 126 | 126 | char *zOut; |
| 127 | 127 | iconv_t cd; |
| 128 | 128 | size_t n, x; |
| 129 | 129 | for(n=0; zFilename[n]>0 && zFilename[n]<=0x7f; n++){} |
| 130 | 130 | if( zFilename[n]!=0 && (cd = iconv_open("UTF-8", "UTF-8-MAC"))!=(iconv_t)-1 ){ |
| 131 | | - n = strlen(zFilename); |
| 132 | | - zOut = fossil_malloc( n+100 ); |
| 133 | | - x = iconv(cd, zFilename, n, zOut, n+100); |
| 131 | + char *zIn = (char*)zFilename; |
| 132 | + char *zOutx; |
| 133 | + size_t nIn, nOutx; |
| 134 | + nIn = n = strlen(zFilename); |
| 135 | + nOutx = nIn+100; |
| 136 | + zOutx = zOut = fossil_malloc( nOutx+1 ); |
| 137 | + x = iconv(cd, &zIn, &nIn, &zOutx, &nOutx); |
| 134 | 138 | if( x==(size_t)-1 ){ |
| 135 | 139 | fossil_free(zOut); |
| 136 | 140 | zOut = fossil_strdup(zFilename); |
| 137 | 141 | }else{ |
| 138 | | - zOut[x] = 0; |
| 142 | + zOut[n+100-nOutx] = 0; |
| 139 | 143 | } |
| 140 | 144 | iconv_close(cd); |
| 141 | 145 | }else{ |
| 142 | 146 | zOut = fossil_strdup(zFilename); |
| 143 | 147 | } |
| 144 | 148 | |