main shrubtools / nviz / util.h
 1struct buffer {
 2	char *data;
 3	size_t len, cap;
 4};
 5
 6struct string {
 7	size_t n;
 8	char s[];
 9};
10
11/* an unevaluated string */
12struct evalstring {
13	char *var;
14	struct string *str;
15	struct evalstring *next;
16};
17
18#ifndef countof
19#define countof(a) (sizeof(a) / sizeof((a)[0]))
20#endif
21
22void warn(const char *, ...);
23void fatal(const char *, ...);
24
25void *xmalloc(size_t);
26void *xreallocarray(void *, size_t, size_t);
27char *xmemdup(const char *, size_t);
28int xasprintf(char **, const char *, ...);
29
30/* append a byte to a buffer */
31void bufadd(struct buffer *buf, char c);
32
33/* allocates a new string with length n. n + 1 bytes are allocated for
34 * s, but not initialized. */
35struct string *mkstr(size_t n);
36
37/* delete an unevaluated string */
38void delevalstr(void *);
39
40/* canonicalizes the given path by removing duplicate slashes, and
41 * folding '/.' and 'foo/..' */
42void canonpath(struct string *);
43/* write a new file with the given name and contents */
44int writefile(const char *, struct string *);