MCPcopy Create free account
hub / github.com/altairwei/WizNotePlus / local_getline

Function local_getline

src/database/cppsqlite3.cpp:1208–1248  ·  view source on GitHub ↗

** This routine reads a line of text from FILE in, stores ** the text in memory obtained from malloc() and returns a pointer ** to the text. NULL is returned at end of file, or if malloc() ** fails. ** ** The interface is like "readline" but no command-line editing ** is done. */

Source from the content-addressed store, hash-verified

1206** is done.
1207*/
1208static char *local_getline(char *zPrompt, FILE *in){
1209 char *zLine;
1210 int nLine;
1211 int n;
1212 int eol;
1213
1214 if( zPrompt && *zPrompt ){
1215 printf("%s",zPrompt);
1216 fflush(stdout);
1217 }
1218 nLine = 100;
1219 zLine = (char*)malloc( nLine );
1220 if( zLine==0 ) return 0;
1221 n = 0;
1222 eol = 0;
1223 while( !eol ){
1224 if( n+100>nLine ){
1225 nLine = nLine*2 + 100;
1226 zLine = (char*)realloc(zLine, nLine);
1227 if( zLine==0 ) return 0;
1228 }
1229 if( fgets(&zLine[n], nLine - n, in)==0 ){
1230 if( n==0 ){
1231 free(zLine);
1232 return 0;
1233 }
1234 zLine[n] = 0;
1235 eol = 1;
1236 break;
1237 }
1238 while( zLine[n] ){ n++; }
1239 if( n>0 && zLine[n-1]=='\n' ){
1240 n--;
1241 if( n>0 && zLine[n-1]=='\r' ) n--;
1242 zLine[n] = 0;
1243 eol = 1;
1244 }
1245 }
1246 zLine = (char*)realloc( zLine, n+1 );
1247 return zLine;
1248}
1249/*
1250** Retrieve a single line of input text.
1251**

Callers 1

one_input_lineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected