diff options
| -rw-r--r-- | src/lib/core/include/str.h | 4 | ||||
| -rw-r--r-- | src/lib/core/str.c | 16 | ||||
| -rw-r--r-- | src/lib/delivery/delivery.c | 11 |
3 files changed, 20 insertions, 11 deletions
diff --git a/src/lib/core/include/str.h b/src/lib/core/include/str.h index 5097148..3e7c3a4 100644 --- a/src/lib/core/include/str.h +++ b/src/lib/core/include/str.h @@ -18,6 +18,10 @@ #define STASIS_SORT_LEN_ASCENDING 1 << 2 #define STASIS_SORT_LEN_DESCENDING 1 << 3 + +char *strdup_maybe_entry(const char * restrict s, struct ExecPoint ep, int exit_code); +#define strdup_maybe(S) strdup_maybe_entry((S), EXECPOINT, 1) + /** * Determine how many times the character `ch` appears in `sptr` string * @param sptr string to scan diff --git a/src/lib/core/str.c b/src/lib/core/str.c index 7ba6c5b..5df7372 100644 --- a/src/lib/core/str.c +++ b/src/lib/core/str.c @@ -4,6 +4,22 @@ #include <unistd.h> #include "str.h" + + +char *strdup_maybe_entry(const char * restrict s, const struct ExecPoint ep, const int exit_code) { + // USE MACRO FROM str.h: strdup_maybe() + if (s != NULL) { + char *x = strdup(s); + if (!x) { + SYSERROR("unable to duplicate string"); + log_print_error(ep, "out of memory"); + exit(exit_code); + } + return x; + } + return NULL; +} + int num_chars(const char *sptr, int ch) { int result = 0; for (int i = 0; sptr[i] != '\0'; i++) { diff --git a/src/lib/delivery/delivery.c b/src/lib/delivery/delivery.c index 644c0fb..a150169 100644 --- a/src/lib/delivery/delivery.c +++ b/src/lib/delivery/delivery.c @@ -1,17 +1,6 @@ #include "delivery.h" #include "conda.h" -static char *strdup_maybe(const char * restrict s) { - if (s != NULL) { - char *x = strdup(s); - if (!x) { - SYSERROR("%s", "strdup failed"); - exit(1); - } - return x; - } - return NULL; -} struct Delivery *delivery_duplicate(const struct Delivery *ctx) { struct Delivery *result = calloc(1, sizeof(*result)); if (!result) { |
