part: implement mlx3ds_assets_open/read/close()

This commit is contained in:
Zy 2024-10-12 15:49:43 +02:00
parent 3f5e13b2f2
commit 8649e86eaa
4 changed files with 133 additions and 7 deletions

View file

@ -15,6 +15,9 @@
# include <string.h>
/// @brief Socket to an asset. Equivalent to a file descriptor.
typedef void *t_assetsocket;
/// @brief Represents a file embedded with the program.
typedef struct s_embeddedasset
{
@ -32,6 +35,26 @@ typedef struct s_embeddedasset
/// @return A reference to the asset. NULL if the asset doesn't exist.
const t_embeddedasset *mlx3ds_assets_get(const char *name);
// TODO add mlx3ds_assets_open()
/// @brief Create a t_assetsocket from an asset.
///
/// @param name Name of the asset to open.
/// @return A socket to the asset. NULL if error.
t_assetsocket mlx3ds_assets_open(const char *name);
/// @brief Reads up to 'count' bytes of the asset content and write it in 'buf'.
///
/// @param asset The asset to read.
/// @param buf The buffer to write the content to.
/// Its size must be at least 'count' bytes.
/// @param count The number of bytes to read.
/// @return The number of bytes actually read. Can be lower than 'count'.
/// 0 if EOF reached.
size_t mlx3ds_assets_read(
t_assetsocket asset, void *buf, size_t count);
/// @brief Close the asset socket to avoid leaks.
///
/// @param asset Asset to close.
void mlx3ds_assets_close(t_assetsocket asset);
#endif