summaryrefslogtreecommitdiff
path: root/include/sheep/util.h
blob: 564c5eb27c1526042891f23ec8ce6b2b101d0a7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
 * include/sheep/util.h
 *
 * Copyright (c) 2009 Johannes Weiner <hannes@cmpxchg.org>
 */
#ifndef _SHEEP_UTIL_H
#define _SHEEP_UTIL_H

#include <stdarg.h>
#include <stddef.h>

#ifdef __GNUC__
#define __noreturn	__attribute__((noreturn))
#else
#define __noreturn
#endif

void *sheep_malloc(size_t);
void *sheep_zalloc(size_t);
void *sheep_realloc(void *, size_t);
char *sheep_strdup(const char *);
void sheep_free(const void *);

struct sheep_strbuf {
	char *bytes;
	size_t nr_bytes;
};
void sheep_strbuf_addn(struct sheep_strbuf *, const char *, size_t);
void sheep_strbuf_add(struct sheep_strbuf *, const char *);
void sheep_strbuf_addf(struct sheep_strbuf *, const char *, ...);

void __noreturn sheep_bug(const char *, ...);

#define sheep_bug_on(cond)						\
	do if (cond)							\
		   sheep_bug("Unexpected condition `%s' in %s:%d",	\
			   #cond, __FILE__, __LINE__);			\
	while (0)

#endif /* _SHEEP_UTIL_H */