From 1d9e70152abe310d915e85a1e622f3662a3f302a Mon Sep 17 00:00:00 2001 From: Greg Sjaardema Date: Tue, 14 May 2024 17:20:45 -0600 Subject: [PATCH] EXODUS: Provide internal strsep and strlcat --- .../seacas/libraries/exodus/src/ex_field_utils.c | 16 +++++----------- .../exodus/test/testrd-field-metadata.c | 9 +++------ 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/packages/seacas/libraries/exodus/src/ex_field_utils.c b/packages/seacas/libraries/exodus/src/ex_field_utils.c index 4d78592f47..f8e07a49f2 100644 --- a/packages/seacas/libraries/exodus/src/ex_field_utils.c +++ b/packages/seacas/libraries/exodus/src/ex_field_utils.c @@ -14,10 +14,7 @@ #define SIZE(X) sizeof(X) / sizeof(X[0]) -#if defined(__MINGW32__) || defined(_WIN64) || defined(__MINGW64__) || \ - defined(__INTEL_LLVM_COMPILER) -#if !defined(strsep) -char *strsep(char **stringp, const char *delim) +char *my_strsep(char **stringp, const char *delim) { char *rv = *stringp; if (rv) { @@ -29,8 +26,7 @@ char *strsep(char **stringp, const char *delim) } return rv; } -#endif -size_t strlcat(char *restrict dst, const char *restrict src, size_t maxlen) +size_t my_strlcat(char *restrict dst, const char *restrict src, size_t maxlen) { const size_t srclen = strlen(src); const size_t dstlen = strnlen(dst, maxlen); @@ -46,8 +42,6 @@ size_t strlcat(char *restrict dst, const char *restrict src, size_t maxlen) return dstlen + srclen; } -#endif - static int number_width(const size_t number) { if (number == 0) { @@ -84,7 +78,7 @@ const char *ex_component_field_name(ex_field *field, int component[EX_MAX_FIELD_ field_name[fnl] = field->component_separator[i]; field_name[fnl + 1] = '\0'; } - strlcat(field_name, suffices[i], EX_MAX_NAME); + my_strlcat(field_name, suffices[i], EX_MAX_NAME); } return field_name; } @@ -311,9 +305,9 @@ const char *ex_field_component_suffix(ex_field *field, int nest_level, int compo // `user_suffices` is a comma-separated string. Assume component is valid. char *string = strdup(field->suffices); char *tofree = string; - char *token = strsep(&string, ","); + char *token = my_strsep(&string, ","); for (int i = 0; i < component - 1; i++) { - token = strsep(&string, ","); + token = my_strsep(&string, ","); } if (token != NULL) { static char user_suffix[32 + 1]; diff --git a/packages/seacas/libraries/exodus/test/testrd-field-metadata.c b/packages/seacas/libraries/exodus/test/testrd-field-metadata.c index 52ab60946c..75c31d4b8a 100644 --- a/packages/seacas/libraries/exodus/test/testrd-field-metadata.c +++ b/packages/seacas/libraries/exodus/test/testrd-field-metadata.c @@ -14,9 +14,7 @@ #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) -#if defined(__MINGW32__) || defined(_WIN64) || defined(__MINGW64__) || \ - defined(__INTEL_LLVM_COMPILER) -char *strsep(char **stringp, const char *delim) +char *my_strsep(char **stringp, const char *delim) { char *rv = *stringp; if (rv) { @@ -28,7 +26,6 @@ char *strsep(char **stringp, const char *delim) } return rv; } -#endif #define EXCHECK(funcall) \ do { \ @@ -46,9 +43,9 @@ static char *get_type_name(char *type_name, size_t which) if (type_name != NULL && type_name[0] != '\0') { char *string = strdup(type_name); char *tofree = string; - char *token = strsep(&string, ","); + char *token = my_strsep(&string, ","); for (int i = 0; i < which; i++) { - token = strsep(&string, ","); + token = my_strsep(&string, ","); } if (token != NULL) { static char tmp_type_name[256 + 1];