| | @@ -166,13 +166,13 @@ |
| 166 | 166 | */ |
| 167 | 167 | void file_copy(const char *zFrom, const char *zTo){ |
| 168 | 168 | FILE *in, *out; |
| 169 | 169 | int got; |
| 170 | 170 | char zBuf[8192]; |
| 171 | | - in = fopen(zFrom, "rb"); |
| 171 | + in = fossil_fopen(zFrom, "rb"); |
| 172 | 172 | if( in==0 ) fossil_fatal("cannot open \"%s\" for reading", zFrom); |
| 173 | | - out = fopen(zTo, "wb"); |
| 173 | + out = fossil_fopen(zTo, "wb"); |
| 174 | 174 | if( out==0 ) fossil_fatal("cannot open \"%s\" for writing", zTo); |
| 175 | 175 | while( (got=fread(zBuf, 1, sizeof(zBuf), in))>0 ){ |
| 176 | 176 | fwrite(zBuf, 1, got, out); |
| 177 | 177 | } |
| 178 | 178 | fclose(in); |
| | @@ -666,5 +666,58 @@ |
| 666 | 666 | blob_read_from_file(&onDisk, zName); |
| 667 | 667 | rc = blob_compare(&onDisk, pContent); |
| 668 | 668 | blob_reset(&onDisk); |
| 669 | 669 | return rc==0; |
| 670 | 670 | } |
| 671 | + |
| 672 | + |
| 673 | +/************************************************************************** |
| 674 | +** The following routines translate between MBCS and UTF8 on windows. |
| 675 | +** Since everything is always UTF8 on unix, these routines are no-ops |
| 676 | +** there. |
| 677 | +*/ |
| 678 | + |
| 679 | +/* |
| 680 | +** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free() |
| 681 | +** to deallocate any memory used to store the returned pointer when done. |
| 682 | +*/ |
| 683 | +char *fossil_mbcs_to_utf8(const char *zMbcs){ |
| 684 | +#ifdef _WIN32 |
| 685 | + return sqlite3_win32_mbcs_to_utf8(zMbcs); |
| 686 | +#else |
| 687 | + return (char*)zMbcs; /* No-op on unix */ |
| 688 | +#endif |
| 689 | +} |
| 690 | + |
| 691 | +/* |
| 692 | +** Translate UTF8 to MBCS. Return a pointer. Call fossil_mbcs_free() |
| 693 | +** to deallocate any memory used to store the returned pointer when done. |
| 694 | +*/ |
| 695 | +char *fossil_utf8_to_mbcs(const char *zUtf8){ |
| 696 | +#ifdef _WIN32 |
| 697 | + return sqlite3_win32_utf8_to_mbcs(zUtf8); |
| 698 | +#else |
| 699 | + return (char*)zUtf8; /* No-op on unix */ |
| 700 | +#endif |
| 701 | +} |
| 702 | + |
| 703 | +/* |
| 704 | +** Translate MBCS to UTF8. Return a pointer. Call fossil_mbcs_free() |
| 705 | +** to deallocate any memory used to store the returned pointer when done. |
| 706 | +*/ |
| 707 | +void fossil_mbcs_free(char *zOld){ |
| 708 | +#ifdef _WIN32 |
| 709 | + free(zOld); |
| 710 | +#else |
| 711 | + /* No-op on unix */ |
| 712 | +#endif |
| 713 | +} |
| 714 | + |
| 715 | +/* |
| 716 | +** Like fopen() but always takes a UTF8 argument. |
| 717 | +*/ |
| 718 | +FILE *fossil_fopen(const char *zName, const char *zMode){ |
| 719 | + char *zMbcs = fossil_utf8_to_mbcs(zName); |
| 720 | + FILE *f = fopen(zMbcs, zMode); |
| 721 | + fossil_mbcs_free(zMbcs); |
| 722 | + return f; |
| 723 | +} |
| 671 | 724 | |