Tou
Tou header library
Loading...
Searching...
No Matches
File operations

Topics

 Lower file operations
 
 
 System/IO control
 
 

Functions

size_t tou_read_fp_in_blocks (FILE *fp, size_t blocksize, tou_func3 cb, void *userdata)
 Reads file in blocks, calling user-provided function for each block.
 
char * tou_read_file (const char *filename, size_t *read_len)
 Reads file from filename.
 
char * tou_read_fp (FILE *fp, size_t *read_len)
 Reads from fp.
 

Detailed Description

Function Documentation

◆ tou_read_file()

char * tou_read_file ( const char * filename,
size_t * read_len )

Reads file from filename.

Automatically allocates memory and optionally returns amount read (may be set to null).

Parameters
[in]filenameEither file name or ""/"stdin" to read from stdin
[out]read_lenOptional pointer to where to store file size
Returns
Pointer to loaded file or NULL if error

◆ tou_read_fp()

char * tou_read_fp ( FILE * fp,
size_t * read_len )

Reads from fp.

Automatically allocates memory and optionally returns amount read (may be set to null).

Parameters
[in]fpFILE* to read from
[out]read_lenOptional pointer to where to store file size
Returns
Pointer to loaded data or NULL on error

◆ tou_read_fp_in_blocks()

size_t tou_read_fp_in_blocks ( FILE * fp,
size_t blocksize,
tou_func3 cb,
void * userdata )

Reads file in blocks, calling user-provided function for each block.

Automatically allocates memory and returns amount read. Function receives 3 parameters:

  • data [in] Pointer to new data
  • len [in] Amount of bytes actually read
  • userdata [in,out] User data provided

Look into this function's source and/or tou_block_store_cb and tou_block_store_struct for more info about using it.

Parameters
[in]fpFILE* from which data is to be read
[in]blocksizeSize in bytes; set to 0 to use default (TOU_DEFAULT_BLOCKSIZE)
[in]cbFunction to call for each block
[in]userdataCustom data to be passed to function
Returns
Total bytes read