Defines | |
#define | MAX_EXTENSION_LENGTH (5) |
#define | MAX_FILESEND_CHUNK_SIZE (32 * 1024) |
Functions | |
bool | qFileLock (int fd) |
Lock file. | |
bool | qFileUnlock (int fd) |
Unlock file which is locked by qFileLock(). | |
bool | qFileExist (const char *filepath) |
Check file existence. | |
char * | qFileGetName (const char *filepath) |
Get filename from filepath. | |
char * | qFileGetDir (const char *filepath) |
Get directory suffix from filepath. | |
char * | qFileGetExt (const char *filepath) |
Get extension from filepath. | |
off_t | qFileGetSize (const char *filepath) |
Get file size. | |
ssize_t | qFileSend (int outfd, int infd, size_t nbytes) |
Transfer data between file descriptors. | |
void * | qFileLoad (const char *filepath, size_t *nbytes) |
Load file into memory. | |
void * | qFileRead (FILE *fp, size_t *nbytes) |
Load file stream which has unknown size into memory. | |
char * | qFileReadLine (FILE *fp) |
Read string. | |
ssize_t | qFileSave (const char *filepath, const void *buf, size_t size, bool append) |
Save to file. |
bool qFileLock | ( | int | fd | ) |
Lock file.
fd | file descriptor |
// for file descriptor int fd = open(...); if(qFileLock(fd) == true) { (...atomic file access...) qFileUnlock(fd); } // for FILE stream object FILE *fp = fopen(...); int fd = fileno(fp); if(qFileLock(fd) == true) { (...atomic file access...) qFileUnlock(fd); }
bool qFileUnlock | ( | int | fd | ) |
Unlock file which is locked by qFileLock().
fd | file descriptor |
bool qFileExist | ( | const char * | filepath | ) |
Check file existence.
filepath | file or directory path |
char* qFileGetName | ( | const char * | filepath | ) |
Get filename from filepath.
filepath | file or directory path |
char* qFileGetDir | ( | const char * | filepath | ) |
Get directory suffix from filepath.
filepath | file or directory path |
char* qFileGetExt | ( | const char * | filepath | ) |
Get extension from filepath.
filepath | file or directory path |
off_t qFileGetSize | ( | const char * | filepath | ) |
Get file size.
filepath | file or directory path |
ssize_t qFileSend | ( | int | outfd, | |
int | infd, | |||
size_t | nbytes | |||
) |
Transfer data between file descriptors.
outfd | output file descriptor | |
infd | input file descriptor | |
size | the number of bytes to copy between file descriptors. 0 means transfer until end of infd. |
void* qFileLoad | ( | const char * | filepath, | |
size_t * | nbytes | |||
) |
Load file into memory.
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. |
// 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);
void* qFileRead | ( | FILE * | fp, | |
size_t * | nbytes | |||
) |
Load file stream which has unknown size into memory.
fp | FILE pointer | |
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 end of stream. |
char* qFileReadLine | ( | FILE * | fp | ) |
Read string.
Same as fgets but can be used for unlimited string line.
fp | FILE pointer |
ssize_t qFileSave | ( | const char * | filepath, | |
const void * | buf, | |||
size_t | size, | |||
bool | append | |||
) |
Save to file.
filepath | file path | |
buf | data | |
size | the number of bytes to save | |
append | false for new(if exists truncate), true for appending |
[Home] [About] [Examples] [Changes] [Download] [SVN Repository] [Install] [Reference] |