2 * Copyright (C) 2012-2013 Andy Spencer <andy753421@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #define ABS(a) ((a) > 0 ? (a) : -(a))
20 #define MIN(a,b) ((a) < (b) ? (a) : (b))
21 #define MAX(a,b) ((a) > (b) ? (a) : (b))
22 #define CLAMP(x,l,h) MIN(MAX(x,l),h)
23 #define ROUND(x) ((int)((x)+0.5))
24 #define N_ELEMENTS(x) (sizeof(x)/sizeof((x)[0]))
26 #define new0(type) alloc0(sizeof(type))
29 typedef void (*cb_t)(void *data);
52 /* Stirng functions */
53 void strsub(char *str, char find, char repl);
54 char *strcopy(const char *str);
55 void strset(char **old, const char *str);
56 int compare(const char *a, const char *b);
57 int match(const char *a, const char *b);
58 int starts(const char *prefix, const char *str);
59 int prefix(const char *str, const char *prefix, const char **suffix);
60 int suffix(const char *str, const char *prefix, const char **suffix);
61 char *despace(char *text);
62 void escape(char *dst, const char *src, int len);
64 /* Memory functions */
65 void *alloc0(int size);
66 void append(buf_t *buf, const char *data, int len);
67 void release(buf_t *buf);
68 const char *reset(buf_t *buf);
71 int base64(const void *in, int ilen, void *out, int olen);
74 char *read_file(const char *path, int *len);
76 /* Polling functions */
77 void poll_add(poll_t *poll, int fd, cb_t cb, void *data);
78 void poll_ctl(poll_t *poll, int in, int out, int err);
79 void poll_del(poll_t *poll);
80 int poll_run(int timeout);
84 void idle_add(idle_t *idle);
85 void idle_set(idle_t *idle, int first, int next);
88 void debug(char *fmt, ...);
89 void error(char *fmt, ...);