X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libi3%2Fsafewrappers.c;h=0a233a1271f996272a50751c964e5ecf94b17015;hb=2c4fd56069cbfba9f49bda5fb6f6c37355c3fa1f;hp=db9b6b4a42efbf287e06466295ad0e2d2e30e2e5;hpb=971864062219bdb4b4ce24fdcf007f2f05251a8a;p=i3%2Fi3 diff --git a/libi3/safewrappers.c b/libi3/safewrappers.c index db9b6b4a..0a233a12 100644 --- a/libi3/safewrappers.c +++ b/libi3/safewrappers.c @@ -2,7 +2,7 @@ * vim:ts=4:sw=4:expandtab * * i3 - an improved dynamic tiling window manager - * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE) + * © 2009 Michael Stapelberg and contributors (see also: LICENSE) * */ #include @@ -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;