summaryrefslogtreecommitdiffstats
path: root/src/cc4group.h
diff options
context:
space:
mode:
authorMarkus Mittendrein <git@maxmitti.tk>2019-03-16 03:50:28 +0100
committerMarkus Mittendrein <git@maxmitti.tk>2019-03-16 03:50:28 +0100
commit9103fb5b961817d1a91248632b4cedfec770b198 (patch)
tree875e16693f78efd016e0cdb09c5c14486e5b365d /src/cc4group.h
parent7c2cda2544f22add8114828535a397a2d733361d (diff)
downloadcc4group-9103fb5b961817d1a91248632b4cedfec770b198.tar.gz
cc4group-9103fb5b961817d1a91248632b4cedfec770b198.zip
Add openFd, openFilePointer and openWithReadCallback methods
Diffstat (limited to 'src/cc4group.h')
-rw-r--r--src/cc4group.h21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/cc4group.h b/src/cc4group.h
index 16c684a..a63d995 100644
--- a/src/cc4group.h
+++ b/src/cc4group.h
@@ -10,6 +10,7 @@ extern "C" {
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
+#include <stdio.h>
typedef struct {
const char* fileName;
@@ -31,6 +32,11 @@ typedef struct {
} CC4Group_CleanupJob;
typedef void* (*CC4Group_TmpMemoryStrategy)(CC4Group* const this, const size_t size, CC4Group_CleanupJob* cleanupJob);
+// the callback has to store a pointer to the newly read data in data, as well as the amount of read data in size
+// the callback must return true if the end of data is reached or any read error happens and false otherwise
+// the pointer passed in will be handled as specified with the corresponding MemoryManagement
+typedef bool (*CC4Group_ReadCallback)(const uint8_t** const data, size_t* const size, void* const arg);
+
typedef struct {
CC4Group* (*new)(void);
bool (*create)(CC4Group* const this);
@@ -42,7 +48,20 @@ typedef struct {
// opens a group that is stored entirely in memory
// only open an in-memory group on a frehsly created group object
- bool (*openMemory)(CC4Group* const this, const uint8_t* const groupData, size_t const size);
+ // see the description of MemoryManagement to know if and when data has to be freed by the caller
+ // if the lazy mode is not used, the data can be freed immediately after this function returns
+ bool (*openMemory)(CC4Group* const this, const uint8_t* const groupData, size_t const size, int const memoryManagement);
+
+ // opens a group through a file descriptor
+ // the file descriptor must have been opened with read access
+ bool (*openFd)(CC4Group* const this, int fd);
+
+ // opens a group through a FILE*
+ // the file must have been opened with read access
+ bool (*openFilePointer)(CC4Group* const this, FILE* fd);
+
+ // opens a group and calls the callback to get the group data
+ bool (*openWithReadCallback)(CC4Group* const this, CC4Group_ReadCallback const callback, void* const callbackArg, int const memoryManagement);
bool (*save)(CC4Group* const this, const char* const path);
bool (*saveOverwrite)(CC4Group* const this, const char* const path);