with help from martijn@.
ok millert@ martijn@
-/* $OpenBSD: error.c,v 1.14 2018/09/08 01:28:39 miko Exp $ */
+/* $OpenBSD: error.c,v 1.15 2018/09/15 12:15:32 miko Exp $ */
/* $NetBSD: err.c,v 1.6 1995/03/21 09:02:47 cgd Exp $ */
/*-
vsnprintf(berr, sizeof(berr), errorlist[id], va);
va_end(va);
- seterr = strsave(berr);
+ seterr = xstrdup(berr);
}
}
-/* $OpenBSD: extern.h,v 1.26 2017/07/22 09:37:21 anton Exp $ */
+/* $OpenBSD: extern.h,v 1.27 2018/09/15 12:15:32 miko Exp $ */
/* $NetBSD: extern.h,v 1.8 1996/10/31 23:50:54 christos Exp $ */
/*-
Char **saveblk(Char **);
Char *strip(Char *);
Char *quote(Char *);
-char *strsave(char *);
+char *xstrdup(const char *);
char *strspl(char *, char *);
void udvar(Char *);
-/* $OpenBSD: misc.c,v 1.20 2017/06/20 16:44:06 anton Exp $ */
+/* $OpenBSD: misc.c,v 1.21 2018/09/15 12:15:32 miko Exp $ */
/* $NetBSD: misc.c,v 1.6 1995/03/21 09:03:09 cgd Exp $ */
/*-
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
+#include <string.h>
#include "csh.h"
#include "extern.h"
}
char *
-strsave(char *s)
+xstrdup(const char *s)
{
- char *n;
- char *p;
+ char *n;
if (s == NULL)
s = "";
- for (p = s; *p++;)
- continue;
- n = p = xreallocarray(NULL, (p - s), sizeof(char));
- while ((*p++ = *s++) != '\0')
- continue;
+ if ((n = strdup(s)) == NULL) {
+ child++;
+ stderror(ERR_NOMEM);
+ }
return (n);
}
-/* $OpenBSD: str.c,v 1.19 2015/10/26 16:31:09 naddy Exp $ */
+/* $OpenBSD: str.c,v 1.20 2018/09/15 12:15:32 miko Exp $ */
/* $NetBSD: str.c,v 1.6 1995/03/21 09:03:24 cgd Exp $ */
/*-
sdst = dst = xreallocarray(NULL, n + 1, sizeof(char *));
for (; *src != NULL; src++)
- *dst++ = strsave(short2str(*src));
+ *dst++ = xstrdup(short2str(*src));
*dst = NULL;
return (sdst);
}