aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlarrybr <larrybr@noemail.net>2023-11-12 00:43:36 +0000
committerlarrybr <larrybr@noemail.net>2023-11-12 00:43:36 +0000
commitcc2b3c20510843742acd74c00fb4de1b6836e1f2 (patch)
treec7d8093b133b6e2bd84ad00202c9e7cae0162ad6 /src
parentea80462c10860b64e57153cdd4a2e61e4d337c63 (diff)
downloadsqlite-cc2b3c20510843742acd74c00fb4de1b6836e1f2.tar.gz
sqlite-cc2b3c20510843742acd74c00fb4de1b6836e1f2.zip
Write BOM without fwrite(), using sputz() so that if it goes to the console, it is translated "properly".
FossilOrigin-Name: 06ef96a8233c6b6ca2653a0b780b3a401cab2b77594125f4f1c54b269c22a9f9
Diffstat (limited to 'src')
-rw-r--r--src/shell.c.in13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/shell.c.in b/src/shell.c.in
index e9c226ac7..af8e8db4a 100644
--- a/src/shell.c.in
+++ b/src/shell.c.in
@@ -9399,9 +9399,9 @@ static int do_meta_command(char *zLine, ShellState *p){
int i;
int eMode = 0;
int bOnce = 0; /* 0: .output, 1: .once, 2: .excel */
- unsigned char zBOM[4]; /* Byte-order mark to using if --bom is present */
+ static const char *zBomUtf8 = "\xef\xbb\xbf";
+ const char *zBom = 0;
- zBOM[0] = 0;
failIfSafeMode(p, "cannot run .%s in safe mode", azArg[0]);
if( c=='e' ){
eMode = 'x';
@@ -9414,10 +9414,7 @@ static int do_meta_command(char *zLine, ShellState *p){
if( z[0]=='-' ){
if( z[1]=='-' ) z++;
if( cli_strcmp(z,"-bom")==0 ){
- zBOM[0] = 0xef;
- zBOM[1] = 0xbb;
- zBOM[2] = 0xbf;
- zBOM[3] = 0;
+ zBom = zBomUtf8;
}else if( c!='e' && cli_strcmp(z,"-x")==0 ){
eMode = 'x'; /* spreadsheet */
}else if( c!='e' && cli_strcmp(z,"-e")==0 ){
@@ -9484,7 +9481,7 @@ static int do_meta_command(char *zLine, ShellState *p){
p->out = stdout;
rc = 1;
}else{
- if( zBOM[0] ) fwrite(zBOM, 1, 3, p->out);
+ if( zBom ) sputz(p->out, zBom);
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
}
#endif
@@ -9497,7 +9494,7 @@ static int do_meta_command(char *zLine, ShellState *p){
p->out = stdout;
rc = 1;
} else {
- if( zBOM[0] ) fwrite(zBOM, 1, 3, p->out);
+ if( zBom ) sputz(p->out, zBom);
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
}
}