Skip to content

Commit

Permalink
EXODUS: A better way to get strdup
Browse files Browse the repository at this point in the history
  • Loading branch information
gdsjaar committed May 15, 2024
1 parent f8178bd commit 74f2fe4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
15 changes: 2 additions & 13 deletions packages/seacas/libraries/exodus/src/ex_field_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,11 @@
#include "exodusII_int.h" // for EX_FATAL, etc
#include <assert.h>
#include <math.h>
#define _GNU_SOURCE
#include <string.h>

#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;
Expand Down Expand Up @@ -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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#define _GNU_SOURCE
#include <string.h>

#define STRINGIFY(x) #x
Expand Down

0 comments on commit 74f2fe4

Please sign in to comment.