aboutsummaryrefslogtreecommitdiffstats
path: root/src/system.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-08-16 12:42:58 +0200
committerDavid Robillard <d@drobilla.net>2022-01-13 23:03:30 -0500
commit00af9fa4e0344b1ff642a7ccd63626f77521ea8a (patch)
treebce03b485b9e93c92ddd15b303465b6a93095a08 /src/system.h
parent6f362db2fbfe1b02929673aa9b0529b4328fb195 (diff)
downloadserd-00af9fa4e0344b1ff642a7ccd63626f77521ea8a.tar.gz
serd-00af9fa4e0344b1ff642a7ccd63626f77521ea8a.tar.bz2
serd-00af9fa4e0344b1ff642a7ccd63626f77521ea8a.zip
Simplify reader interface
Diffstat (limited to 'src/system.h')
-rw-r--r--src/system.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/system.h b/src/system.h
index fae1cb84..7dae6a96 100644
--- a/src/system.h
+++ b/src/system.h
@@ -19,6 +19,7 @@
#include "attributes.h"
+#include <stdint.h>
#include <stdio.h>
/// Open a file configured for fast sequential reading
@@ -42,4 +43,20 @@ serd_allocate_buffer(size_t size);
void
serd_free_aligned(void* ptr);
+/// Wrapper for getc that is compatible with SerdReadFunc
+static inline size_t
+serd_file_read_byte(void* buf, size_t size, size_t nmemb, void* stream)
+{
+ (void)size;
+ (void)nmemb;
+
+ const int c = getc((FILE*)stream);
+ if (c == EOF) {
+ *((uint8_t*)buf) = 0;
+ return 0;
+ }
+ *((uint8_t*)buf) = (uint8_t)c;
+ return 1;
+}
+
#endif // SERD_SYSTEM_H