* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#define _GNU_SOURCE
#define _XOPEN_SOURCE
#define _XOPEN_SOURCE_EXTENDED
#define _POSIX_C_SOURCE 200100
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
+#include <ctype.h>
#include <errno.h>
#include <time.h>
return strdup(str);
}
+void strset(char **old, const char *str)
+{
+ if (*old)
+ free(*old);
+ if (str)
+ *old = strdup(str);
+ else
+ *old = NULL;
+}
+
int match(const char *a, const char *b)
{
if (a == b)
return !strcmp(a, b);
}
+int prefix(const char *str, const char *prefix, const char **suffix)
+{
+ while (*str && *prefix) {
+ if (*str != *prefix)
+ return 0;
+ str++;
+ prefix++;
+ }
+ if (*prefix)
+ return 0;
+ if (*str && *str != ' ')
+ return 0;
+ while (*str && *str == ' ')
+ str++;
+ if (suffix)
+ *suffix = *str ? str : NULL;
+ return 1;
+}
+
+char *despace(char *str)
+{
+ int chr, spaces = 1;
+ char *src = str;
+ char *dst = str;
+ while ((chr = *src++)) {
+ if (isspace(chr))
+ spaces++;
+ else
+ spaces=0;
+ if (spaces == 0)
+ *dst++ = chr;
+ if (spaces == 1)
+ *dst++ = ' ';
+ }
+ if (dst > str && spaces)
+ dst--;
+ *dst = '\0';
+ return str;
+}
+
/* Memory functions */
void *alloc0(int size)
{
buf->max = 0;
}
+const char *reset(buf_t *buf)
+{
+ if (!buf->len)
+ return NULL;
+ buf->len = 0;
+ return buf->data;
+}
+
/* Data functions */
int base64(const void *_in, int ilen, void *_out, int olen)
{
int poll_add(poll_t *poll, int fd, cb_t cb, void *data)
{
struct epoll_event ctl = {
- .events = EPOLLIN | EPOLLOUT | EPOLLERR,
+ .events = EPOLLET | EPOLLIN | EPOLLOUT | EPOLLERR,
.data.ptr = poll,
};
poll->fd = fd;
int poll_ctl(poll_t *poll, int in, int out, int err)
{
struct epoll_event ctl = {
- .events = (in ? EPOLLIN : 0)
+ .events = EPOLLET
+ | (in ? EPOLLIN : 0)
| (out ? EPOLLOUT : 0)
| (err ? EPOLLERR : 0),
.data.ptr = poll,
if (count < 0)
continue;
if (count == 0)
- continue;
+ return running;
if (!(poll = event.data.ptr))
continue;
if (!(poll->cb))