scorpiox-bot-plugin-fetch
←sxbuf.hc
37 lines · 1 KBHEADBlameDownload
1/*
2 * sxbuf.h - shared growable buffer + tiny string helpers used by every
3 * module of plugin_fetch. Implementation in sxbuf.c.
4 */
5#ifndef SX_FETCH_BUF_H
6#define SX_FETCH_BUF_H
7
8#include <stddef.h>
9#include <stdio.h>
10
11typedef struct {
12 char *p;
13 size_t n;
14 size_t cap;
15} buf_t;
16
17void buf_init(buf_t *b);
18void buf_free(buf_t *b);
19void buf_add(buf_t *b, const char *s);
20void buf_bput(buf_t *b, const char *s, size_t n);
21void buf_addf(buf_t *b, const char *fmt, ...);
22
23void *sx_malloc(size_t n);
24char *sx_strdup(const char *s);
25
26void url_decode(char *s);
27int get_query_val(const char *qs, const char *key, char *out, size_t outsz);
28void json_escape(FILE *out, const char *s);
29
30/* Case-insensitive compare with no platform dependency: MinGW spells these
31 * _stricmp, glibc/musl hide them behind <strings.h>, and we only ever need
32 * these two. ASCII only, locale-independent (which is what an HTTP header
33 * name and a content-type want anyway). Implementation in sxbuf.c. */
34int sx_strncasecmp(const char *a, const char *b, size_t n);
35int sx_strcasecmp(const char *a, const char *b);
36
37#endif /* SX_FETCH_BUF_H */