|
libarmutils
1.4
|
.h File Buffer Header. More...
Data Structures | |
| struct | FileBuffer |
| FileBuffer Structure. More... | |
Functions | |
| void | file_buffer_destroy (FileBuffer *fbuf) |
| Free memory used by a FileBuffer structure. | |
| FileBuffer * | file_buffer_init (void) |
| Allocate memory for a FileBuffer structure. | |
| int | file_buffer_read (FileBuffer *fbuf, const char *full_path, char **data) |
| Read a file into a FileBuffer. | |
| int | file_buffer_split_lines (FileBuffer *fbuf, int *nlines, char ***lines) |
| Create array of line pointers into a FileBuffer. | |
.h File Buffer Header.
| void file_buffer_destroy | ( | FileBuffer * | fbuf | ) |
Free memory used by a FileBuffer structure.
| fbuf | pointer to the FileBuffer structure |
Definition at line 38 of file file_buffer.c.
| FileBuffer* file_buffer_init | ( | void | ) |
Allocate memory for a FileBuffer structure.
Error messages from this function are sent to the message handler (see msngr_init_log() and msngr_init_mail()).
| fbuf | pointer to the FileBuffer structure |
| NULL | if a memory allocation error occurred |
Definition at line 58 of file file_buffer.c.
| int file_buffer_read | ( | FileBuffer * | fbuf, |
| const char * | full_path, | ||
| char ** | data | ||
| ) |
Read a file into a FileBuffer.
The in memory copy of the file can be accessed via the 'data' member of the FileBuffer structure. This memory is managed by the FileBuffer structure and should not be freed by the calling process. It will be freed when file_buffer_destroy() is called.
Using the same FileBuffer to read additional files will reused the previously allocated memory, reallocating more as necessary.
Example:
Error messages from this function are sent to the message handler (see msngr_init_log() and msngr_init_mail()).
| fbuf | pointer to the FileBuffer structure |
| full_path | full path to the input file |
| data | output: fbuf->data if not NULL |
| 1 | if successful (or zero length file) |
| 0 | if an errror occurred |
Definition at line 148 of file file_buffer.c.
| int file_buffer_split_lines | ( | FileBuffer * | fbuf, |
| int * | nlines, | ||
| char *** | lines | ||
| ) |
Create array of line pointers into a FileBuffer.
This function will replace newline characters '
' with string terminator characters '\0' and create an array of pointers to each line in the buffer. The output fbuf->lines array will be null terminated.
The memory used by the returned array of line pointers is managed by the FileBuffer structure and should not be freed by the calling process.
The number of lines and line pointers can also be accessed using the 'nlines' and 'lines' members of the FileBuffer structure.
Example:
Error messages from this function are sent to the message handler (see msngr_init_log() and msngr_init_mail()).
| fbuf | pointer to the FileBuffer structure |
| nlines | output: fbuf->nlines if not NULL |
| lines | output: fbuf->lines if not NULL |
| 1 | if successful |
| 0 | if a memory allocation error occurred |
Definition at line 281 of file file_buffer.c.