MCPcopy Create free account
hub / github.com/audacity/audacity / local_getline

Function local_getline

lib-src/sqlite/shell.c:666–709  ·  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

664** a previous call to this routine that may be reused.
665*/
666static char *local_getline(char *zLine, FILE *in){
667 int nLine = zLine==0 ? 0 : 100;
668 int n = 0;
669
670 while( 1 ){
671 if( n+100>nLine ){
672 nLine = nLine*2 + 100;
673 zLine = realloc(zLine, nLine);
674 if( zLine==0 ) shell_out_of_memory();
675 }
676 if( fgets(&zLine[n], nLine - n, in)==0 ){
677 if( n==0 ){
678 free(zLine);
679 return 0;
680 }
681 zLine[n] = 0;
682 break;
683 }
684 while( zLine[n] ) n++;
685 if( n>0 && zLine[n-1]=='\n' ){
686 n--;
687 if( n>0 && zLine[n-1]=='\r' ) n--;
688 zLine[n] = 0;
689 break;
690 }
691 }
692#if defined(_WIN32) || defined(WIN32)
693 /* For interactive input on Windows systems, translate the
694 ** multi-byte characterset characters into UTF-8. */
695 if( stdin_is_interactive && in==stdin ){
696 char *zTrans = sqlite3_win32_mbcs_to_utf8_v2(zLine, 0);
697 if( zTrans ){
698 int nTrans = strlen30(zTrans)+1;
699 if( nTrans>nLine ){
700 zLine = realloc(zLine, nTrans);
701 if( zLine==0 ) shell_out_of_memory();
702 }
703 memcpy(zLine, zTrans, nTrans);
704 sqlite3_free(zTrans);
705 }
706 }
707#endif /* defined(_WIN32) || defined(WIN32) */
708 return zLine;
709}
710
711/*
712** Retrieve a single line of input text.

Callers 1

one_input_lineFunction · 0.85

Calls 3

shell_out_of_memoryFunction · 0.85
freeFunction · 0.85
strlen30Function · 0.85

Tested by

no test coverage detected