X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libi3%2Fsafewrappers.c;h=94ad4ee6c60a73fa4a28ae6cb4d353d9f5bfff4b;hb=6dfa348960be752a1e46e16887c01cdec4946580;hp=74460f37662360f75153048c1c0b0298327b5c74;hpb=66a1fa7d4643981bcc8f78b03e170e35bf00bfc7;p=i3%2Fi3 diff --git a/libi3/safewrappers.c b/libi3/safewrappers.c index 74460f37..94ad4ee6 100644 --- a/libi3/safewrappers.c +++ b/libi3/safewrappers.c @@ -5,6 +5,8 @@ * © 2009 Michael Stapelberg and contributors (see also: LICENSE) * */ +#include "libi3.h" + #include #include #include @@ -13,8 +15,6 @@ #include #include -#include "libi3.h" - /* * The s* functions (safe) are wrappers around malloc, strdup, …, which exits if one of * the called functions returns NULL, meaning that there is no more memory available @@ -27,10 +27,10 @@ void *smalloc(size_t size) { return result; } -void *scalloc(size_t size) { - void *result = calloc(size, 1); +void *scalloc(size_t num, size_t size) { + void *result = calloc(num, size); if (result == NULL) - err(EXIT_FAILURE, "calloc(%zd)", size); + err(EXIT_FAILURE, "calloc(%zd, %zd)", num, size); return result; } @@ -48,6 +48,13 @@ char *sstrdup(const char *str) { return result; } +char *sstrndup(const char *str, size_t size) { + char *result = strndup(str, size); + if (result == NULL) + err(EXIT_FAILURE, "strndup()"); + return result; +} + int sasprintf(char **strp, const char *fmt, ...) { va_list args; int result;