bp/utils.h

42 lines
1.2 KiB
C
Raw Normal View History

//
// utils.h - Some utility and printing functions.
//
2020-09-11 01:28:06 -07:00
#ifndef UTILS__H
#define UTILS__H
#include <stdbool.h>
2020-09-11 01:28:06 -07:00
#include <stdio.h>
#include <stdlib.h>
2020-09-11 01:28:06 -07:00
#include <string.h>
#include <unistd.h>
2021-01-15 19:30:21 -08:00
#include "match.h"
2020-09-07 23:22:43 -07:00
#define streq(a, b) (strcmp(a, b) == 0)
#define check(cond, ...) do { if (!(cond)) { (void)fprintf(stderr, __VA_ARGS__); (void)fwrite("\n", 1, 1, stderr); exit(EXIT_FAILURE); } } while(0)
2021-01-18 09:35:15 -08:00
#define new(t) memcheck(calloc(1, sizeof(t)))
#define xcalloc(a,b) memcheck(calloc(a,b))
#define xrealloc(a,b) memcheck(realloc(a,b))
2020-09-08 19:45:00 -07:00
__attribute__((nonnull))
2021-01-17 23:06:37 -08:00
char unescapechar(const char *escaped, const char **end);
2020-12-30 21:20:54 -08:00
__attribute__((pure, nonnull))
2020-09-11 01:28:06 -07:00
const char *after_name(const char *str);
__attribute__((pure, nonnull, returns_nonnull))
2020-09-11 01:28:06 -07:00
const char *after_spaces(const char *str);
__attribute__((nonnull))
bool matchchar(const char **str, char c);
__attribute__((nonnull))
bool matchstr(const char **str, const char *target);
__attribute__((nonnull))
2020-09-11 01:28:06 -07:00
size_t unescape_string(char *dest, const char *src, size_t bufsize);
__attribute__((returns_nonnull))
void *memcheck(/*@null@*/ /*@out@*/ void *p);
__attribute__((nonnull))
int memicmp(const void *s1, const void *s2, size_t n);
__attribute__((nonnull))
void xfree(void *p);
2020-09-10 03:41:03 -07:00
2020-09-11 01:28:06 -07:00
#endif
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1