|
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.
char *text = (char *)qFileLoad("/tmp/text.txt", NULL);
int binlen = 0;
char *bin = (char *)qFileLoad("/tmp/binary.bin", &binlen);
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.
|