initial: modular iptv-dl with runtime config from ~/.iptv-downloader/config.json
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
#include "buf.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void buf_init(Buf *b) {
|
||||
b->data = malloc(4096); b->len = 0; b->cap = 4096; b->data[0] = 0;
|
||||
}
|
||||
|
||||
void buf_free(Buf *b) {
|
||||
free(b->data); b->data = NULL; b->len = 0; b->cap = 0;
|
||||
}
|
||||
|
||||
void buf_append(Buf *b, const char *s, size_t n) {
|
||||
while (b->len + n + 1 > b->cap) { b->cap *= 2; b->data = realloc(b->data, b->cap); }
|
||||
memcpy(b->data + b->len, s, n);
|
||||
b->len += n;
|
||||
b->data[b->len] = 0;
|
||||
}
|
||||
|
||||
void buf_str(Buf *b, const char *s) { buf_append(b, s, strlen(s)); }
|
||||
|
||||
void buf_fmt(Buf *b, const char *fmt, ...) {
|
||||
char tmp[4096]; va_list ap; va_start(ap, fmt);
|
||||
vsnprintf(tmp, sizeof(tmp), fmt, ap); va_end(ap);
|
||||
buf_str(b, tmp);
|
||||
}
|
||||
Reference in New Issue
Block a user