work on type inference some more
[ccc.git] / util.h
1 #ifndef UTIL_H
2 #define UTIL_H
3
4 #include <stdarg.h>
5 #include <stdbool.h>
6 #include <stdio.h>
7
8 #define min(x, y) ((x)<(y)?(x):(y))
9
10 void die(const char *msg, ...);
11 void pdie(const char *msg);
12
13 /* if buf == NULL, a fresh buffer is allocated */
14 char *escape_char(char c, char *buf, bool str);
15 /* unescaped character will be in position 0 and the rest from position 1 on */
16 char *unescape_char(char *c);
17 /* Remove the last and first character from the string */
18 char *trimquotes(char *c);
19 void pindent(int indent, FILE *out);
20
21 void safe_fprintf(FILE *out, const char *msg, ...);
22 void *safe_malloc(size_t size);
23 void *safe_strdup(const char *c);
24 FILE *safe_fopen(const char *path, const char *mode);
25 void safe_fclose(FILE *file);
26
27 #endif