aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/buf.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-11-15 13:50:15 +0100
committerEgor Tensin <Egor.Tensin@gmail.com>2023-11-15 14:03:11 +0100
commit992ac5301fc8727d83017b242af2df9895eebfcc (patch)
tree4fdd21a61b54d368540d6ef65258f97473051381 /src/buf.c
parentclient: print the server response (diff)
downloadcimple-992ac5301fc8727d83017b242af2df9895eebfcc.tar.gz
cimple-992ac5301fc8727d83017b242af2df9895eebfcc.zip
implement a command to list runs
Diffstat (limited to 'src/buf.c')
-rw-r--r--src/buf.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/buf.c b/src/buf.c
new file mode 100644
index 0000000..90e33ad
--- /dev/null
+++ b/src/buf.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2023 Egor Tensin <Egor.Tensin@gmail.com>
+ * This file is part of the "cimple" project.
+ * For details, see https://github.com/egor-tensin/cimple.
+ * Distributed under the MIT License.
+ */
+
+#include "buf.h"
+#include "log.h"
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+struct buf {
+ uint32_t size;
+ const void *data;
+};
+
+int buf_create(struct buf **_buf, const void *data, uint32_t size)
+{
+ struct buf *buf = malloc(sizeof(struct buf));
+ if (!buf) {
+ log_errno("malloc");
+ return -1;
+ }
+
+ buf->data = data;
+ buf->size = size;
+
+ *_buf = buf;
+ return 0;
+}
+
+int buf_create_from_string(struct buf **buf, const char *str)
+{
+ return buf_create(buf, str, strlen(str) + 1);
+}
+
+void buf_destroy(struct buf *buf)
+{
+ free(buf);
+}
+
+uint32_t buf_get_size(const struct buf *buf)
+{
+ return buf->size;
+}
+
+const void *buf_get_data(const struct buf *buf)
+{
+ return buf->data;
+}