-/* $OpenBSD: alloc.c,v 1.19 2018/09/18 06:56:09 deraadt Exp $ */
+/* $OpenBSD: alloc.c,v 1.20 2018/09/18 17:48:22 millert Exp $ */
/* $NetBSD: alloc.c,v 1.6 1995/03/21 09:02:23 cgd Exp $ */
/*-
#include <unistd.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <string.h>
#include "csh.h"
#include "extern.h"
void *
-Malloc(size_t n)
+xmalloc(size_t n)
{
void *ptr;
}
void *
-Reallocarray(void * p, size_t c, size_t n)
+xreallocarray(void * p, size_t c, size_t n)
{
void *ptr;
}
void *
-Calloc(size_t s, size_t n)
+xcalloc(size_t s, size_t n)
{
void *ptr;
return (ptr);
}
+
+char *
+xstrdup(const char *s)
+{
+ char *n;
+
+ if (s == NULL)
+ s = "";
+ if ((n = strdup(s)) == NULL) {
+ child++;
+ stderror(ERR_NOMEM);
+ }
+ return (n);
+}
-/* $OpenBSD: csh.h,v 1.32 2018/09/18 06:56:09 deraadt Exp $ */
+/* $OpenBSD: csh.h,v 1.33 2018/09/18 17:48:22 millert 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: error.c,v 1.16 2018/09/18 06:56:09 deraadt Exp $ */
+/* $OpenBSD: error.c,v 1.17 2018/09/18 17:48:22 millert 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.30 2018/09/18 06:56:09 deraadt Exp $ */
+/* $OpenBSD: extern.h,v 1.31 2018/09/18 17:48:22 millert 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 *strspl(char *, char *);
void udvar(Char *);
/*
* alloc.c
*/
-void * Malloc(size_t);
-void * Reallocarray(void *, size_t, size_t);
-void * Calloc(size_t, size_t);
+void *xmalloc(size_t);
+void *xreallocarray(void *, size_t, size_t);
+void *xcalloc(size_t, size_t);
+char *xstrdup(const char *);
/*
* str.c:
-/* $OpenBSD: misc.c,v 1.23 2018/09/18 06:56:09 deraadt Exp $ */
+/* $OpenBSD: misc.c,v 1.24 2018/09/18 17:48:22 millert Exp $ */
/* $NetBSD: misc.c,v 1.6 1995/03/21 09:03:09 cgd Exp $ */
/*-
return (0);
}
-char *
-strsave(char *s)
-{
- char *n;
- char *p;
-
- if (s == NULL)
- s = "";
- for (p = s; *p++;)
- continue;
- n = p = xreallocarray(NULL, (p - s), sizeof(char));
- while ((*p++ = *s++) != '\0')
- continue;
- return (n);
-}
-
Char **
blkend(Char **up)
{
-/* $OpenBSD: str.c,v 1.21 2018/09/18 06:56:09 deraadt Exp $ */
+/* $OpenBSD: str.c,v 1.22 2018/09/18 17:48:22 millert 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);
}