Skip to content

Commit

Permalink
EXODUS: Provide internal strsep and strlcat
Browse files Browse the repository at this point in the history
  • Loading branch information
gdsjaar committed May 14, 2024
1 parent 66d6a3a commit 1d9e701
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
16 changes: 5 additions & 11 deletions packages/seacas/libraries/exodus/src/ex_field_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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];
Expand Down
9 changes: 3 additions & 6 deletions packages/seacas/libraries/exodus/test/testrd-field-metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -28,7 +26,6 @@ char *strsep(char **stringp, const char *delim)
}
return rv;
}
#endif

#define EXCHECK(funcall) \
do { \
Expand All @@ -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];
Expand Down

0 comments on commit 1d9e701

Please sign in to comment.