2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
6 * © 2009-2011 Michael Stapelberg and contributors
8 * See file LICENSE for license information.
19 * The s* functions (safe) are wrappers around malloc, strdup, …, which exits if one of
20 * the called functions returns NULL, meaning that there is no more memory available
23 void *smalloc(size_t size) {
24 void *result = malloc(size);
26 err(EXIT_FAILURE, "malloc(%zd)", size);
30 void *scalloc(size_t size) {
31 void *result = calloc(size, 1);
33 err(EXIT_FAILURE, "calloc(%zd)", size);
37 void *srealloc(void *ptr, size_t size) {
38 void *result = realloc(ptr, size);
39 if (result == NULL && size > 0)
40 err(EXIT_FAILURE, "realloc(%zd)", size);
44 char *sstrdup(const char *str) {
45 char *result = strdup(str);
47 err(EXIT_FAILURE, "strdup()");
51 int sasprintf(char **strp, const char *fmt, ...) {
56 if ((result = vasprintf(strp, fmt, args)) == -1)
57 err(EXIT_FAILURE, "asprintf(%s)", fmt);