This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar/deps/base64/buffer.c
2024-11-25 19:22:19 +08:00

34 lines
622 B
C

#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;
}