libqaeda

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | README | LICENSE

commit 645f54a19044620cd75a93cd454cd62ec24ae49e
parent 11273ca302d41b1d27857fc3f9b3a8a0cef25bc3
Author: lash <dev@holbrook.no>
Date:   Tue, 25 Mar 2025 01:21:49 +0000

Abstract io std calls

Diffstat:
Msrc/io/std.c | 15+++++++++++++++
Msrc/lq/io.h | 3+++
Msrc/store/file.c | 15++++++++-------
3 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/src/io/std.c b/src/io/std.c @@ -1,5 +1,20 @@ +#include <stdio.h> #include <stdlib.h> +#include <fcntl.h> +#include <unistd.h> char *mktempdir(char *s) { return mkdtemp(s); } + +int lq_open(const char *pathname, int flags, int mode) { + return open(pathname, flags, (mode_t)mode); +} + +int lq_read(int f, void *buf, size_t c) { + return read(f, buf, c); +} + +void lq_close(int fd) { + close(fd); +} diff --git a/src/lq/io.h b/src/lq/io.h @@ -12,5 +12,8 @@ * @return Pointer to valid path string. NULL if directory could not be created. */ char* mktempdir(char *s); +int lq_open(const char *pathname, int flags, int mode); +int lq_read(int f, char *buf, int c); +void lq_close(int fd); #endif // LIBQAEDA_IO_H_ diff --git a/src/store/file.c b/src/store/file.c @@ -5,6 +5,7 @@ #include <fcntl.h> #include "lq/crypto.h" +#include "lq/io.h" #include "lq/store.h" #include "lq/err.h" #include "lq/mem.h" @@ -35,7 +36,7 @@ int lq_file_content_get(enum payload_e typ, LQStore *store, const char *key, siz if (r < 0) { return ERR_READ; } - f = open(path, O_RDONLY, S_IRUSR); + f = lq_open(path, O_RDONLY, S_IRUSR); if (f < 0) { return ERR_READ; } @@ -43,18 +44,18 @@ int lq_file_content_get(enum payload_e typ, LQStore *store, const char *key, siz p = value; l = 0; while (1) { - c = read(f, p, *value_len - l); + c = lq_read(f, p, *value_len - l); if (c == 0) { break; } l += c; if (l > *value_len) { - close(f); + lq_close(f); return ERR_OVERFLOW; } p += c; } - close(f); + lq_close(f); *value_len = l; @@ -82,7 +83,7 @@ int lq_file_content_put(enum payload_e typ, LQStore *store, const char *key, siz if (r < 0) { return ERR_WRITE; } - f = open(path, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR); + f = lq_open(path, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR); if (f < 0) { return ERR_WRITE; } @@ -91,7 +92,7 @@ int lq_file_content_put(enum payload_e typ, LQStore *store, const char *key, siz while (l > 0) { c = write(f, p, l); if (c < 0) { - close(f); + lq_close(f); return ERR_WRITE; } if (c == 0) { @@ -100,7 +101,7 @@ int lq_file_content_put(enum payload_e typ, LQStore *store, const char *key, siz l -= c; p += c; } - close(f); + lq_close(f); return ERR_OK; }