summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authormiko <miko@cvs.openbsd.org>2018-09-15 12:15:33 +0000
committermiko <miko@cvs.openbsd.org>2018-09-15 12:15:33 +0000
commitc34d06059d2e9bf5e2535a92f40a58db1989866d (patch)
tree2dd6ccf61eda8d4e034953bfcfd8e8ecfffc3599 /bin
parent75ef7240d898870efeba4ea5d3f1cf84753dba35 (diff)
strsave() is hard-fail strdup() so simplify and rename to xstrdup().
with help from martijn@. ok millert@ martijn@
Diffstat (limited to 'bin')
-rw-r--r--bin/csh/error.c4
-rw-r--r--bin/csh/extern.h4
-rw-r--r--bin/csh/misc.c17
-rw-r--r--bin/csh/str.c4
4 files changed, 14 insertions, 15 deletions
diff --git a/bin/csh/error.c b/bin/csh/error.c
index 723a6213485..6d8aa8321b2 100644
--- a/bin/csh/error.c
+++ b/bin/csh/error.c
@@ -1,4 +1,4 @@
-/* $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 $ */
/*-
@@ -289,7 +289,7 @@ seterror(int id, ...)
vsnprintf(berr, sizeof(berr), errorlist[id], va);
va_end(va);
- seterr = strsave(berr);
+ seterr = xstrdup(berr);
}
}
diff --git a/bin/csh/extern.h b/bin/csh/extern.h
index aba5f06ca06..8cc67947a80 100644
--- a/bin/csh/extern.h
+++ b/bin/csh/extern.h
@@ -1,4 +1,4 @@
-/* $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 $ */
/*-
@@ -201,7 +201,7 @@ int prefix(Char *, Char *);
Char **saveblk(Char **);
Char *strip(Char *);
Char *quote(Char *);
-char *strsave(char *);
+char *xstrdup(const char *);
char *strspl(char *, char *);
void udvar(Char *);
diff --git a/bin/csh/misc.c b/bin/csh/misc.c
index 5fc9e8d815b..f6030765c92 100644
--- a/bin/csh/misc.c
+++ b/bin/csh/misc.c
@@ -1,4 +1,4 @@
-/* $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 $ */
/*-
@@ -34,6 +34,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
+#include <string.h>
#include "csh.h"
#include "extern.h"
@@ -53,18 +54,16 @@ any(char *s, int c)
}
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);
}
diff --git a/bin/csh/str.c b/bin/csh/str.c
index edf45e31188..2355bab92bb 100644
--- a/bin/csh/str.c
+++ b/bin/csh/str.c
@@ -1,4 +1,4 @@
-/* $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 $ */
/*-
@@ -77,7 +77,7 @@ short2blk(Char **src)
sdst = dst = xreallocarray(NULL, n + 1, sizeof(char *));
for (; *src != NULL; src++)
- *dst++ = strsave(short2str(*src));
+ *dst++ = xstrdup(short2str(*src));
*dst = NULL;
return (sdst);
}