BSB Developer Docs
Loading...
Searching...
No Matches
temp_file.h File Reference

Library for easy creation and management of temporary files. More...

#include <storage/storage.h>

Go to the source code of this file.

Typedefs

typedef struct TempFile TempFile
 Opaque TempFile structure declaration.
 

Functions

TempFile * temp_file_alloc (Storage *storage)
 Create a TempFile instance.
 
void temp_file_free (TempFile *instance)
 Delete a TempFile instance.
 
bool temp_file_create (TempFile *instance, const char *path)
 Create an underlying file and open it for writing.
 
bool temp_file_write (TempFile *instance, const void *data, size_t data_len)
 Write data to the underlying file.
 
bool temp_file_remove (TempFile *instance)
 Remove the underlying file.
 

Detailed Description

Library for easy creation and management of temporary files.

Function Documentation

◆ temp_file_alloc()

TempFile * temp_file_alloc ( Storage * storage)

Create a TempFile instance.

This function does not create any files, only allocates a container that can later be used to create a file via temp_file_create().

Parameters
[in]storagepointer to the Storage instance.
Returns
pointer to the created instance

◆ temp_file_create()

bool temp_file_create ( TempFile * instance,
const char * path )

Create an underlying file and open it for writing.

This function will create necessary paths if they do not exist.

Warning
This function will silently overwrite conflicting files.
Parameters
[in,out]instancepointer to the instance to be used
[in]pathfull path to the file to be created
Returns
true if the file could be created, false otherwise

◆ temp_file_free()

void temp_file_free ( TempFile * instance)

Delete a TempFile instance.

This function does not remove any files it might have created.

Parameters
[in,out]instancepointer to the instance to be deleted

◆ temp_file_remove()

bool temp_file_remove ( TempFile * instance)

Remove the underlying file.

Parameters
[in,out]instancepointer to the instance to be removed.
Returns
true if the file could be removed, false otherwise

◆ temp_file_write()

bool temp_file_write ( TempFile * instance,
const void * data,
size_t data_len )

Write data to the underlying file.

Parameters
[in,out]instancepointer to the instance to be written to
[in]datapointer to arbitrary data to be written to the file
[in]data_lenlength of the data to be written
Returns
true if the data was written successfully, false otherwise