Add estrdup(), a checked version of strdup and use it.
This commit is contained in:
parent
22770fe8ea
commit
091b5c0118
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: arch.c,v 1.15 1996/06/02 21:09:33 christos Exp $ */
|
||||
/* $NetBSD: arch.c,v 1.16 1996/08/13 16:42:00 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
||||
@ -42,7 +42,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)arch.c 5.7 (Berkeley) 12/28/90";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: arch.c,v 1.15 1996/06/02 21:09:33 christos Exp $";
|
||||
static char rcsid[] = "$NetBSD: arch.c,v 1.16 1996/08/13 16:42:00 christos Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -546,7 +546,7 @@ ArchStatMember (archive, member, hash)
|
||||
}
|
||||
|
||||
ar = (Arch *)emalloc (sizeof (Arch));
|
||||
ar->name = strdup (archive);
|
||||
ar->name = estrdup (archive);
|
||||
ar->fnametab = NULL;
|
||||
ar->fnamesize = 0;
|
||||
Hash_InitTable (&ar->members, -1);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: dir.c,v 1.10 1996/02/04 22:20:38 christos Exp $ */
|
||||
/* $NetBSD: dir.c,v 1.11 1996/08/13 16:42:02 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
||||
@ -42,7 +42,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)dir.c 5.6 (Berkeley) 12/28/90";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: dir.c,v 1.10 1996/02/04 22:20:38 christos Exp $";
|
||||
static char rcsid[] = "$NetBSD: dir.c,v 1.11 1996/08/13 16:42:02 christos Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -354,7 +354,7 @@ DirMatchFiles (pattern, p, expansions)
|
||||
(pattern[0] == '.')))
|
||||
{
|
||||
(void)Lst_AtEnd(expansions,
|
||||
(isDot ? strdup(entry->name) :
|
||||
(isDot ? estrdup(entry->name) :
|
||||
str_concat(p->name, entry->name,
|
||||
STR_ADDSLASH)));
|
||||
}
|
||||
@ -706,7 +706,7 @@ Dir_FindFile (name, path)
|
||||
}
|
||||
hits += 1;
|
||||
dot->hits += 1;
|
||||
return (strdup (name));
|
||||
return (estrdup (name));
|
||||
}
|
||||
|
||||
if (Lst_Open (path) == FAILURE) {
|
||||
@ -817,7 +817,7 @@ Dir_FindFile (name, path)
|
||||
/*
|
||||
* Checking in dot -- DON'T put a leading ./ on the thing.
|
||||
*/
|
||||
file = strdup(name);
|
||||
file = estrdup(name);
|
||||
checkedDot = TRUE;
|
||||
}
|
||||
if (DEBUG(DIR)) {
|
||||
@ -913,7 +913,7 @@ Dir_FindFile (name, path)
|
||||
}
|
||||
|
||||
if (Hash_FindEntry (&p->files, cp) != (Hash_Entry *)NULL) {
|
||||
return (strdup (name));
|
||||
return (estrdup (name));
|
||||
} else {
|
||||
return ((char *) NULL);
|
||||
}
|
||||
@ -928,7 +928,7 @@ Dir_FindFile (name, path)
|
||||
if (DEBUG(DIR)) {
|
||||
printf("got it (in mtime cache)\n");
|
||||
}
|
||||
return(strdup(name));
|
||||
return(estrdup(name));
|
||||
} else if (stat (name, &stb) == 0) {
|
||||
entry = Hash_CreateEntry(&mtimes, name, (Boolean *)NULL);
|
||||
if (DEBUG(DIR)) {
|
||||
@ -936,7 +936,7 @@ Dir_FindFile (name, path)
|
||||
name);
|
||||
}
|
||||
Hash_SetValue(entry, (long)stb.st_mtime);
|
||||
return (strdup (name));
|
||||
return (estrdup (name));
|
||||
} else {
|
||||
if (DEBUG(DIR)) {
|
||||
printf("failed. Returning NULL\n");
|
||||
@ -979,7 +979,7 @@ Dir_MTime (gn)
|
||||
}
|
||||
|
||||
if (fullName == (char *)NULL) {
|
||||
fullName = strdup(gn->name);
|
||||
fullName = estrdup(gn->name);
|
||||
}
|
||||
|
||||
entry = Hash_FindEntry(&mtimes, fullName);
|
||||
@ -1053,7 +1053,7 @@ Dir_AddDir (path, name)
|
||||
|
||||
if ((d = opendir (name)) != (DIR *) NULL) {
|
||||
p = (Path *) emalloc (sizeof (Path));
|
||||
p->name = strdup (name);
|
||||
p->name = estrdup (name);
|
||||
p->hits = 0;
|
||||
p->refCount = 1;
|
||||
Hash_InitTable (&p->files, -1);
|
||||
@ -1137,7 +1137,7 @@ Dir_MakeFlags (flag, path)
|
||||
LstNode ln; /* the node of the current directory */
|
||||
Path *p; /* the structure describing the current directory */
|
||||
|
||||
str = strdup ("");
|
||||
str = estrdup ("");
|
||||
|
||||
if (Lst_Open (path) == SUCCESS) {
|
||||
while ((ln = Lst_Next (path)) != NILLNODE) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: main.c,v 1.29 1996/05/28 23:34:41 christos Exp $ */
|
||||
/* $NetBSD: main.c,v 1.30 1996/08/13 16:42:08 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
||||
@ -48,7 +48,7 @@ char copyright[] =
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)main.c 5.25 (Berkeley) 4/1/91";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: main.c,v 1.29 1996/05/28 23:34:41 christos Exp $";
|
||||
static char rcsid[] = "$NetBSD: main.c,v 1.30 1996/08/13 16:42:08 christos Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -333,7 +333,7 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != EOF) {
|
||||
optind = 1; /* - */
|
||||
goto rearg;
|
||||
}
|
||||
(void)Lst_AtEnd(create, (ClientData)strdup(*argv));
|
||||
(void)Lst_AtEnd(create, (ClientData)estrdup(*argv));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1124,6 +1124,21 @@ emalloc(len)
|
||||
return(p);
|
||||
}
|
||||
|
||||
/*
|
||||
* emalloc --
|
||||
* strdup, but die on error.
|
||||
*/
|
||||
char *
|
||||
estrdup(str)
|
||||
const char *str;
|
||||
{
|
||||
char *p;
|
||||
|
||||
if ((p = strdup(str)) == NULL)
|
||||
enomem();
|
||||
return(p);
|
||||
}
|
||||
|
||||
/*
|
||||
* erealloc --
|
||||
* realloc, but die on error.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: nonints.h,v 1.10 1996/05/28 23:34:44 christos Exp $ */
|
||||
/* $NetBSD: nonints.h,v 1.11 1996/08/13 16:42:11 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
||||
@ -72,6 +72,7 @@ void Punt __P((char *, ...));
|
||||
void DieHorribly __P((void));
|
||||
int PrintAddr __P((ClientData, ClientData));
|
||||
void Finish __P((int));
|
||||
char *estrdup __P((const char *));
|
||||
void *emalloc __P((size_t));
|
||||
void *erealloc __P((void *, size_t));
|
||||
void enomem __P((void));
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: parse.c,v 1.23 1996/05/28 23:34:46 christos Exp $ */
|
||||
/* $NetBSD: parse.c,v 1.24 1996/08/13 16:42:13 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
||||
@ -42,7 +42,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)parse.c 5.18 (Berkeley) 2/19/91";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: parse.c,v 1.23 1996/05/28 23:34:46 christos Exp $";
|
||||
static char rcsid[] = "$NetBSD: parse.c,v 1.24 1996/08/13 16:42:13 christos Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -539,7 +539,7 @@ ParseDoSrc (tOp, src, allsrc)
|
||||
* invoked if the user didn't specify a target on the command
|
||||
* line. This is to allow #ifmake's to succeed, or something...
|
||||
*/
|
||||
(void) Lst_AtEnd (create, (ClientData)strdup(src));
|
||||
(void) Lst_AtEnd (create, (ClientData)estrdup(src));
|
||||
/*
|
||||
* Add the name to the .TARGETS variable as well, so the user cna
|
||||
* employ that, if desired.
|
||||
@ -1635,7 +1635,7 @@ ParseDoInclude (file)
|
||||
char *prefEnd, *Fname;
|
||||
|
||||
/* Make a temporary copy of this, to be safe. */
|
||||
Fname = strdup(fname);
|
||||
Fname = estrdup(fname);
|
||||
|
||||
prefEnd = strrchr (Fname, '/');
|
||||
if (prefEnd != (char *)NULL) {
|
||||
@ -1643,7 +1643,7 @@ ParseDoInclude (file)
|
||||
|
||||
*prefEnd = '\0';
|
||||
if (file[0] == '/')
|
||||
newName = strdup(file);
|
||||
newName = estrdup(file);
|
||||
else
|
||||
newName = str_concat (Fname, file, STR_ADDSLASH);
|
||||
fullname = Dir_FindFile (newName, parseIncPath);
|
||||
@ -1760,7 +1760,7 @@ Parse_FromString(str)
|
||||
curPTR = (PTR *) emalloc (sizeof (PTR));
|
||||
curPTR->str = curPTR->ptr = str;
|
||||
lineno = 0;
|
||||
fname = strdup(fname);
|
||||
fname = estrdup(fname);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: suff.c,v 1.11 1995/11/02 23:55:08 christos Exp $ */
|
||||
/* $NetBSD: suff.c,v 1.12 1996/08/13 16:42:16 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
||||
@ -42,7 +42,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)suff.c 5.6 (Berkeley) 6/1/90";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: suff.c,v 1.11 1995/11/02 23:55:08 christos Exp $";
|
||||
static char rcsid[] = "$NetBSD: suff.c,v 1.12 1996/08/13 16:42:16 christos Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -802,7 +802,7 @@ Suff_AddSuffix (str)
|
||||
if (ln == NILLNODE) {
|
||||
s = (Suff *) emalloc (sizeof (Suff));
|
||||
|
||||
s->name = strdup (str);
|
||||
s->name = estrdup (str);
|
||||
s->nameLen = strlen (s->name);
|
||||
s->searchPath = Lst_Init (FALSE);
|
||||
s->children = Lst_Init (FALSE);
|
||||
@ -1009,7 +1009,7 @@ SuffAddSrc (sp, lsp)
|
||||
* that...
|
||||
*/
|
||||
s2 = (Src *) emalloc (sizeof (Src));
|
||||
s2->file = strdup(targ->pref);
|
||||
s2->file = estrdup(targ->pref);
|
||||
s2->pref = targ->pref;
|
||||
s2->parent = targ;
|
||||
s2->node = NILGNODE;
|
||||
@ -1272,7 +1272,7 @@ SuffFindCmds (targ, slst)
|
||||
* again (ick)), and return the new structure.
|
||||
*/
|
||||
ret = (Src *)emalloc (sizeof (Src));
|
||||
ret->file = strdup(s->name);
|
||||
ret->file = estrdup(s->name);
|
||||
ret->pref = targ->pref;
|
||||
ret->suff = suff;
|
||||
suff->refCount++;
|
||||
@ -1862,7 +1862,7 @@ SuffFindNormalDeps(gn, slst)
|
||||
* Allocate a Src structure to which things can be transformed
|
||||
*/
|
||||
targ = (Src *)emalloc(sizeof (Src));
|
||||
targ->file = strdup(gn->name);
|
||||
targ->file = estrdup(gn->name);
|
||||
targ->suff = (Suff *)Lst_Datum(ln);
|
||||
targ->suff->refCount++;
|
||||
targ->node = gn;
|
||||
@ -1907,13 +1907,13 @@ SuffFindNormalDeps(gn, slst)
|
||||
}
|
||||
|
||||
targ = (Src *)emalloc(sizeof (Src));
|
||||
targ->file = strdup(gn->name);
|
||||
targ->file = estrdup(gn->name);
|
||||
targ->suff = suffNull;
|
||||
targ->suff->refCount++;
|
||||
targ->node = gn;
|
||||
targ->parent = (Src *)NULL;
|
||||
targ->children = 0;
|
||||
targ->pref = strdup(sopref);
|
||||
targ->pref = estrdup(sopref);
|
||||
#ifdef DEBUG_SRC
|
||||
targ->cp = Lst_Init(FALSE);
|
||||
#endif
|
||||
@ -2052,7 +2052,7 @@ sfnd_abort:
|
||||
gn->suffix->refCount++;
|
||||
if (gn->path != NULL)
|
||||
free(gn->path);
|
||||
gn->path = strdup(gn->name);
|
||||
gn->path = estrdup(gn->name);
|
||||
}
|
||||
|
||||
goto sfnd_return;
|
||||
@ -2153,7 +2153,7 @@ sfnd_abort:
|
||||
*/
|
||||
if (gn->path)
|
||||
free(gn->path);
|
||||
gn->path = strdup(gn->name);
|
||||
gn->path = estrdup(gn->name);
|
||||
|
||||
/*
|
||||
* Nuke the transformation path and the Src structures left over in the
|
||||
@ -2334,7 +2334,7 @@ Suff_Init ()
|
||||
*/
|
||||
emptySuff = suffNull = (Suff *) emalloc (sizeof (Suff));
|
||||
|
||||
suffNull->name = strdup ("");
|
||||
suffNull->name = estrdup ("");
|
||||
suffNull->nameLen = 0;
|
||||
suffNull->searchPath = Lst_Init (FALSE);
|
||||
Dir_Concat(suffNull->searchPath, dirSearchPath);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: targ.c,v 1.7 1996/04/08 18:57:49 jtc Exp $ */
|
||||
/* $NetBSD: targ.c,v 1.8 1996/08/13 16:42:21 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
||||
@ -40,7 +40,7 @@
|
||||
|
||||
#ifndef lint
|
||||
/* from: static char sccsid[] = "@(#)targ.c 5.9 (Berkeley) 3/1/91"; */
|
||||
static char *rcsid = "$Id: targ.c,v 1.7 1996/04/08 18:57:49 jtc Exp $";
|
||||
static char *rcsid = "$Id: targ.c,v 1.8 1996/08/13 16:42:21 christos Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*-
|
||||
@ -161,7 +161,7 @@ Targ_NewGN (name)
|
||||
register GNode *gn;
|
||||
|
||||
gn = (GNode *) emalloc (sizeof (GNode));
|
||||
gn->name = strdup (name);
|
||||
gn->name = estrdup (name);
|
||||
gn->path = (char *) 0;
|
||||
if (name[0] == '-' && name[1] == 'l') {
|
||||
gn->type = OP_LIB;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: var.c,v 1.13 1996/05/28 23:34:49 christos Exp $ */
|
||||
/* $NetBSD: var.c,v 1.14 1996/08/13 16:42:25 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
||||
@ -42,7 +42,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)var.c 5.7 (Berkeley) 6/1/90";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: var.c,v 1.13 1996/05/28 23:34:49 christos Exp $";
|
||||
static char rcsid[] = "$NetBSD: var.c,v 1.14 1996/08/13 16:42:25 christos Exp $";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -281,7 +281,7 @@ VarFind (name, ctxt, flags)
|
||||
int len;
|
||||
|
||||
v = (Var *) emalloc(sizeof(Var));
|
||||
v->name = strdup(name);
|
||||
v->name = estrdup(name);
|
||||
|
||||
len = strlen(env);
|
||||
|
||||
@ -334,7 +334,7 @@ VarAdd (name, val, ctxt)
|
||||
|
||||
v = (Var *) emalloc (sizeof (Var));
|
||||
|
||||
v->name = strdup (name);
|
||||
v->name = estrdup (name);
|
||||
|
||||
len = val ? strlen(val) : 0;
|
||||
v->val = Buf_Init(len+1);
|
||||
|
Loading…
Reference in New Issue
Block a user