aboutsummaryrefslogtreecommitdiff
path: root/ext/consio/console_io.c
diff options
context:
space:
mode:
authordrh <>2024-09-03 14:15:57 +0000
committerdrh <>2024-09-03 14:15:57 +0000
commit940cdc94f30c181c68df84261ca9ba407b28176e (patch)
tree6035326bba6abdb331b857c1ec4149246bce472d /ext/consio/console_io.c
parent23a16c8387870a86aef8dea7f8dbad506dd29d94 (diff)
parent22cd1eec5ae516facb39a9ac3efbf6a28f170237 (diff)
downloadsqlite-940cdc94f30c181c68df84261ca9ba407b28176e.tar.gz
sqlite-940cdc94f30c181c68df84261ca9ba407b28176e.zip
Fix ext/consio so that it works correctly with SQLITE_USE_ONLY_WIN32.
FossilOrigin-Name: efc6f3d7e92a25f440fb8d392daf325af5ca7dca104a5bb4bd59f7df93af53b0
Diffstat (limited to 'ext/consio/console_io.c')
-rwxr-xr-xext/consio/console_io.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/ext/consio/console_io.c b/ext/consio/console_io.c
index 6b837cbaf..75324a34f 100755
--- a/ext/consio/console_io.c
+++ b/ext/consio/console_io.c
@@ -655,6 +655,10 @@ cfWrite(const void *buf, size_t osz, size_t ocnt, FILE *pf){
return rv;
}
+/* An fgets() equivalent, using Win32 file API for actual input.
+** Input ends when given buffer is filled or a newline is read.
+** If the FILE object is in text mode, swallows 0x0D. (ASCII CR)
+*/
SQLITE_INTERNAL_LINKAGE char *
cfGets(char *cBuf, int n, FILE *pf){
int nci = 0;
@@ -665,7 +669,10 @@ cfGets(char *cBuf, int n, FILE *pf){
while( nci < n-1 ){
DWORD nr;
if( !ReadFile(fai.fh, cBuf+nci, 1, &nr, 0) || nr==0 ) break;
- if( nr>0 && (!eatCR || cBuf[nci]!='\r') ) nci += nr;
+ if( nr>0 && (!eatCR || cBuf[nci]!='\r') ){
+ nci += nr;
+ if( cBuf[nci-nr]=='\n' ) break;
+ }
}
if( nci < n ) cBuf[nci] = 0;
return (nci>0)? cBuf : 0;