* © 2009 Michael Stapelberg and contributors (see also: LICENSE)
*
*/
+#include "libi3.h"
+
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <err.h>
#include <errno.h>
-#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
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;
}
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;