aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-08-28 13:23:45 +0200
committerMattias Andrée <maandree@kth.se>2018-08-28 13:24:00 +0200
commit34c0fd8f36269699b75e0aaf841911b5ae06246e (patch)
tree29cded18fde2cede51008b811713ef5c497f53db
parentAdd tests for allocation functions (diff)
downloadlibsimple-34c0fd8f36269699b75e0aaf841911b5ae06246e.tar.gz
libsimple-34c0fd8f36269699b75e0aaf841911b5ae06246e.tar.bz2
libsimple-34c0fd8f36269699b75e0aaf841911b5ae06246e.tar.xz
Simplify en* functions, and handle argv0 == NULL correct
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--encalloc.c9
-rw-r--r--enmalloc.c9
-rw-r--r--enmemdup.c9
-rw-r--r--enrealloc.c9
-rw-r--r--enstrdup.c9
-rw-r--r--enstrndup.c9
-rw-r--r--envmalloczn.c9
-rw-r--r--envputenvf.c9
-rw-r--r--envreallocn.c9
9 files changed, 18 insertions, 63 deletions
diff --git a/encalloc.c b/encalloc.c
index 1277d7b..de5a2c9 100644
--- a/encalloc.c
+++ b/encalloc.c
@@ -3,17 +3,12 @@
#ifndef TEST
-extern char *argv0;
-
-
void *
libsimple_encalloc(int status, size_t n, size_t m) /* TODO test */
{
void *ret = calloc(n, m);
- if (!ret) {
- fprintf(stderr, "%s: calloc: %s\n", argv0, strerror(errno));
- exit(status);
- }
+ if (!ret)
+ enprintf(status, "calloc:");
return ret;
}
diff --git a/enmalloc.c b/enmalloc.c
index 0a13f03..f981872 100644
--- a/enmalloc.c
+++ b/enmalloc.c
@@ -3,17 +3,12 @@
#ifndef TEST
-extern char *argv0;
-
-
void *
libsimple_enmalloc(int status, size_t n) /* TODO test */
{
void *ret = malloc(n);
- if (!ret) {
- fprintf(stderr, "%s: malloc: %s\n", argv0, strerror(errno));
- exit(status);
- }
+ if (!ret)
+ enprintf(status, "malloc:");
return ret;
}
diff --git a/enmemdup.c b/enmemdup.c
index 8693af6..9050efd 100644
--- a/enmemdup.c
+++ b/enmemdup.c
@@ -3,17 +3,12 @@
#ifndef TEST
-extern char *argv0;
-
-
void *
libsimple_enmemdup(int status, const void *s, size_t n) /* TODO test */
{
void *ret = memdup(s, n);
- if (!ret) {
- fprintf(stderr, "%s: memdup: %s\n", argv0, strerror(errno));
- exit(status);
- }
+ if (!ret)
+ enprintf(status, "memdup:");
return ret;
}
diff --git a/enrealloc.c b/enrealloc.c
index 04feede..92a50db 100644
--- a/enrealloc.c
+++ b/enrealloc.c
@@ -3,17 +3,12 @@
#ifndef TEST
-extern char *argv0;
-
-
void *
libsimple_enrealloc(int status, void *ptr, size_t n) /* TODO test */
{
char *ret = realloc(ptr, n);
- if (!ret) {
- fprintf(stderr, "%s: realloc: %s\n", argv0, strerror(errno));
- exit(status);
- }
+ if (!ret)
+ enprintf(status, "realloc:");
return ret;
}
diff --git a/enstrdup.c b/enstrdup.c
index 2adb309..d8a8c53 100644
--- a/enstrdup.c
+++ b/enstrdup.c
@@ -3,17 +3,12 @@
#ifndef TEST
-extern char *argv0;
-
-
char *
libsimple_enstrdup(int status, const char *s) /* TODO test */
{
char *ret = strdup(s);
- if (!ret) {
- fprintf(stderr, "%s: strdup: %s\n", argv0, strerror(errno));
- exit(status);
- }
+ if (!ret)
+ enprintf(status, "strdup:");
return ret;
}
diff --git a/enstrndup.c b/enstrndup.c
index 7dd6595..8803a99 100644
--- a/enstrndup.c
+++ b/enstrndup.c
@@ -3,17 +3,12 @@
#ifndef TEST
-extern char *argv0;
-
-
char *
libsimple_enstrndup(int status, const char *s, size_t n) /* TODO test */
{
void *ret = strndup(s, n);
- if (!ret) {
- fprintf(stderr, "%s: strndup: %s\n", argv0, strerror(errno));
- exit(status);
- }
+ if (!ret)
+ enprintf(status, "strndup:");
return ret;
}
diff --git a/envmalloczn.c b/envmalloczn.c
index 832ce67..84c0ea7 100644
--- a/envmalloczn.c
+++ b/envmalloczn.c
@@ -3,17 +3,12 @@
#ifndef TEST
-extern char *argv0;
-
-
void *
libsimple_envmalloczn(int status, int clear, size_t n, va_list ap) /* TODO test */
{
void *ret = libsimple_vmalloczn(clear, n, ap);
- if (!ret) {
- fprintf(stderr, "%s: %s: %s\n", argv0, clear ? "calloc" : "malloc", strerror(errno));
- exit(status);
- }
+ if (!ret)
+ enprintf(status, "%s:", clear ? "calloc" : "malloc");
return ret;
}
diff --git a/envputenvf.c b/envputenvf.c
index cf30208..cdcf4f5 100644
--- a/envputenvf.c
+++ b/envputenvf.c
@@ -3,16 +3,11 @@
#ifndef TEST
-extern char *argv0;
-
-
void
libsimple_envputenvf(int status, const char *fmt, va_list ap) /* TODO test */
{
- if (vputenvf(fmt, ap)) {
- fprintf(stderr, "%s: putenvf: %s\n", argv0, strerror(errno));
- exit(status);
- }
+ if (vputenvf(fmt, ap))
+ enprintf(status, "putenvf:");
}
diff --git a/envreallocn.c b/envreallocn.c
index 44b69e3..1956933 100644
--- a/envreallocn.c
+++ b/envreallocn.c
@@ -3,17 +3,12 @@
#ifndef TEST
-extern char *argv0;
-
-
void *
libsimple_envreallocn(int status, void *ptr, size_t n, va_list ap) /* TODO test */
{
void *ret = libsimple_vreallocn(ptr, n, ap);
- if (!ret) {
- fprintf(stderr, "%s: realloc: %s\n", argv0, strerror(errno));
- exit(status);
- }
+ if (!ret)
+ enprintf(status, "realloc:");
return ret;
}