summaryrefslogtreecommitdiff
path: root/deps/base64/buffer.c
diff options
context:
space:
mode:
authoryangwei <[email protected]>2024-11-25 19:22:19 +0800
committeryangwei <[email protected]>2024-11-25 19:22:19 +0800
commit1199e9d83f1b2c2d47d8fb7de911674319379651 (patch)
treec6c5f49405af8a0c33ab239fac3d488d61feb1fa /deps/base64/buffer.c
parentcce1155ae366077cca72047887f476bae7b0856a (diff)
✨ feat(integrate utable): deps/utable
Diffstat (limited to 'deps/base64/buffer.c')
-rw-r--r--deps/base64/buffer.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/deps/base64/buffer.c b/deps/base64/buffer.c
new file mode 100644
index 0000000..aad598c
--- /dev/null
+++ b/deps/base64/buffer.c
@@ -0,0 +1,33 @@
+#include <stdlib.h>
+#include <ctype.h>
+#include "b64.h"
+
+#ifdef b64_USE_CUSTOM_MALLOC
+extern void* b64_malloc(size_t);
+#endif
+
+#ifdef b64_USE_CUSTOM_REALLOC
+extern void* b64_realloc(void*, size_t);
+#endif
+
+int b64_buf_malloc(b64_buffer_t * buf)
+{
+ buf->ptr = b64_malloc(B64_BUFFER_SIZE);
+ if(!buf->ptr) return -1;
+
+ buf->bufc = 1;
+
+ return 0;
+}
+
+int b64_buf_realloc(b64_buffer_t* buf, size_t size)
+{
+ if ((int)size > buf->bufc * B64_BUFFER_SIZE)
+ {
+ while ((int)size > buf->bufc * B64_BUFFER_SIZE) buf->bufc++;
+ buf->ptr = b64_realloc(buf->ptr, B64_BUFFER_SIZE * buf->bufc);
+ if (!buf->ptr) return -1;
+ }
+
+ return 0;
+}