2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
5 * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
17 * The s* functions (safe) are wrappers around malloc, strdup, …, which exits if one of
18 * the called functions returns NULL, meaning that there is no more memory available
21 void *smalloc(size_t size) {
22 void *result = malloc(size);
24 err(EXIT_FAILURE, "malloc(%zd)", size);
28 void *scalloc(size_t size) {
29 void *result = calloc(size, 1);
31 err(EXIT_FAILURE, "calloc(%zd)", size);
35 void *srealloc(void *ptr, size_t size) {
36 void *result = realloc(ptr, size);
37 if (result == NULL && size > 0)
38 err(EXIT_FAILURE, "realloc(%zd)", size);
42 char *sstrdup(const char *str) {
43 char *result = strdup(str);
45 err(EXIT_FAILURE, "strdup()");
49 int sasprintf(char **strp, const char *fmt, ...) {
54 if ((result = vasprintf(strp, fmt, args)) == -1)
55 err(EXIT_FAILURE, "asprintf(%s)", fmt);