** 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
| 14344 | ** is undefined in this case. |
| 14345 | */ |
| 14346 | static char *readFile(const char *zName, int *pnByte){ |
| 14347 | FILE *in = fopen(zName, "rb"); |
| 14348 | long nIn; |
| 14349 | size_t nRead; |
| 14350 | char *pBuf; |
| 14351 | if( in==0 ) return 0; |
| 14352 | fseek(in, 0, SEEK_END); |
| 14353 | nIn = ftell(in); |
| 14354 | rewind(in); |
| 14355 | pBuf = sqlite3_malloc64( nIn+1 ); |
| 14356 | if( pBuf==0 ){ fclose(in); return 0; } |
| 14357 | nRead = fread(pBuf, nIn, 1, in); |
| 14358 | fclose(in); |
| 14359 | if( nRead!=1 ){ |
| 14360 | sqlite3_free(pBuf); |
| 14361 | return 0; |
| 14362 | } |
| 14363 | pBuf[nIn] = 0; |
| 14364 | if( pnByte ) *pnByte = nIn; |
| 14365 | return pBuf; |
| 14366 | } |
| 14367 | |
| 14368 | #if defined(SQLITE_ENABLE_SESSION) |
| 14369 | /* |
no outgoing calls
no test coverage detected