]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Use _wfopen() instead of fopen() on Windows in the CLI.
authordrh <>
Tue, 24 Sep 2024 10:30:07 +0000 (10:30 +0000)
committerdrh <>
Tue, 24 Sep 2024 10:30:07 +0000 (10:30 +0000)
FossilOrigin-Name: 21a8cac5e9a0d5ead29ca1114be7520d182348f7e2e2e2416852b827d7e09f21

manifest
manifest.uuid
src/shell.c.in

index f90dfa8f2553eec77b240282100b2039161a754e..6c38834512f1d9da746ab4cce7a43d9aeb99c918 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Always\suse\sfputws()\sfor\soutput\sto\sa\sWindows\scommand-line\sprompt.
-D 2024-09-24T09:51:53.618
+C Use\s_wfopen()\sinstead\sof\sfopen()\son\sWindows\sin\sthe\sCLI.
+D 2024-09-24T10:30:07.376
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -768,7 +768,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
 F src/resolve.c b2cd748488012312824508639b6af908461e45403037d5c4e19d9b0e8195507f
 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe
-F src/shell.c.in 6054892954e926a30a5b3d2994805477d38154692b5bb571d81db86791d0e58b
+F src/shell.c.in 95f1bdfb9b1d513c7d82ab04fbca746a9668fb02d3eb984cd1cfb3b4ffc413e0
 F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54
@@ -2213,8 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 5c54530d5a0a4125a1ba44f22537c4f63d5e5708f347c43cbac3e1832c4335da
-R 39e94947c12065fc6ead20518785128b
+P 33950a8c3f3e48e5107fe56647da05147aa84f9c3eccbe7c8671f5b502ebb70b
+R 563de058a2a6970ab738b542c7a8c099
 U drh
-Z 9f7cd507ccaf6f6343bd8b5a2d5f1672
+Z 3b9fb03668dcca40431939db5346d2bc
 # Remove this line to create a well-formed Fossil manifest.
index d6a1143c6788d44453fcac76b0b8154613bc38ee..a3d44399a6b663af47570694b81e981b3b23ea10 100644 (file)
@@ -1 +1 @@
-33950a8c3f3e48e5107fe56647da05147aa84f9c3eccbe7c8671f5b502ebb70b
+21a8cac5e9a0d5ead29ca1114be7520d182348f7e2e2e2416852b827d7e09f21
index c400073872c865ff48167c6f7df0221fca847086..5677e060f78c217d712b70161e790e7e96b8e26c 100644 (file)
@@ -344,6 +344,33 @@ static void cli_fprintf(FILE *out, const char *zFormat, ...){
 # define cli_fprintf fprintf
 #endif
 
+#ifdef _WIN32
+/* fopen() for windows */
+static FILE *cli_fopen(const char *zFilename, const char *zMode){
+  FILE *fp = 0;
+  wchar_t *b1, *b2;
+  int sz1, sz2;
+
+  sz1 = (int)strlen(zFilename);
+  sz2 = (int)strlen(zMode);
+  b1 = malloc( (sz1+1)*sizeof(b1[0]) );
+  b2 = malloc( (sz2+1)*sizeof(b1[0]) );
+  if( b1 && b2 ){
+    sz1 = MultiByteToWideChar(CP_UTF8, 0, zFilename, sz1, b1, sz1);
+    b1[sz1] = 0;
+    sz2 = MultiByteToWideChar(CP_UTF8, 0, zMode, sz2, b2, sz2);
+    b2[sz2] = 0;
+    fp = _wfopen(b1, b2);
+  }
+  free(b1);
+  free(b2);
+  return fp;
+}
+#else
+/* library version works for everybody else */
+# define cli_fopen fopen
+#endif
+
 /* Use console I/O package as a direct INCLUDE. */
 #define SQLITE_INTERNAL_LINKAGE static
 
@@ -827,7 +854,7 @@ static FILE * openChrSource(const char *zFile){
   /* On Windows, open first, then check the stream nature. This order
   ** is necessary because _stat() and sibs, when checking a named pipe,
   ** effectively break the pipe as its supplier sees it. */
-  FILE *rv = fopen(zFile, "rb");
+  FILE *rv = cli_fopen(zFile, "rb");
   if( rv==0 ) return 0;
   if( _fstat64(_fileno(rv), &x) != 0
       || !STAT_CHR_SRC(x.st_mode)){
@@ -841,7 +868,7 @@ static FILE * openChrSource(const char *zFile){
 # define STAT_CHR_SRC(mode) (S_ISREG(mode)||S_ISFIFO(mode)||S_ISCHR(mode))
   if( rc!=0 ) return 0;
   if( STAT_CHR_SRC(x.st_mode) ){
-    return fopen(zFile, "rb");
+    return cli_fopen(zFile, "rb");
   }else{
     return 0;
   }
@@ -1681,7 +1708,7 @@ static void editFunc(
   bBin = sqlite3_value_type(argv[0])==SQLITE_BLOB;
   /* When writing the file to be edited, do \n to \r\n conversions on systems
   ** that want \r\n line endings */
-  f = fopen(zTempFile, bBin ? "wb" : "w");
+  f = cli_fopen(zTempFile, bBin ? "wb" : "w");
   if( f==0 ){
     sqlite3_result_error(context, "edit() cannot open temp file", -1);
     goto edit_func_end;
@@ -1712,7 +1739,7 @@ static void editFunc(
     sqlite3_result_error(context, "EDITOR returned non-zero", -1);
     goto edit_func_end;
   }
-  f = fopen(zTempFile, "rb");
+  f = cli_fopen(zTempFile, "rb");
   if( f==0 ){
     sqlite3_result_error(context,
       "edit() cannot reopen temp file after edit", -1);
@@ -3113,7 +3140,7 @@ static void displayLinuxIoStats(void){
   FILE *in;
   char z[200];
   sqlite3_snprintf(sizeof(z), z, "/proc/%d/io", getpid());
-  in = fopen(z, "rb");
+  in = cli_fopen(z, "rb");
   if( in==0 ) return;
   while( cli_fgets(z, sizeof(z), in)!=0 ){
     static const struct {
@@ -5170,7 +5197,7 @@ static int process_input(ShellState *p);
 ** is undefined in this case.
 */
 static char *readFile(const char *zName, int *pnByte){
-  FILE *in = fopen(zName, "rb");
+  FILE *in = cli_fopen(zName, "rb");
   long nIn;
   size_t nRead;
   char *pBuf;
@@ -5260,7 +5287,7 @@ static int session_filter(void *pCtx, const char *zTab){
 ** the type cannot be determined from content.
 */
 int deduceDatabaseType(const char *zName, int dfltZip){
-  FILE *f = fopen(zName, "rb");
+  FILE *f = cli_fopen(zName, "rb");
   size_t n;
   int rc = SHELL_OPEN_UNSPEC;
   char zBuf[100];
@@ -5313,7 +5340,7 @@ static unsigned char *readHexDb(ShellState *p, int *pnData){
   unsigned int x[16];
   char zLine[1000];
   if( zDbFilename ){
-    in = fopen(zDbFilename, "r");
+    in = cli_fopen(zDbFilename, "r");
     if( in==0 ){
       eputf("cannot open \"%s\" for reading\n", zDbFilename);
       return 0;
@@ -5800,7 +5827,7 @@ static FILE *output_file_open(const char *zFile, int bTextMode){
   }else if( cli_strcmp(zFile, "off")==0 ){
     f = 0;
   }else{
-    f = fopen(zFile, bTextMode ? "w" : "wb");
+    f = cli_fopen(zFile, bTextMode ? "w" : "wb");
     if( f==0 ){
       eputf("Error: cannot open \"%s\"\n", zFile);
     }
@@ -9029,7 +9056,7 @@ static int do_meta_command(char *zLine, ShellState *p){
       sCtx.xCloser = pclose;
 #endif
     }else{
-      sCtx.in = fopen(sCtx.zFile, "rb");
+      sCtx.in = cli_fopen(sCtx.zFile, "rb");
       sCtx.xCloser = fclose;
     }
     if( sCtx.in==0 ){
@@ -9358,7 +9385,7 @@ static int do_meta_command(char *zLine, ShellState *p){
       sqlite3IoTrace = iotracePrintf;
       iotrace = stdout;
     }else{
-      iotrace = fopen(azArg[1], "w");
+      iotrace = cli_fopen(azArg[1], "w");
       if( iotrace==0 ){
         eputf("Error: cannot open \"%s\"\n", azArg[1]);
         sqlite3IoTrace = 0;
@@ -10327,7 +10354,7 @@ static int do_meta_command(char *zLine, ShellState *p){
       failIfSafeMode(p, "cannot run \".session %s\" in safe mode", azCmd[0]);
       if( nCmd!=2 ) goto session_syntax_error;
       if( pSession->p==0 ) goto session_not_open;
-      out = fopen(azCmd[1], "wb");
+      out = cli_fopen(azCmd[1], "wb");
       if( out==0 ){
         eputf("ERROR: cannot open \"%s\" for writing\n",
               azCmd[1]);
@@ -12267,7 +12294,7 @@ static void process_sqliterc(
     shell_check_oom(zBuf);
     sqliterc = zBuf;
   }
-  p->in = fopen(sqliterc,"rb");
+  p->in = cli_fopen(sqliterc,"rb");
   if( p->in ){
     if( stdin_is_interactive ){
       eputf("-- Loading resources from %s\n", sqliterc);