add dupeString wrapper function

This function calls strdup and exits on failure.
This commit is contained in:
William Hubbs 2021-07-05 19:32:37 -05:00
commit 4272a5299a
2 changed files with 12 additions and 0 deletions

View file

@ -62,6 +62,17 @@ void *reallocMem(void *p, size_t n)
return s;
}
char *dupeString(char *s)
{
char *c;
if (!(c = strdup(s))) {
fprintf(stderr, "Out of memory!\n");
exit(1);
}
return c;
}
char *initString(int *l)
{
*l = 0;

View file

@ -26,6 +26,7 @@ extern char *EMPTYSTRING;
void *allocMem(size_t n);
void *reallocMem(void *p, size_t n);
char *dupeString(char *s);
char *initString(int *l);
void stringAndString(char **s, int *l, const char *t);
void stringAndBytes(char **s, int *l, const char *t, int cnt);