it becomes entirely unusable.
-/* $OpenBSD: alloc.c,v 1.18 2018/09/18 02:29:10 miko Exp $ */
+/* $OpenBSD: alloc.c,v 1.19 2018/09/18 06:56:09 deraadt Exp $ */
/* $NetBSD: alloc.c,v 1.6 1995/03/21 09:02:23 cgd Exp $ */
/*-
#include "extern.h"
void *
-xmalloc(size_t n)
+Malloc(size_t n)
{
void *ptr;
}
void *
-xreallocarray(void * p, size_t c, size_t n)
+Reallocarray(void * p, size_t c, size_t n)
{
void *ptr;
}
void *
-xcalloc(size_t s, size_t n)
+Calloc(size_t s, size_t n)
{
void *ptr;
-/* $OpenBSD: csh.h,v 1.31 2018/09/18 02:29:10 miko Exp $ */
+/* $OpenBSD: csh.h,v 1.32 2018/09/18 06:56:09 deraadt Exp $ */
/* $NetBSD: csh.h,v 1.9 1995/03/21 09:02:40 cgd Exp $ */
/*-
#include "char.h"
#include "error.h"
+#define xmalloc(i) Malloc(i)
+#define xreallocarray(p, i, j) Reallocarray(p, i, j)
+#define xcalloc(n, s) Calloc(n, s)
+
#include <stdio.h>
FILE *cshin, *cshout, *csherr;
-/* $OpenBSD: dol.c,v 1.23 2018/09/17 16:00:19 martijn Exp $ */
+/* $OpenBSD: dol.c,v 1.24 2018/09/18 06:56:09 deraadt Exp $ */
/* $NetBSD: dol.c,v 1.8 1995/09/27 00:38:38 jtc Exp $ */
/*-
for (i = 0; Isdigit(*np); i = i * 10 + *np++ - '0')
continue;
- if ((i < 0 || i > upb) && !strchr("-*", *np)) {
+ if ((i < 0 || i > upb) && !any("-*", *np)) {
dolerror(vp->v_name);
return;
}
dolmod[dolnmod++] = delim;
if (!delim || letter(delim)
- || Isdigit(delim) || strchr(" \t\n", delim)) {
+ || Isdigit(delim) || any(" \t\n", delim)) {
seterror(ERR_BADSUBST);
break;
}
}
continue;
}
- if (!strchr("htrqxes", c))
+ if (!any("htrqxes", c))
stderror(ERR_BADMOD, c);
dolmod[dolnmod++] = c;
if (c == 'q')
delim = dolmod[++i];
if (!delim || letter(delim)
- || Isdigit(delim) || strchr(" \t\n", delim)) {
+ || Isdigit(delim) || any(" \t\n", delim)) {
seterror(ERR_BADSUBST);
break;
}
/* \ quotes \ $ ` here */
if (c == '\\') {
c = DgetC(0);
- if (!strchr("$\\`", c))
+ if (!any("$\\`", c))
unDgetC(c | QUOTE), c = '\\';
else
c |= QUOTE;
* If any ` in line do command substitution
*/
mbp = mbuf;
- if (strchr(short2str(mbp), '`')) {
+ if (any(short2str(mbp), '`')) {
/*
* 1 arg to dobackp causes substitution to be literal. Words are
* broken only at newlines so that all blanks and tabs are
-/* $OpenBSD: error.c,v 1.15 2018/09/15 12:15:32 miko Exp $ */
+/* $OpenBSD: error.c,v 1.16 2018/09/18 06:56:09 deraadt 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 = xstrdup(berr);
+ seterr = strsave(berr);
}
}
-/* $OpenBSD: exec.c,v 1.20 2018/09/17 16:00:19 martijn Exp $ */
+/* $OpenBSD: exec.c,v 1.21 2018/09/18 06:56:09 deraadt Exp $ */
/* $NetBSD: exec.c,v 1.9 1996/09/30 20:03:54 christos Exp $ */
/*-
blkfree(pv);
pexerr();
}
- slash = (bool) strchr(short2str(expath), '/');
+ slash = any(short2str(expath), '/');
/*
* Glob the argument list, if necessary. Otherwise trim off the quote bits.
Char **pv;
Char *sav;
struct varent *v;
- bool slash = (bool) strchr(short2str(name), '/');
+ bool slash = any(short2str(name), '/');
int hashval = 0, hashval1, i;
v = adrof(STRpath);
if ((i = iscommand(sp->word)) != 0) {
Char **pv;
struct varent *v;
- bool slash = (bool) strchr(short2str(sp->word), '/');
+ bool slash = any(short2str(sp->word), '/');
v = adrof(STRpath);
if (v == 0 || v->vec[0] == 0 || slash)
-/* $OpenBSD: exp.c,v 1.17 2018/09/17 16:00:19 martijn Exp $ */
+/* $OpenBSD: exp.c,v 1.18 2018/09/18 06:56:09 deraadt Exp $ */
/* $NetBSD: exp.c,v 1.6 1995/03/21 09:02:51 cgd Exp $ */
/*-
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
-#include <string.h>
#include "csh.h"
#include "extern.h"
p1 = exp4(vp, ignore);
op = **vp;
- if (op && strchr("<>", op[0]) && op[0] == op[1]) {
+ if (op && any("<>", op[0]) && op[0] == op[1]) {
(*vp)++;
p2 = exp3a(vp, ignore);
if (op[0] == '<')
if (isa(**vp, ANYOP))
return (Strsave(STRNULL));
cp = *(*vp)++;
- if (*cp == '-' && strchr("erwxfdzopls", cp[1])) {
+ if (*cp == '-' && any("erwxfdzopls", cp[1])) {
struct stat stb;
if (cp[2] != '\0')
-/* $OpenBSD: extern.h,v 1.29 2018/09/18 02:29:10 miko Exp $ */
+/* $OpenBSD: extern.h,v 1.30 2018/09/18 06:56:09 deraadt Exp $ */
/* $NetBSD: extern.h,v 1.8 1996/10/31 23:50:54 christos Exp $ */
/*-
/*
* misc.c
*/
+int any(char *, int);
Char **blkcat(Char **, Char **);
Char **blkcpy(Char **, Char **);
Char **blkend(Char **);
Char **saveblk(Char **);
Char *strip(Char *);
Char *quote(Char *);
-char *xstrdup(const char *);
+char *strsave(char *);
char *strspl(char *, char *);
void udvar(Char *);
/*
* alloc.c
*/
-void * xmalloc(size_t);
-void * xreallocarray(void *, size_t, size_t);
-void * xcalloc(size_t, size_t);
+void * Malloc(size_t);
+void * Reallocarray(void *, size_t, size_t);
+void * Calloc(size_t, size_t);
/*
* str.c:
-/* $OpenBSD: lex.c,v 1.26 2018/09/17 16:00:19 martijn Exp $ */
+/* $OpenBSD: lex.c,v 1.27 2018/09/18 06:56:09 deraadt Exp $ */
/* $NetBSD: lex.c,v 1.9 1995/09/27 00:38:46 jtc Exp $ */
/*-
np = name, *np++ = '$';
c = sc = getC(DOEXCL);
- if (strchr("\t \n", c)) {
+ if (any("\t \n", c)) {
ungetD(c);
ungetC('$' | QUOTE);
return;
*np++ = delim;
if (!delim || letter(delim)
- || Isdigit(delim) || strchr(" \t\n", delim)) {
+ || Isdigit(delim) || any(" \t\n", delim)) {
seterror(ERR_BADSUBST);
break;
}
}
c = 's';
}
- if (!strchr("htrqxes", c)) {
+ if (!any("htrqxes", c)) {
if ((amodflag || gmodflag) && c == '\n')
stderror(ERR_VARSYN); /* strike */
seterror(ERR_VARMOD, c);
goto subst;
}
c = getC(0);
- if (!strchr(":^$*-%", c))
+ if (!any(":^$*-%", c))
goto subst;
left = right = -1;
if (c == ':') {
case 's':
delim = getC(0);
- if (letter(delim) || Isdigit(delim) || strchr(" \t\n", delim)) {
+ if (letter(delim) || Isdigit(delim) || any(" \t\n", delim)) {
unreadc(delim);
lhsb[0] = 0;
seterror(ERR_BADSUBST);
case 'h':
case 't':
- if (!strchr(short2str(cp), '/'))
+ if (!any(short2str(cp), '/'))
return (type == 't' ? Strsave(cp) : 0);
wp = Strend(cp);
while (*--wp != '/')
if (first) {
c = getC(0);
unreadc(c);
- if (strchr("-$*", c))
+ if (any("-$*", c))
return (1);
}
if (*al > *ar || *ar > dol) {
/* FALLSTHROUGH */
default:
- if (strchr("(=~", c)) {
+ if (any("(=~", c)) {
unreadc(c);
ungetC(HIST);
return (0);
}
np = lhsb;
event = 0;
- while (!cmap(c, _ESC | _META | _QF | _QB) && !strchr("${}:", c)) {
+ while (!cmap(c, _ESC | _META | _QF | _QB) && !any("${}:", c)) {
if (event != -1 && Isdigit(c))
event = event * 10 + c - '0';
else
-/* $OpenBSD: misc.c,v 1.22 2018/09/17 16:00:19 martijn Exp $ */
+/* $OpenBSD: misc.c,v 1.23 2018/09/18 06:56:09 deraadt 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"
static int fdcmp(int);
static int renum(int, int);
+int
+any(char *s, int c)
+{
+ if (!s)
+ return (0); /* Check for nil pointer */
+ while (*s)
+ if (*s++ == c)
+ return (1);
+ return (0);
+}
+
char *
-xstrdup(const char *s)
+strsave(char *s)
{
- char *n;
+ char *n;
+ char *p;
if (s == NULL)
s = "";
- if ((n = strdup(s)) == NULL) {
- child++;
- stderror(ERR_NOMEM);
- }
+ for (p = s; *p++;)
+ continue;
+ n = p = xreallocarray(NULL, (p - s), sizeof(char));
+ while ((*p++ = *s++) != '\0')
+ continue;
return (n);
}
-/* $OpenBSD: parse.c,v 1.13 2018/09/17 16:00:19 martijn Exp $ */
+/* $OpenBSD: parse.c,v 1.14 2018/09/18 06:56:09 deraadt Exp $ */
/* $NetBSD: parse.c,v 1.6 1995/03/21 09:03:10 cgd Exp $ */
/*-
asyntax(struct wordent *p1, struct wordent *p2)
{
while (p1 != p2)
- if (strchr(";&\n", p1->word[0]))
+ if (any(";&\n", p1->word[0]))
p1 = p1->next;
else {
asyn0(p1, p2);
{
while (p1 != p2)
- if (strchr(";&\n", p1->word[0]))
+ if (any(";&\n", p1->word[0]))
p1 = p1->next;
else
return (syn0(p1, p2, flags));
}
if (p->next == p2)
continue;
- if (strchr(RELPAR, p->next->word[0]))
+ if (any(RELPAR, p->next->word[0]))
continue;
n--;
continue;
continue;
}
p = p->next;
- if (strchr(RELPAR, p->word[0])) {
+ if (any(RELPAR, p->word[0])) {
seterror(ERR_MISRED);
continue;
}
continue;
}
p = p->next;
- if (strchr(RELPAR, p->word[0])) {
+ if (any(RELPAR, p->word[0])) {
seterror(ERR_MISRED);
continue;
}
-/* $OpenBSD: set.c,v 1.20 2018/09/17 16:00:19 martijn Exp $ */
+/* $OpenBSD: set.c,v 1.21 2018/09/18 06:56:09 deraadt Exp $ */
/* $NetBSD: set.c,v 1.8 1995/03/21 18:35:52 mycroft Exp $ */
/*-
#include <sys/types.h>
#include <stdlib.h>
#include <stdarg.h>
-#include <string.h>
#include "csh.h"
#include "extern.h"
}
else {
c = *p++;
- if (strchr("+-", c)) {
+ if (any("+-", c)) {
if (c != op || *p)
stderror(ERR_NAME | ERR_UNKNOWNOP);
p = Strsave(STR1);
}
else {
- if (strchr("<>", op)) {
+ if (any("<>", op)) {
if (c != op)
stderror(ERR_NAME | ERR_UNKNOWNOP);
c = *p++;
-/* $OpenBSD: str.c,v 1.20 2018/09/15 12:15:32 miko Exp $ */
+/* $OpenBSD: str.c,v 1.21 2018/09/18 06:56:09 deraadt 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++ = xstrdup(short2str(*src));
+ *dst++ = strsave(short2str(*src));
*dst = NULL;
return (sdst);
}
-/* $OpenBSD: time.c,v 1.16 2018/09/17 16:00:19 martijn Exp $ */
+/* $OpenBSD: time.c,v 1.17 2018/09/18 06:56:09 deraadt Exp $ */
/* $NetBSD: time.c,v 1.7 1995/03/21 13:55:25 mycroft Exp $ */
/*-
#include <sys/types.h>
#include <stdarg.h>
-#include <string.h>
#include "csh.h"
#include "extern.h"
v++, cp = *v++;
if (cp == 0)
nval = 4;
- else if (*v == 0 && strchr("+-", cp[0]))
+ else if (*v == 0 && any("+-", cp[0]))
nval = getn(cp);
(void) setpriority(PRIO_PROCESS, 0, nval);
}