Remove the local basename in favor of the libc version.

Remove xmalloc and xstrdup and do the error checking at the place of use.
This commit is contained in:
David E. O'Brien 2001-07-24 14:09:47 +00:00
parent 707cb19845
commit de9b3b9034
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=80289
5 changed files with 22 additions and 43 deletions

View File

@ -86,6 +86,7 @@ register int td;
{
register int c, n;
static int sysval = 0;
char *p;
#ifdef DEBUG
printf("argc = %d\n", argc);
@ -352,7 +353,9 @@ register int td;
* dom4wrap - set up for
* wrap-up/wind-down activity
*/
m4wraps = (argc > 2) ? xstrdup(argv[2]) : null;
if ((p = strdup(argv[2])) == NULL)
err(1, "strdup");
m4wraps = (argc > 2) ? p : null;
break;
case EXITTYPE:
@ -472,7 +475,8 @@ register char *defn;
if (!*defn)
p->defn = null;
else
p->defn = xstrdup(defn);
if ((p->defn = strdup(defn)) == NULL)
err(1, "strdup");
p->type = MACRTYPE;
}
@ -515,7 +519,8 @@ register char *defn;
if (!*defn)
p->defn = null;
else
p->defn = xstrdup(defn);
if ((p->defn = strdup(defn)) == NULL)
err(1, "strdup");
p->type = MACRTYPE;
}

View File

@ -37,8 +37,6 @@
* $FreeBSD$
*/
char *basename __P((char *));
char *xalloc __P((unsigned long));
int expr __P((char *));
ndptr addent __P((char *));
void chrsave __P((int));
@ -58,7 +56,6 @@ void doundiv __P((char *[], int));
void eval __P((char *[], int, int));
void expand __P((char *[], int));
void getdiv __P((int));
char *xstrdup __P((const char *));
int hash __P((char *));
int indx __P((char *, char *));
void killdiv __P((void));

View File

@ -36,6 +36,8 @@
#ifndef lint
static char sccsid[] = "@(#)look.c 8.1 (Berkeley) 6/6/93";
static char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
/*
@ -45,6 +47,7 @@ static char sccsid[] = "@(#)look.c 8.1 (Berkeley) 6/6/93";
*/
#include <sys/types.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -89,10 +92,12 @@ char *name;
ndptr p;
h = hash(name);
p = (ndptr) xalloc(sizeof(struct ndblock));
if ((p = malloc(sizeof(struct ndblock))) == NULL)
err(1, "malloc");
p->nxtptr = hashtab[h];
hashtab[h] = p;
p->name = xstrdup(name);
if ((p->name = strdup(name)) == NULL)
err(1, "strdup");
return p;
}

View File

@ -59,6 +59,7 @@ static const char rcsid[] =
#include <err.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "mdef.h"
@ -181,8 +182,11 @@ main(argc,argv)
argv += optind;
active = stdout; /* default active output */
if ((p = strdup(_PATH_DIVDIRNAME)) == NULL)
err(1, "strdup");
/* filename for diversions */
m4dir = mkdtemp(xstrdup(_PATH_DIVDIRNAME));
m4dir = mkdtemp(p);
err_set_exit(cleanup);
(void) asprintf(&m4temp, "%s/%s", m4dir, _PATH_DIVNAME);
@ -406,7 +410,8 @@ initkwds() {
for (i = 0; i < MAXKEYS; i++) {
h = hash(keywrds[i].knam);
p = (ndptr) xalloc(sizeof(struct ndblock));
if ((p = malloc(sizeof(struct ndblock))) == NULL)
err(1, "malloc");
p->nxtptr = hashtab[h];
hashtab[h] = p;
p->name = keywrds[i].knam;

View File

@ -203,39 +203,6 @@ killdiv()
}
}
char *
xalloc(n)
unsigned long n;
{
register char *p = malloc(n);
if (p == NULL)
err(1, "malloc");
return p;
}
char *
xstrdup(s)
const char *s;
{
register char *p = strdup(s);
if (p == NULL)
err(1, "strdup");
return p;
}
char *
basename(s)
register char *s;
{
register char *p;
if ((p = strrchr(s, '/')) == NULL)
return s;
return ++p;
}
void
cleanup(n)
int n;