MCPcopy Create free account
hub / github.com/Kitware/VTK / readFile

Function readFile

ThirdParty/sqlite/vtksqlite/shell.c:25227–25258  ·  view source on GitHub ↗

** Read the content of file zName into memory obtained from sqlite3_malloc64() ** and return a pointer to the buffer. The caller is responsible for freeing ** the memory. ** ** If parameter pnByte is not NULL, (*pnByte) is set to the number of bytes ** read. ** ** For convenience, a nul-terminator byte is always appended to the data read ** from the file before the buffer is returned. This byte is

Source from the content-addressed store, hash-verified

25225** is undefined in this case.
25226*/
25227static char *readFile(const char *zName, int *pnByte){
25228 FILE *in = sqlite3_fopen(zName, "rb");
25229 long nIn;
25230 size_t nRead;
25231 char *pBuf;
25232 int rc;
25233 if( in==0 ) return 0;
25234 rc = fseek(in, 0, SEEK_END);
25235 if( rc!=0 ){
25236 sqlite3_fprintf(stderr,"Error: '%s' not seekable\n", zName);
25237 fclose(in);
25238 return 0;
25239 }
25240 nIn = ftell(in);
25241 rewind(in);
25242 pBuf = sqlite3_malloc64( nIn+1 );
25243 if( pBuf==0 ){
25244 sqlite3_fputs("Error: out of memory\n", stderr);
25245 fclose(in);
25246 return 0;
25247 }
25248 nRead = fread(pBuf, nIn, 1, in);
25249 fclose(in);
25250 if( nRead!=1 ){
25251 sqlite3_free(pBuf);
25252 sqlite3_fprintf(stderr,"Error: cannot read '%s'\n", zName);
25253 return 0;
25254 }
25255 pBuf[nIn] = 0;
25256 if( pnByte ) *pnByte = nIn;
25257 return pBuf;
25258}
25259
25260#if defined(SQLITE_ENABLE_SESSION)
25261/*

Callers 4

ifFunction · 0.70
do_meta_commandFunction · 0.70
testStatesFunction · 0.50
testBlobsFunction · 0.50

Calls 3

sqlite3_fopenFunction · 0.85
sqlite3_fprintfFunction · 0.85
sqlite3_fputsFunction · 0.85

Tested by

no test coverage detected