Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Handle translation between '/' and '\\' on Windows and Cygwin |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | ticket-d17d6e5b17 |
| Files: | files | file ages | folders |
| SHA1: |
ba87fb1fecfa54a28922ead0c8e10a8c |
| User & Date: | jan.nijtmans 2013-01-24 12:00:24.324 |
Context
|
2013-01-27
| ||
| 20:29 | merge trunk, combine with "allow-backslash-on-unix" branch check-in: 38159dae32 user: jan.nijtmans tags: ticket-d17d6e5b17 | |
|
2013-01-24
| ||
| 12:00 | Handle translation between '/' and '\\' on Windows and Cygwin check-in: ba87fb1fec user: jan.nijtmans tags: ticket-d17d6e5b17 | |
| 10:53 | merge trunk check-in: ba3e82f189 user: jan.nijtmans tags: ticket-d17d6e5b17 | |
Changes
Changes to src/file.c.
| ︙ | ︙ | |||
545 546 547 548 549 550 551 |
return 0;
}
if( (z[++i]&0xc0)!=0x80 ){
/* Invalid second continuation byte */
return 0;
}
}
| < < | 545 546 547 548 549 550 551 552 553 554 555 556 557 558 |
return 0;
}
if( (z[++i]&0xc0)!=0x80 ){
/* Invalid second continuation byte */
return 0;
}
}
}
if( c=='/' ){
if( z[i+1]=='/' ) return 0;
if( z[i+1]=='.' ){
if( z[i+2]=='/' || z[i+2]==0 ) return 0;
if( z[i+2]=='.' && (z[i+3]=='/' || z[i+3]==0) ) return 0;
}
|
| ︙ | ︙ | |||
790 791 792 793 794 795 796 |
fossil_print(" file_isdir = %d\n", file_wd_isdir(zName));
}
}
/*
** Return TRUE if the given filename is canonical.
**
| | | > > | 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 |
fossil_print(" file_isdir = %d\n", file_wd_isdir(zName));
}
}
/*
** Return TRUE if the given filename is canonical.
**
** Canonical names are full pathnames which contain no "/./" or "/../"
** terms and (On Windows/Cygwin) using "/" not "\".
*/
int file_is_canonical(const char *z){
int i;
if( z[0]!='/'
#if defined(_WIN32)
&& (z[0]==0 || z[1]!=':' || z[2]!='/')
#endif
) return 0;
for(i=0; z[i]; i++){
#if defined(_WIN32) || defined(__CYGWIN__)
if( z[i]=='\\' ) return 0;
#endif
if( z[i]=='/' ){
if( z[i+1]=='.' ){
if( z[i+2]=='/' || z[i+2]==0 ) return 0;
if( z[i+2]=='.' && (z[i+3]=='/' || z[i+3]==0) ) return 0;
}
}
}
|
| ︙ | ︙ |
Changes to src/utf8.c.
| ︙ | ︙ | |||
131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
nByte = WideCharToMultiByte(CP_UTF8, 0, zFilename, -1, 0, 0, 0, 0);
zUtf = sqlite3_malloc( nByte );
if( zUtf==0 ){
return 0;
}
WideCharToMultiByte(CP_UTF8, 0, zFilename, -1, zUtf, nByte, 0, 0);
return zUtf;
#elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
char *zIn = (char*)zFilename;
char *zOut;
iconv_t cd;
size_t n, x;
for(n=0; zIn[n]>0 && zIn[n]<=0x7f; n++){}
if( zIn[n]!=0 && (cd = iconv_open("UTF-8", "UTF-8-MAC"))!=(iconv_t)-1 ){
| > > > > | 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
nByte = WideCharToMultiByte(CP_UTF8, 0, zFilename, -1, 0, 0, 0, 0);
zUtf = sqlite3_malloc( nByte );
if( zUtf==0 ){
return 0;
}
WideCharToMultiByte(CP_UTF8, 0, zFilename, -1, zUtf, nByte, 0, 0);
return zUtf;
#elif defined(__CYGWIN__)
char *zOut;
zOut = fossil_strdup(zFilename);
return zOut;
#elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
char *zIn = (char*)zFilename;
char *zOut;
iconv_t cd;
size_t n, x;
for(n=0; zIn[n]>0 && zIn[n]<=0x7f; n++){}
if( zIn[n]!=0 && (cd = iconv_open("UTF-8", "UTF-8-MAC"))!=(iconv_t)-1 ){
|
| ︙ | ︙ | |||
167 168 169 170 171 172 173 | /* ** Translate UTF8 to unicode for use in filename translations. ** Return a pointer to the translated text.. Call fossil_filename_free() ** to deallocate any memory used to store the returned pointer when done. ** ** On Windows, characters in the range U+0001 to U+0031 and the | | > > > > > > > > > > > > | | | 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
/*
** Translate UTF8 to unicode for use in filename translations.
** Return a pointer to the translated text.. Call fossil_filename_free()
** to deallocate any memory used to store the returned pointer when done.
**
** On Windows, characters in the range U+0001 to U+0031 and the
** characters '"', '*', ':', '<', '>', '?' and '|' are invalid
** to be used. Therefore, translated those to characters in the
** (private use area), in the range U+F001 - U+F07F, so those
** characters never arrive in any Windows API. The filenames might
** look strange in Windows explorer, but in the cygwin shell
** everything looks as expected.
**
** See: <http://cygwin.com/cygwin-ug-net/using-specialnames.html>
**
*/
void *fossil_utf8_to_filename(const char *zUtf8){
#ifdef _WIN32
WCHAR *zUnicode = fossil_utf8_to_unicode(zUtf8);
WCHAR *wUnicode = zUnicode;
/* If path starts with "<drive>:/" or "<drive>:\", don't translate the ':' */
if( fossil_isalpha(zUtf8[0]) && zUtf8[1]==':'
&& (zUtf8[2]=='\\' || zUtf8[2]=='/')) {
zUnicode[2] = '\\';
wUnicode += 3;
}
while( *wUnicode != '\0' ){
if ( (*wUnicode < 32) || wcschr(L"\"*<>?|:", *wUnicode) ){
*wUnicode |= 0xF000;
}else if( *wUnicode == '/' ){
*wUnicode = '\\';
}
++wUnicode;
}
return zUnicode;
#elif defined(__CYGWIN__)
char *zPath = fossil_strdup(zUtf8);
char *p = zPath;
while( (*p = *zUtf8++) != 0){
if (*p++ == '\\' ) {
p[-1] = '/';
}
}
return zPath;
#elif defined(__APPLE__) && !defined(WITHOUT_ICONV)
return fossil_strdup(zUtf8);
#else
return (void *)zUtf8; /* No-op on unix */
#endif
}
/*
** Deallocate any memory that was previously allocated by
** fossil_filename_to_utf8() or fossil_utf8_to_filename().
*/
void fossil_filename_free(void *pOld){
#if defined(_WIN32)
sqlite3_free(pOld);
#elif (defined(__APPLE__) && !defined(WITHOUT_ICONV)) || defined(__CYGWIN__)
fossil_free(pOld);
#else
/* No-op on all other unix */
#endif
}
/*
|
| ︙ | ︙ |