MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / local_getline

Function local_getline

modules/dasSQLITE/sqlite/shell.c:792–835  ·  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. ** ** If zLine is not NULL then it is a malloced buffer returned from ** a previous call to this routine that may be reused. */

Source from the content-addressed store, hash-verified

790** a previous call to this routine that may be reused.
791*/
792static char *local_getline(char *zLine, FILE *in){
793 int nLine = zLine==0 ? 0 : 100;
794 int n = 0;
795
796 while( 1 ){
797 if( n+100>nLine ){
798 nLine = nLine*2 + 100;
799 zLine = realloc(zLine, nLine);
800 shell_check_oom(zLine);
801 }
802 if( fgets(&zLine[n], nLine - n, in)==0 ){
803 if( n==0 ){
804 free(zLine);
805 return 0;
806 }
807 zLine[n] = 0;
808 break;
809 }
810 while( zLine[n] ) n++;
811 if( n>0 && zLine[n-1]=='\n' ){
812 n--;
813 if( n>0 && zLine[n-1]=='\r' ) n--;
814 zLine[n] = 0;
815 break;
816 }
817 }
818#if defined(_WIN32) || defined(WIN32)
819 /* For interactive input on Windows systems, translate the
820 ** multi-byte characterset characters into UTF-8. */
821 if( stdin_is_interactive && in==stdin ){
822 char *zTrans = sqlite3_win32_mbcs_to_utf8_v2(zLine, 0);
823 if( zTrans ){
824 i64 nTrans = strlen(zTrans)+1;
825 if( nTrans>nLine ){
826 zLine = realloc(zLine, nTrans);
827 shell_check_oom(zLine);
828 }
829 memcpy(zLine, zTrans, nTrans);
830 sqlite3_free(zTrans);
831 }
832 }
833#endif /* defined(_WIN32) || defined(WIN32) */
834 return zLine;
835}
836
837/*
838** Retrieve a single line of input text.

Callers 1

one_input_lineFunction · 0.85

Calls 2

shell_check_oomFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected