void* qFileLoad ( const char *  filepath,
size_t *  nbytes 
)

Load file into memory.

Parameters:
filepath file path
nbytes has two purpost, one is to set how many bytes are readed. the other is actual the number loaded bytes will be stored. nbytes must be point 0 or NULL to read entire file.
Returns:
allocated memory pointer if successful, otherwise returns NULL.
   // loading text file
   char *text = (char *)qFileLoad("/tmp/text.txt", NULL);

   // loading binary file
   int binlen = 0;
   char *bin = (char *)qFileLoad("/tmp/binary.bin", &binlen);

   // loading partial
   int binlen = 10;
   char *bin = (char *)qFileLoad("/tmp/binary.bin", &binlen);

Note:
This method actually allocates memory more than 1 bytes than filesize then append NULL character at the end. For example, when the file size is 10 bytes long, 10+1 bytes will allocated and the last byte is always NULL character. So you can load text file and use without appending NULL character. By the way, *size still will be returned the actual file size of 10.

Definition at line 247 of file qFile.c.


Generated on Mon Mar 26 07:00:51 2018 for JSOC_Documentation by  doxygen 1.5.7.1