/* * Copyright (C) 2012-2013 Andy Spencer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /* Macros */ #define ABS(a) ((a) > 0 ? (a) : -(a)) #define MIN(a,b) ((a) < (b) ? (a) : (b)) #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define CLAMP(x,l,h) MIN(MAX(x,l),h) #define ROUND(x) ((int)((x)+0.5)) #define N_ELEMENTS(x) (sizeof(x)/sizeof((x)[0])) #define new0(type) alloc0(sizeof(type)) /* Types */ typedef void (*cb_t)(void *data); typedef struct { char *data; int len; int max; } buf_t; typedef struct { int fd; cb_t cb; void *data; } poll_t; /* Debug functions */ void util_init(void); /* Stirng functions */ void strsub(char *str, char find, char repl); char *strcopy(const char *str); void strset(char **old, const char *str); int match(const char *a, const char *b); int prefix(const char *str, const char *prefix, const char **suffix); char *despace(char *text); void escape(char *dst, const char *src, int len); /* Memory functions */ void *alloc0(int size); void append(buf_t *buf, const char *data, int len); void release(buf_t *buf); const char *reset(buf_t *buf); /* Data functions */ int base64(const void *in, int ilen, void *out, int olen); /* File functions */ char *read_file(const char *path, int *len); /* Polling functions */ int poll_add(poll_t *poll, int fd, cb_t cb, void *data); int poll_ctl(poll_t *poll, int in, int out, int err); int poll_del(poll_t *poll); int poll_run(int timeout); void poll_quit(void); /* Debug functions */ void debug(char *fmt, ...); void error(char *fmt, ...);