Macros | Functions
file.h File Reference

Helper functions about file handling. More...

Macros

#define VTM_FILE_ATTR_REG   1
 
#define VTM_FILE_ATTR_DIR   2
 

Functions

VTM_API uint64_t vtm_file_get_fsize (FILE *fp)
 
VTM_API int vtm_file_getline (FILE *fp, char **buf, size_t *buf_len)
 
VTM_API const char * vtm_file_get_ext (const char *filename)
 
VTM_API int vtm_file_get_fattr (FILE *fp, int *attr)
 

Macro Definition Documentation

#define VTM_FILE_ATTR_REG   1

regular file

#define VTM_FILE_ATTR_DIR   2

directory

Function Documentation

VTM_API uint64_t vtm_file_get_fsize ( FILE *  fp)

Determines the file size.

Returns
the file size in bytes
VTM_API int vtm_file_getline ( FILE *  fp,
char **  buf,
size_t *  buf_len 
)

Reads one line delimited by \n from file.

The same buffer can be used in subsequent reads. The buffer is resized if more space is needed.

Parameters
fpthe file where to read from
[in,out]theallocated buffer with line content
[in,out]sizeof the buffer
Returns
VTM_OK if read of line was successful
VTM_E_IO_EOF when end of file is reached
VTM_API const char* vtm_file_get_ext ( const char *  filename)

Determines the extension of the given filename.

Returns
pointer to extension in in input string
NULL if file has no extension
VTM_API int vtm_file_get_fattr ( FILE *  fp,
int *  attr 
)

Reads the attributes of given file.

Parameters
fpthe file where to read from
[out]attrattributes are stored here
Returns
VTM_OK if attributes were read successfuully
VTM_E_IO_UNKNOWN if an error occured