diff options
author | drh <> | 2025-05-13 16:58:36 +0000 |
---|---|---|
committer | drh <> | 2025-05-13 16:58:36 +0000 |
commit | 494830ca8ecdd771f73d4751aa959ed81746c345 (patch) | |
tree | be143959319dcc8f35c397e8d3a14a434755f0f0 /ext/misc/fileio.c | |
parent | 0df6c5b9a70c6c1b87430c7f69f6849c145803b9 (diff) | |
download | sqlite-494830ca8ecdd771f73d4751aa959ed81746c345.tar.gz sqlite-494830ca8ecdd771f73d4751aa959ed81746c345.zip |
First cut at enhancing the fsdir virtual table so that it works with
unicode characters on Windows.
FossilOrigin-Name: c9e04dadfdf6c860631ce5603693add565ff2033aa25af5736302af7045fc91e
Diffstat (limited to 'ext/misc/fileio.c')
-rw-r--r-- | ext/misc/fileio.c | 57 |
1 files changed, 45 insertions, 12 deletions
diff --git a/ext/misc/fileio.c b/ext/misc/fileio.c index 80ac3b3e7..96a7f82bd 100644 --- a/ext/misc/fileio.c +++ b/ext/misc/fileio.c @@ -98,14 +98,9 @@ SQLITE_EXTENSION_INIT1 # include <direct.h> # include "test_windirent.h" # define dirent DIRENT -# ifndef chmod -# define chmod _chmod -# endif -# ifndef stat -# define stat _stat -# endif -# define mkdir(path,mode) _mkdir(path) -# define lstat(path,buf) stat(path,buf) +# define stat _stat +# define chmod(path,mode) fileio_chmod(path,mode) +# define mkdir(path,mode) fileio_mkdir(path) #endif #include <time.h> #include <errno.h> @@ -130,6 +125,40 @@ SQLITE_EXTENSION_INIT1 #define FSDIR_COLUMN_PATH 4 /* Path to top of search */ #define FSDIR_COLUMN_DIR 5 /* Path is relative to this directory */ +/* +** UTF8 chmod() function for Windows +*/ +#if defined(_WIN32) || defined(WIN32) +static int fileio_chmod(const char *zPath, int pmode){ + sqlite3_int64 sz = strlen(zPath); + wchar_t *b1 = sqlite3_malloc64( (sz+1)*sizeof(b1[0]) ); + int rc; + if( b1==0 ) return -1; + sz = MultiByteToWideChar(CP_UTF8, 0, zPath, sz, b1, sz); + b1[sz] = 0; + rc = _wchmod(b1, pmode); + sqlite3_free(b1); + return rc; +} +#endif + +/* +** UTF8 mkdir() function for Windows +*/ +#if defined(_WIN32) || defined(WIN32) +static int fileio_mkdir(const char *zPath){ + sqlite3_int64 sz = strlen(zPath); + wchar_t *b1 = sqlite3_malloc64( (sz+1)*sizeof(b1[0]) ); + int rc; + if( b1==0 ) return -1; + sz = MultiByteToWideChar(CP_UTF8, 0, zPath, sz, b1, sz); + b1[sz] = 0; + rc = _wmkdir(b1); + sqlite3_free(b1); + return rc; +} +#endif + /* ** Set the result stored by context ctx to a blob containing the @@ -291,7 +320,13 @@ static int fileStat( struct stat *pStatBuf ){ #if defined(_WIN32) - int rc = stat(zPath, pStatBuf); + sqlite3_int64 sz = strlen(zPath); + wchar_t *b1 = sqlite3_malloc64( (sz+1)*sizeof(b1[0]) ); + int rc; + if( b1==0 ) return 1; + sz = MultiByteToWideChar(CP_UTF8, 0, zPath, sz, b1, sz); + b1[sz] = 0; + rc = _wstat(b1, pStatBuf); if( rc==0 ) statTimesToUtc(zPath, pStatBuf); return rc; #else @@ -309,9 +344,7 @@ static int fileLinkStat( struct stat *pStatBuf ){ #if defined(_WIN32) - int rc = lstat(zPath, pStatBuf); - if( rc==0 ) statTimesToUtc(zPath, pStatBuf); - return rc; + return fileStat(zPath, pStatBuf); #else return lstat(zPath, pStatBuf); #endif |