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

Function readFile

modules/dasSQLITE/sqlite/shell.c:20041–20061  ·  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

20039** is undefined in this case.
20040*/
20041static char *readFile(const char *zName, int *pnByte){
20042 FILE *in = fopen(zName, "rb");
20043 long nIn;
20044 size_t nRead;
20045 char *pBuf;
20046 if( in==0 ) return 0;
20047 fseek(in, 0, SEEK_END);
20048 nIn = ftell(in);
20049 rewind(in);
20050 pBuf = sqlite3_malloc64( nIn+1 );
20051 if( pBuf==0 ){ fclose(in); return 0; }
20052 nRead = fread(pBuf, nIn, 1, in);
20053 fclose(in);
20054 if( nRead!=1 ){
20055 sqlite3_free(pBuf);
20056 return 0;
20057 }
20058 pBuf[nIn] = 0;
20059 if( pnByte ) *pnByte = nIn;
20060 return pBuf;
20061}
20062
20063#if defined(SQLITE_ENABLE_SESSION)
20064/*

Callers 2

ifFunction · 0.85
do_meta_commandFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected