From 74f2fe4048b0356648273bb1cce35fc467f64f5e Mon Sep 17 00:00:00 2001 From: Greg Sjaardema Date: Wed, 15 May 2024 10:07:46 -0600 Subject: [PATCH] EXODUS: A better way to get strdup --- .../seacas/libraries/exodus/src/ex_field_utils.c | 15 ++------------- .../libraries/exodus/test/testrd-field-metadata.c | 1 + 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/packages/seacas/libraries/exodus/src/ex_field_utils.c b/packages/seacas/libraries/exodus/src/ex_field_utils.c index 2a77dfd83e..cda2985cef 100644 --- a/packages/seacas/libraries/exodus/src/ex_field_utils.c +++ b/packages/seacas/libraries/exodus/src/ex_field_utils.c @@ -10,22 +10,11 @@ #include "exodusII_int.h" // for EX_FATAL, etc #include #include +#define _GNU_SOURCE #include #define SIZE(X) sizeof(X) / sizeof(X[0]) -char *my_strdup(const char *s) -{ - size_t slen = strlen(s); - char *result = malloc(slen + 1); - if (result == NULL) { - return NULL; - } - - memcpy(result, s, slen + 1); - return result; -} - char *my_strsep(char **stringp, const char *delim) { char *rv = *stringp; @@ -315,7 +304,7 @@ const char *ex_field_component_suffix(ex_field *field, int nest_level, int compo case EX_FIELD_TYPE_USER_DEFINED: { if (field->suffices[0] != '\0') { // `user_suffices` is a comma-separated string. Assume component is valid. - char *string = my_strdup(field->suffices); + char *string = strdup(field->suffices); char *tofree = string; char *token = my_strsep(&string, ","); for (int i = 0; i < component - 1; i++) { diff --git a/packages/seacas/libraries/exodus/test/testrd-field-metadata.c b/packages/seacas/libraries/exodus/test/testrd-field-metadata.c index c8f4f89226..80f23aea86 100644 --- a/packages/seacas/libraries/exodus/test/testrd-field-metadata.c +++ b/packages/seacas/libraries/exodus/test/testrd-field-metadata.c @@ -9,6 +9,7 @@ #include #include #include +#define _GNU_SOURCE #include #define STRINGIFY(x) #x