X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libi3%2Fsafewrappers.c;h=0a233a1271f996272a50751c964e5ecf94b17015;hb=d6aece03ee27e2f1819c25663c6b2f20f1879892;hp=74460f37662360f75153048c1c0b0298327b5c74;hpb=67ec2333ee659e4b8ce90e75b94a518a2dee81c0;p=i3%2Fi3 diff --git a/libi3/safewrappers.c b/libi3/safewrappers.c index 74460f37..0a233a12 100644 --- a/libi3/safewrappers.c +++ b/libi3/safewrappers.c @@ -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;