Don't use emalloc and friends directly, but call them consistently

bmake_malloc and friends. Implement them via macros for the native case
and provide fallback implementations otherwise. Avoid polluting the
namespace by not defining enomem globally. Don't bother to provide
strdup and strndup, they were only used for the estrdup and estrndup
comapt code.

This addresses the presence of emalloc in system libraries on A/UX and
resulted strange issues as reported by Timothy E. Larson.
This commit is contained in:
joerg 2008-10-06 22:09:21 +00:00
parent 23970ca9fd
commit bd681a4d7e
16 changed files with 183 additions and 220 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.43 2008/02/14 22:11:20 christos Exp $
# $NetBSD: Makefile,v 1.44 2008/10/06 22:09:21 joerg Exp $
# @(#)Makefile 5.2 (Berkeley) 12/28/90
PROG= make
@ -34,7 +34,7 @@ COPTS.var.c+= -Wno-cast-qual
.ifdef TOOLDIR
# this is a native netbsd build,
# use libutil rather than the local emalloc etc.
CPPFLAGS+= -DHAVE_EMALLOC
CPPFLAGS+= -DUSE_EMALLOC
LDADD+=-lutil
DPADD+=${LIBUTIL}
.endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: arch.c,v 1.55 2008/02/15 21:29:50 christos Exp $ */
/* $NetBSD: arch.c,v 1.56 2008/10/06 22:09:21 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: arch.c,v 1.55 2008/02/15 21:29:50 christos Exp $";
static char rcsid[] = "$NetBSD: arch.c,v 1.56 2008/10/06 22:09:21 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)arch.c 8.2 (Berkeley) 1/2/94";
#else
__RCSID("$NetBSD: arch.c,v 1.55 2008/02/15 21:29:50 christos Exp $");
__RCSID("$NetBSD: arch.c,v 1.56 2008/10/06 22:09:21 joerg Exp $");
#endif
#endif /* not lint */
#endif
@ -363,7 +363,7 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt)
* are just placed at the end of the nodeLst we're returning.
*/
sz = strlen(memName)+strlen(libName)+3;
buf = sacrifice = emalloc(sz);
buf = sacrifice = bmake_malloc(sz);
snprintf(buf, sz, "%s(%s)", libName, memName);
@ -398,14 +398,14 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt)
Lst members = Lst_Init(FALSE);
char *member;
size_t sz = MAXPATHLEN, nsz;
nameBuf = emalloc(sz);
nameBuf = bmake_malloc(sz);
Dir_Expand(memName, dirSearchPath, members);
while (!Lst_IsEmpty(members)) {
member = (char *)Lst_DeQueue(members);
nsz = strlen(libName) + strlen(member) + 3;
if (sz > nsz)
nameBuf = erealloc(nameBuf, sz = nsz * 2);
nameBuf = bmake_realloc(nameBuf, sz = nsz * 2);
snprintf(nameBuf, sz, "%s(%s)", libName, member);
free(member);
@ -429,7 +429,7 @@ Arch_ParseArchive(char **linePtr, Lst nodeLst, GNode *ctxt)
free(nameBuf);
} else {
size_t sz = strlen(libName) + strlen(memName) + 3;
nameBuf = emalloc(sz);
nameBuf = bmake_malloc(sz);
snprintf(nameBuf, sz, "%s(%s)", libName, memName);
gn = Targ_FindNode(nameBuf, TARG_CREATE);
free(nameBuf);
@ -610,8 +610,8 @@ ArchStatMember(char *archive, char *member, Boolean hash)
return (NULL);
}
ar = emalloc(sizeof(Arch));
ar->name = estrdup(archive);
ar = bmake_malloc(sizeof(Arch));
ar->name = bmake_strdup(archive);
ar->fnametab = NULL;
ar->fnamesize = 0;
Hash_InitTable(&ar->members, -1);
@ -686,7 +686,7 @@ ArchStatMember(char *archive, char *member, Boolean hash)
#endif
he = Hash_CreateEntry(&ar->members, memName, NULL);
Hash_SetValue(he, emalloc(sizeof(struct ar_hdr)));
Hash_SetValue(he, bmake_malloc(sizeof(struct ar_hdr)));
memcpy(Hash_GetValue(he), &arh, sizeof(struct ar_hdr));
}
fseek(arch, (size + 1) & ~1, SEEK_CUR);
@ -760,7 +760,7 @@ ArchSVR4Entry(Arch *ar, char *name, size_t size, FILE *arch)
* This is a table of archive names, so we build one for
* ourselves
*/
ar->fnametab = emalloc(size);
ar->fnametab = bmake_malloc(size);
ar->fnamesize = size;
if (fread(ar->fnametab, size, 1, arch) != 1) {
@ -1183,7 +1183,7 @@ Arch_FindLib(GNode *gn, Lst path)
char *libName; /* file name for archive */
size_t sz = strlen(gn->name) + 6 - 2;
libName = emalloc(sz);
libName = bmake_malloc(sz);
snprintf(libName, sz, "lib%s.a", &gn->name[2]);
gn->path = Dir_FindFile(libName, path);

View File

@ -1,4 +1,4 @@
/* $NetBSD: buf.c,v 1.21 2008/02/15 21:29:50 christos Exp $ */
/* $NetBSD: buf.c,v 1.22 2008/10/06 22:09:21 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -70,14 +70,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: buf.c,v 1.21 2008/02/15 21:29:50 christos Exp $";
static char rcsid[] = "$NetBSD: buf.c,v 1.22 2008/10/06 22:09:21 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)buf.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: buf.c,v 1.21 2008/02/15 21:29:50 christos Exp $");
__RCSID("$NetBSD: buf.c,v 1.22 2008/10/06 22:09:21 joerg Exp $");
#endif
#endif /* not lint */
#endif
@ -105,7 +105,7 @@ __RCSID("$NetBSD: buf.c,v 1.21 2008/02/15 21:29:50 christos Exp $");
#define BufExpand(bp,nb) \
while (bp->left < (nb)+1) {\
int newSize = (bp)->size * 2; \
Byte *newBuf = (Byte *)erealloc((bp)->buffer, newSize); \
Byte *newBuf = (Byte *)bmake_realloc((bp)->buffer, newSize); \
\
(bp)->inPtr = newBuf + ((bp)->inPtr - (bp)->buffer); \
(bp)->outPtr = newBuf + ((bp)->outPtr - (bp)->buffer);\
@ -267,13 +267,13 @@ Buf_Init(int size)
{
Buffer bp; /* New Buffer */
bp = emalloc(sizeof(*bp));
bp = bmake_malloc(sizeof(*bp));
if (size <= 0) {
size = BUF_DEF_SIZE;
}
bp->left = bp->size = size;
bp->buffer = emalloc(size);
bp->buffer = bmake_malloc(size);
bp->inPtr = bp->outPtr = bp->buffer;
*bp->inPtr = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: dir.c,v 1.55 2008/02/15 21:29:50 christos Exp $ */
/* $NetBSD: dir.c,v 1.56 2008/10/06 22:09:21 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -70,14 +70,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: dir.c,v 1.55 2008/02/15 21:29:50 christos Exp $";
static char rcsid[] = "$NetBSD: dir.c,v 1.56 2008/10/06 22:09:21 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)dir.c 8.2 (Berkeley) 1/2/94";
#else
__RCSID("$NetBSD: dir.c,v 1.55 2008/02/15 21:29:50 christos Exp $");
__RCSID("$NetBSD: dir.c,v 1.56 2008/10/06 22:09:21 joerg Exp $");
#endif
#endif /* not lint */
#endif
@ -276,10 +276,10 @@ Dir_Init(const char *cdname)
Dir_InitCur(cdname);
dotLast = emalloc(sizeof(Path));
dotLast = bmake_malloc(sizeof(Path));
dotLast->refCount = 1;
dotLast->hits = 0;
dotLast->name = estrdup(".DOTLAST");
dotLast->name = bmake_strdup(".DOTLAST");
Hash_InitTable(&dotLast->files, -1);
}
@ -552,7 +552,7 @@ DirMatchFiles(const char *pattern, Path *p, Lst expansions)
(pattern[0] == '.')))
{
(void)Lst_AtEnd(expansions,
(isDot ? estrdup(entry->name) :
(isDot ? bmake_strdup(entry->name) :
str_concat(p->name, entry->name,
STR_ADDSLASH)));
}
@ -635,7 +635,7 @@ DirExpandCurly(const char *word, const char *brace, Lst path, Lst expansions)
/*
* Allocate room for the combination and install the three pieces.
*/
file = emalloc(otherLen + cp - start + 1);
file = bmake_malloc(otherLen + cp - start + 1);
if (brace != word) {
strncpy(file, word, brace-word);
}
@ -909,7 +909,7 @@ DirLookupSubdir(Path *p, const char *name)
/*
* Checking in dot -- DON'T put a leading ./ on the thing.
*/
file = estrdup(name);
file = bmake_strdup(name);
}
if (DEBUG(DIR)) {
@ -977,7 +977,7 @@ DirLookupAbs(Path *p, const char *name, const char *cp)
fprintf(debug_file, " must be here but isn't -- returning\n");
}
/* Return empty string: terminates search */
return estrdup("");
return bmake_strdup("");
}
p->hits += 1;
@ -985,7 +985,7 @@ DirLookupAbs(Path *p, const char *name, const char *cp)
if (DEBUG(DIR)) {
fprintf(debug_file, " returning %s\n", name);
}
return (estrdup(name));
return (bmake_strdup(name));
}
/*-
@ -1011,7 +1011,7 @@ DirFindDot(Boolean hasSlash __unused, const char *name, const char *cp)
}
hits += 1;
dot->hits += 1;
return (estrdup(name));
return (bmake_strdup(name));
}
if (cur &&
Hash_FindEntry(&cur->files, cp) != NULL) {
@ -1283,7 +1283,7 @@ Dir_FindFile(const char *name, Lst path)
}
if (Hash_FindEntry(&p->files, cp) != NULL) {
return (estrdup(name));
return (bmake_strdup(name));
} else {
return (NULL);
}
@ -1298,7 +1298,7 @@ Dir_FindFile(const char *name, Lst path)
if (DEBUG(DIR)) {
fprintf(debug_file, " got it (in mtime cache)\n");
}
return(estrdup(name));
return(bmake_strdup(name));
} else if (stat(name, &stb) == 0) {
entry = Hash_CreateEntry(&mtimes, name, NULL);
if (DEBUG(DIR)) {
@ -1306,7 +1306,7 @@ Dir_FindFile(const char *name, Lst path)
name);
}
Hash_SetValue(entry, (long)stb.st_mtime);
return (estrdup(name));
return (bmake_strdup(name));
} else {
if (DEBUG(DIR)) {
fprintf(debug_file, " failed. Returning NULL\n");
@ -1439,7 +1439,7 @@ Dir_MTime(GNode *gn)
}
if (fullName == NULL) {
fullName = estrdup(gn->name);
fullName = bmake_strdup(gn->name);
}
entry = Hash_FindEntry(&mtimes, fullName);
@ -1524,8 +1524,8 @@ Dir_AddDir(Lst path, const char *name)
}
if ((d = opendir(name)) != NULL) {
p = emalloc(sizeof(Path));
p->name = estrdup(name);
p = bmake_malloc(sizeof(Path));
p->name = bmake_strdup(name);
p->hits = 0;
p->refCount = 1;
Hash_InitTable(&p->files, -1);
@ -1606,7 +1606,7 @@ Dir_MakeFlags(const char *flag, Lst path)
LstNode ln; /* the node of the current directory */
Path *p; /* the structure describing the current directory */
str = estrdup("");
str = bmake_strdup("");
if (Lst_Open(path) == SUCCESS) {
while ((ln = Lst_Next(path)) != NILLNODE) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: for.c,v 1.29 2008/05/26 14:29:55 christos Exp $ */
/* $NetBSD: for.c,v 1.30 2008/10/06 22:09:21 joerg Exp $ */
/*
* Copyright (c) 1992, The Regents of the University of California.
@ -30,14 +30,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: for.c,v 1.29 2008/05/26 14:29:55 christos Exp $";
static char rcsid[] = "$NetBSD: for.c,v 1.30 2008/10/06 22:09:21 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)for.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: for.c,v 1.29 2008/05/26 14:29:55 christos Exp $");
__RCSID("$NetBSD: for.c,v 1.30 2008/10/06 22:09:21 joerg Exp $");
#endif
#endif /* not lint */
#endif
@ -116,7 +116,7 @@ ForAddVar(const char *data, size_t len)
Buf_AddBytes(buf, len, (Byte *)UNCONST(data));
accumFor.nvars++;
accumFor.vars = erealloc(accumFor.vars, accumFor.nvars*sizeof(char *));
accumFor.vars = bmake_realloc(accumFor.vars, accumFor.nvars*sizeof(char *));
accumFor.vars[accumFor.nvars-1] = (char *)Buf_GetAll(buf, &varlen);
@ -324,7 +324,7 @@ For_Run(int lineno)
if (Lst_Open(arg.lst) != SUCCESS)
return;
values = emalloc(arg.nvars * sizeof(char *));
values = bmake_malloc(arg.nvars * sizeof(char *));
while (!done) {
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: hash.c,v 1.16 2005/08/04 00:20:12 christos Exp $ */
/* $NetBSD: hash.c,v 1.17 2008/10/06 22:09:21 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -70,14 +70,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: hash.c,v 1.16 2005/08/04 00:20:12 christos Exp $";
static char rcsid[] = "$NetBSD: hash.c,v 1.17 2008/10/06 22:09:21 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)hash.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: hash.c,v 1.16 2005/08/04 00:20:12 christos Exp $");
__RCSID("$NetBSD: hash.c,v 1.17 2008/10/06 22:09:21 joerg Exp $");
#endif
#endif /* not lint */
#endif
@ -148,7 +148,7 @@ Hash_InitTable(Hash_Table *t, int numBuckets)
t->numEntries = 0;
t->size = i;
t->mask = i - 1;
t->bucketPtr = hp = emalloc(sizeof(*hp) * i);
t->bucketPtr = hp = bmake_malloc(sizeof(*hp) * i);
while (--i >= 0)
*hp++ = NULL;
}
@ -287,7 +287,7 @@ Hash_CreateEntry(Hash_Table *t, const char *key, Boolean *newPtr)
*/
if (t->numEntries >= rebuildLimit * t->size)
RebuildTable(t);
e = emalloc(sizeof(*e) + keylen);
e = bmake_malloc(sizeof(*e) + keylen);
hp = &t->bucketPtr[h & t->mask];
e->next = *hp;
*hp = e;
@ -448,7 +448,7 @@ RebuildTable(Hash_Table *t)
i <<= 1;
t->size = i;
t->mask = mask = i - 1;
t->bucketPtr = hp = emalloc(sizeof(*hp) * i);
t->bucketPtr = hp = bmake_malloc(sizeof(*hp) * i);
while (--i >= 0)
*hp++ = NULL;
for (hp = oldhp, i = oldsize; --i >= 0;) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: job.c,v 1.139 2008/02/15 21:29:50 christos Exp $ */
/* $NetBSD: job.c,v 1.140 2008/10/06 22:09:21 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@ -70,14 +70,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: job.c,v 1.139 2008/02/15 21:29:50 christos Exp $";
static char rcsid[] = "$NetBSD: job.c,v 1.140 2008/10/06 22:09:21 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: job.c,v 1.139 2008/02/15 21:29:50 christos Exp $");
__RCSID("$NetBSD: job.c,v 1.140 2008/10/06 22:09:21 joerg Exp $");
#endif
#endif /* not lint */
#endif
@ -740,7 +740,7 @@ JobPrintCommand(ClientData cmdp, ClientData jobp)
if (!commandShell->hasErrCtl) {
/* Worst that could happen is every char needs escaping. */
escCmd = emalloc((strlen(cmd) * 2) + 1);
escCmd = bmake_malloc((strlen(cmd) * 2) + 1);
for (i = 0, j= 0; cmd[i] != '\0'; i++, j++) {
if (cmd[i] == '$' || cmd[i] == '`' || cmd[i] == '\\' ||
cmd[i] == '"')
@ -2118,7 +2118,7 @@ Job_Init(void)
GNode *begin; /* node for commands to do at the very start */
/* Allocate space for all the job info */
job_table = emalloc(maxJobs * sizeof *job_table);
job_table = bmake_malloc(maxJobs * sizeof *job_table);
memset(job_table, 0, maxJobs * sizeof *job_table);
job_table_end = job_table + maxJobs;
wantToken = 0;
@ -2160,8 +2160,8 @@ Job_Init(void)
JobCreatePipe(&childExitJob, 3);
/* We can only need to wait for tokens, children and output from each job */
fds = emalloc(sizeof (*fds) * (2 + maxJobs));
jobfds = emalloc(sizeof (*jobfds) * (2 + maxJobs));
fds = bmake_malloc(sizeof (*fds) * (2 + maxJobs));
jobfds = bmake_malloc(sizeof (*jobfds) * (2 + maxJobs));
/* These are permanent entries and take slots 0 and 1 */
watchfd(&tokenWaitJob);
@ -2423,7 +2423,7 @@ Job_ParseShell(char *line)
}
commandShell = sh;
} else {
commandShell = emalloc(sizeof(Shell));
commandShell = bmake_malloc(sizeof(Shell));
*commandShell = newShell;
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: lstInt.h,v 1.15 2008/02/05 16:39:26 joerg Exp $ */
/* $NetBSD: lstInt.h,v 1.16 2008/10/06 22:09:21 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -86,7 +86,7 @@ typedef struct List {
* PAlloc (var, ptype) --
* Allocate a pointer-typedef structure 'ptype' into the variable 'var'
*/
#define PAlloc(var,ptype) var = (ptype) emalloc(sizeof *(var))
#define PAlloc(var,ptype) var = (ptype) bmake_malloc(sizeof *(var))
/*
* LstValid (l) --

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.150 2008/07/21 14:19:24 lukem Exp $ */
/* $NetBSD: main.c,v 1.151 2008/10/06 22:09:21 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,7 +69,7 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: main.c,v 1.150 2008/07/21 14:19:24 lukem Exp $";
static char rcsid[] = "$NetBSD: main.c,v 1.151 2008/10/06 22:09:21 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\
#if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: main.c,v 1.150 2008/07/21 14:19:24 lukem Exp $");
__RCSID("$NetBSD: main.c,v 1.151 2008/10/06 22:09:21 joerg Exp $");
#endif
#endif /* not lint */
#endif
@ -423,7 +423,7 @@ rearg:
break;
case 'T':
if (argvalue == NULL) goto noarg;
tracefile = estrdup(argvalue);
tracefile = bmake_strdup(argvalue);
Var_Append(MAKEFLAGS, "-T", VAR_GLOBAL);
Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
break;
@ -543,7 +543,7 @@ rearg:
Punt("illegal (null) argument.");
if (*argv[1] == '-' && !dashDash)
goto rearg;
(void)Lst_AtEnd(create, estrdup(argv[1]));
(void)Lst_AtEnd(create, bmake_strdup(argv[1]));
}
return;
@ -588,7 +588,7 @@ Main_ParseArgLine(char *line)
if (!*line)
return;
buf = emalloc(len = strlen(line) + strlen(argv0) + 2);
buf = bmake_malloc(len = strlen(line) + strlen(argv0) + 2);
(void)snprintf(buf, len, "%s %s", argv0, line);
if (p1)
free(p1);
@ -943,7 +943,7 @@ main(int argc, char **argv)
if (syspath == NULL || *syspath == '\0')
syspath = defsyspath;
else
syspath = estrdup(syspath);
syspath = bmake_strdup(syspath);
for (start = syspath; *start != '\0'; start = cp) {
for (cp = start; *cp != '\0' && *cp != ':'; cp++)
@ -1159,7 +1159,7 @@ ReadMakefile(ClientData p, ClientData q __unused)
char *fname = p; /* makefile to read */
int fd;
size_t len = MAXPATHLEN;
char *name, *path = emalloc(len);
char *name, *path = bmake_malloc(len);
int setMAKEFILE;
if (!strcmp(fname, "-")) {
@ -1172,7 +1172,7 @@ ReadMakefile(ClientData p, ClientData q __unused)
if (strcmp(curdir, objdir) && *fname != '/') {
size_t plen = strlen(curdir) + strlen(fname) + 2;
if (len < plen)
path = erealloc(path, len = 2 * plen);
path = bmake_realloc(path, len = 2 * plen);
(void)snprintf(path, len, "%s/%s", curdir, fname);
fd = open(path, O_RDONLY);
@ -1184,7 +1184,7 @@ ReadMakefile(ClientData p, ClientData q __unused)
/* If curdir failed, try objdir (ala .depend) */
plen = strlen(objdir) + strlen(fname) + 2;
if (len < plen)
path = erealloc(path, len = 2 * plen);
path = bmake_realloc(path, len = 2 * plen);
(void)snprintf(path, len, "%s/%s", objdir, fname);
fd = open(path, O_RDONLY);
if (fd != -1) {
@ -1535,7 +1535,7 @@ Cmd_Exec(const char *cmd, const char **errnum)
}
return res;
bad:
res = emalloc(1);
res = bmake_malloc(1);
*res = '\0';
return res;
}
@ -1666,13 +1666,24 @@ Finish(int errors)
Fatal("%d error%s", errors, errors == 1 ? "" : "s");
}
#ifndef HAVE_EMALLOC
#ifndef USE_EMALLOC
/*
* emalloc --
* enomem --
* die when out of memory.
*/
static void
enomem(void)
{
(void)fprintf(stderr, "%s: %s.\n", progname, strerror(errno));
exit(2);
}
/*
* bmake_malloc --
* malloc, but die on error.
*/
void *
emalloc(size_t len)
bmake_malloc(size_t len)
{
void *p;
@ -1682,55 +1693,55 @@ emalloc(size_t len)
}
/*
* estrdup --
* bmake_strdup --
* strdup, but die on error.
*/
char *
estrdup(const char *str)
bmake_strdup(const char *str)
{
size_t len;
char *p;
if ((p = strdup(str)) == NULL)
len = strlen(str) + 1;
if ((p = malloc(len)) == NULL)
enomem();
return(p);
return memcpy(p, str, len);
}
/*
* estrndup --
* bmake_strndup --
* strndup, but die on error.
*/
char *
estrndup(const char *str, size_t len)
bmake_strndup(const char *str, size_t max_len)
{
size_t len;
char *p;
if ((p = strndup(str, len)) == NULL)
enomem();
if (str == NULL)
return NULL;
len = strlen(str);
if (len > max_len)
len = max_len;
p = bmake_malloc(len + 1);
memcpy(p, str, len);
p[len] = '\0';
return(p);
}
/*
* erealloc --
* bmake_realloc --
* realloc, but die on error.
*/
void *
erealloc(void *ptr, size_t size)
bmake_realloc(void *ptr, size_t size)
{
if ((ptr = realloc(ptr, size)) == NULL)
enomem();
return(ptr);
}
/*
* enomem --
* die when out of memory.
*/
void
enomem(void)
{
(void)fprintf(stderr, "%s: %s.\n", progname, strerror(errno));
exit(2);
}
#endif
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: nonints.h,v 1.48 2008/02/15 21:29:50 christos Exp $ */
/* $NetBSD: nonints.h,v 1.49 2008/10/06 22:09:21 joerg Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
@ -116,15 +116,17 @@ void Punt(const char *, ...)
void DieHorribly(void) __attribute__((__noreturn__));
int PrintAddr(ClientData, ClientData);
void Finish(int);
#ifndef HAVE_EMALLOC
char *estrdup(const char *);
char *strndup(const char *, size_t);
char *estrndup(const char *, size_t);
void *emalloc(size_t);
void *erealloc(void *, size_t);
void enomem(void);
#ifndef USE_EMALLOC
void *bmake_malloc(size_t);
void *bmake_realloc(void *, size_t);
char *bmake_strdup(const char *);
char *bmake_strndup(const char *, size_t);
#else
#include <util.h>
#define bmake_malloc(x) emalloc(x)
#define bmake_realloc(x,y) erealloc(x,y)
#define bmake_strdup(x) estrdup(x)
#define bmake_strndup(x,y) estrndup(x,y)
#endif
int eunlink(const char *);
void execError(const char *, const char *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: parse.c,v 1.146 2008/06/03 13:02:28 christos Exp $ */
/* $NetBSD: parse.c,v 1.147 2008/10/06 22:09:21 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: parse.c,v 1.146 2008/06/03 13:02:28 christos Exp $";
static char rcsid[] = "$NetBSD: parse.c,v 1.147 2008/10/06 22:09:21 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: parse.c,v 1.146 2008/06/03 13:02:28 christos Exp $");
__RCSID("$NetBSD: parse.c,v 1.147 2008/10/06 22:09:21 joerg Exp $");
#endif
#endif /* not lint */
#endif
@ -667,7 +667,7 @@ ParseDoSrc(int tOp, const char *src)
* 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, estrdup(src));
(void)Lst_AtEnd(create, bmake_strdup(src));
/*
* Add the name to the .TARGETS variable as well, so the user can
* employ that, if desired.
@ -1755,7 +1755,7 @@ Parse_include_file(char *file, Boolean isSystem, int silent)
* find the durn thing. A return of NULL indicates the file don't
* exist.
*/
fullname = file[0] == '/' ? estrdup(file) : NULL;
fullname = file[0] == '/' ? bmake_strdup(file) : NULL;
if (fullname == NULL && !isSystem) {
/*
@ -1766,7 +1766,7 @@ Parse_include_file(char *file, Boolean isSystem, int silent)
* we can locate the beast.
*/
incdir = estrdup(curFile->fname);
incdir = bmake_strdup(curFile->fname);
prefEnd = strrchr(incdir, '/');
if (prefEnd != NULL) {
*prefEnd = '\0';
@ -1917,7 +1917,7 @@ ParseSetParseFile(const char *filename)
Var_Set(".PARSEFILE", filename, VAR_GLOBAL, 0);
} else {
len = slash - filename;
dirname = emalloc(len + 1);
dirname = bmake_malloc(len + 1);
memcpy(dirname, filename, len);
dirname[len] = 0;
Var_Set(".PARSEDIR", dirname, VAR_GLOBAL, 0);
@ -1992,7 +1992,7 @@ Parse_SetInput(const char *name, int line, int fd, char *buf)
Lst_AtFront(includes, curFile);
/* Allocate and fill in new structure */
curFile = emalloc(sizeof *curFile);
curFile = bmake_malloc(sizeof *curFile);
/*
* Once the previous state has been saved, we can get down to reading
@ -2012,7 +2012,7 @@ Parse_SetInput(const char *name, int line, int fd, char *buf)
* Allocate a 32k data buffer (as stdio seems to).
* Set pointers so that first ParseReadc has to do a file read.
*/
buf = emalloc(IFILE_BUFLEN);
buf = bmake_malloc(IFILE_BUFLEN);
buf[0] = 0;
curFile->P_str = buf;
curFile->P_ptr = buf;
@ -2192,7 +2192,7 @@ ParseGetLine(int flags, int *length)
len = cf->P_str + cf->P_buflen - tp - 32;
if (len <= 0) {
/* We need a bigger buffer to hold this line */
tp = erealloc(cf->P_str, cf->P_buflen + IFILE_BUFLEN);
tp = bmake_realloc(cf->P_str, cf->P_buflen + IFILE_BUFLEN);
cf->P_ptr = cf->P_ptr - cf->P_str + tp;
cf->P_end = cf->P_end - cf->P_str + tp;
ptr = ptr - cf->P_str + tp;
@ -2512,7 +2512,7 @@ Parse_File(const char *name, int fd)
* commands of all targets in the dependency spec
*/
if (targets) {
cp = estrdup(cp);
cp = bmake_strdup(cp);
Lst_ForEach(targets, ParseAddCmd, cp);
#ifdef CLEANUP
Lst_AtEnd(targCmds, cp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: str.c,v 1.28 2008/02/15 21:29:50 christos Exp $ */
/* $NetBSD: str.c,v 1.29 2008/10/06 22:09:21 joerg Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: str.c,v 1.28 2008/02/15 21:29:50 christos Exp $";
static char rcsid[] = "$NetBSD: str.c,v 1.29 2008/10/06 22:09:21 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)str.c 5.8 (Berkeley) 6/1/90";
#else
__RCSID("$NetBSD: str.c,v 1.28 2008/02/15 21:29:50 christos Exp $");
__RCSID("$NetBSD: str.c,v 1.29 2008/10/06 22:09:21 joerg Exp $");
#endif
#endif /* not lint */
#endif
@ -102,7 +102,7 @@ str_concat(const char *s1, const char *s2, int flags)
len2 = strlen(s2);
/* allocate length plus separator plus EOS */
result = emalloc((u_int)(len1 + len2 + 2));
result = bmake_malloc((u_int)(len1 + len2 + 2));
/* copy first string into place */
memcpy(result, s1, len1);
@ -145,7 +145,7 @@ brk_string(const char *str, int *store_argc, Boolean expand, char **buffer)
const char *p;
int len;
int argmax = 50, curlen = 0;
char **argv = emalloc((argmax + 1) * sizeof(char *));
char **argv = bmake_malloc((argmax + 1) * sizeof(char *));
/* skip leading space chars. */
for (; *str == ' ' || *str == '\t'; ++str)
@ -153,7 +153,7 @@ brk_string(const char *str, int *store_argc, Boolean expand, char **buffer)
/* allocate room for a copy of the string */
if ((len = strlen(str) + 1) > curlen)
*buffer = emalloc(curlen = len);
*buffer = bmake_malloc(curlen = len);
/*
* copy the string; at the same time, parse backslashes,
@ -206,7 +206,7 @@ brk_string(const char *str, int *store_argc, Boolean expand, char **buffer)
*t++ = '\0';
if (argc == argmax) {
argmax *= 2; /* ramp up fast */
argv = (char **)erealloc(argv,
argv = (char **)bmake_realloc(argv,
(argmax + 1) * sizeof(char *));
}
argv[argc++] = start;

View File

@ -1,4 +1,4 @@
/* $NetBSD: suff.c,v 1.63 2008/02/15 21:29:50 christos Exp $ */
/* $NetBSD: suff.c,v 1.64 2008/10/06 22:09:21 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: suff.c,v 1.63 2008/02/15 21:29:50 christos Exp $";
static char rcsid[] = "$NetBSD: suff.c,v 1.64 2008/10/06 22:09:21 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94";
#else
__RCSID("$NetBSD: suff.c,v 1.63 2008/02/15 21:29:50 christos Exp $");
__RCSID("$NetBSD: suff.c,v 1.64 2008/10/06 22:09:21 joerg Exp $");
#endif
#endif /* not lint */
#endif
@ -966,9 +966,9 @@ Suff_AddSuffix(char *str, GNode **gn)
ln = Lst_Find(sufflist, str, SuffSuffHasNameP);
if (ln == NILLNODE) {
s = emalloc(sizeof(Suff));
s = bmake_malloc(sizeof(Suff));
s->name = estrdup(str);
s->name = bmake_strdup(str);
s->nameLen = strlen(s->name);
s->searchPath = Lst_Init(FALSE);
s->children = Lst_Init(FALSE);
@ -1189,8 +1189,8 @@ SuffAddSrc(ClientData sp, ClientData lsp)
* structure for a file with no suffix attached. Two birds, and all
* that...
*/
s2 = emalloc(sizeof(Src));
s2->file = estrdup(targ->pref);
s2 = bmake_malloc(sizeof(Src));
s2->file = bmake_strdup(targ->pref);
s2->pref = targ->pref;
s2->parent = targ;
s2->node = NILGNODE;
@ -1207,7 +1207,7 @@ SuffAddSrc(ClientData sp, ClientData lsp)
fprintf(debug_file, "\n");
#endif
}
s2 = emalloc(sizeof(Src));
s2 = bmake_malloc(sizeof(Src));
s2->file = str_concat(targ->pref, s->name, 0);
s2->pref = targ->pref;
s2->parent = targ;
@ -1474,8 +1474,8 @@ SuffFindCmds(Src *targ, Lst slst)
* source node's name so Suff_FindDeps can free it
* again (ick)), and return the new structure.
*/
ret = emalloc(sizeof(Src));
ret->file = estrdup(s->name);
ret = bmake_malloc(sizeof(Src));
ret->file = bmake_strdup(s->name);
ret->pref = targ->pref;
ret->suff = suff;
suff->refCount++;
@ -2072,8 +2072,8 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
/*
* Allocate a Src structure to which things can be transformed
*/
targ = emalloc(sizeof(Src));
targ->file = estrdup(gn->name);
targ = bmake_malloc(sizeof(Src));
targ->file = bmake_strdup(gn->name);
targ->suff = (Suff *)Lst_Datum(ln);
targ->suff->refCount++;
targ->node = gn;
@ -2088,7 +2088,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
* the length of the suffix from the end of the name.
*/
prefLen = (eoname - targ->suff->nameLen) - sopref;
targ->pref = emalloc(prefLen + 1);
targ->pref = bmake_malloc(prefLen + 1);
memcpy(targ->pref, sopref, prefLen);
targ->pref[prefLen] = '\0';
@ -2117,14 +2117,14 @@ SuffFindNormalDeps(GNode *gn, Lst slst)
fprintf(debug_file, "\tNo known suffix on %s. Using .NULL suffix\n", gn->name);
}
targ = emalloc(sizeof(Src));
targ->file = estrdup(gn->name);
targ = bmake_malloc(sizeof(Src));
targ->file = bmake_strdup(gn->name);
targ->suff = suffNull;
targ->suff->refCount++;
targ->node = gn;
targ->parent = NULL;
targ->children = 0;
targ->pref = estrdup(sopref);
targ->pref = bmake_strdup(sopref);
#ifdef DEBUG_SRC
targ->cp = Lst_Init(FALSE);
#endif
@ -2529,9 +2529,9 @@ Suff_Init(void)
* actually go on the suffix list or everyone will think that's its
* suffix.
*/
emptySuff = suffNull = emalloc(sizeof(Suff));
emptySuff = suffNull = bmake_malloc(sizeof(Suff));
suffNull->name = estrdup("");
suffNull->name = bmake_strdup("");
suffNull->nameLen = 0;
suffNull->searchPath = Lst_Init(FALSE);
Dir_Concat(suffNull->searchPath, dirSearchPath);

View File

@ -1,4 +1,4 @@
/* $NetBSD: targ.c,v 1.52 2008/02/15 21:29:50 christos Exp $ */
/* $NetBSD: targ.c,v 1.53 2008/10/06 22:09:21 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: targ.c,v 1.52 2008/02/15 21:29:50 christos Exp $";
static char rcsid[] = "$NetBSD: targ.c,v 1.53 2008/10/06 22:09:21 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)targ.c 8.2 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: targ.c,v 1.52 2008/02/15 21:29:50 christos Exp $");
__RCSID("$NetBSD: targ.c,v 1.53 2008/10/06 22:09:21 joerg Exp $");
#endif
#endif /* not lint */
#endif
@ -233,8 +233,8 @@ Targ_NewGN(const char *name)
{
GNode *gn;
gn = emalloc(sizeof(GNode));
gn->name = estrdup(name);
gn = bmake_malloc(sizeof(GNode));
gn->name = bmake_strdup(name);
gn->uname = NULL;
gn->path = NULL;
if (name[0] == '-' && name[1] == 'l') {

View File

@ -1,15 +1,15 @@
/* $NetBSD: util.c,v 1.44 2008/02/15 21:29:50 christos Exp $ */
/* $NetBSD: util.c,v 1.45 2008/10/06 22:09:21 joerg Exp $ */
/*
* Missing stuff from OS's
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: util.c,v 1.44 2008/02/15 21:29:50 christos Exp $";
static char rcsid[] = "$NetBSD: util.c,v 1.45 2008/10/06 22:09:21 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: util.c,v 1.44 2008/02/15 21:29:50 christos Exp $");
__RCSID("$NetBSD: util.c,v 1.45 2008/10/06 22:09:21 joerg Exp $");
#endif
#endif
@ -38,63 +38,13 @@ strerror(int e)
}
#endif
#if !defined(MAKE_NATIVE) && !defined(HAVE_STRDUP)
#include <string.h>
/* strdup
*
* Make a duplicate of a string.
* For systems which lack this function.
*/
char *
strdup(const char *str)
{
size_t len;
char *p;
if (str == NULL)
return NULL;
len = strlen(str) + 1;
p = emalloc(len);
return memcpy(p, str, len);
}
#endif
#if !defined(HAVE_EMALLOC) && !defined(HAVE_STRNDUP)
#include <string.h>
/* strndup
*
* Make a duplicate of a string, up to a maximum length.
* For systems which lack this function.
*/
char *
strndup(const char *str, size_t maxlen)
{
size_t len;
char *p;
if (str == NULL)
return NULL;
len = strlen(str);
if (len > maxlen)
len = maxlen;
p = emalloc(len + 1);
memcpy(p, str, len);
p[len] = '\0';
return p;
}
#endif
#if !defined(MAKE_NATIVE) && !defined(HAVE_SETENV)
int
setenv(const char *name, const char *value, int dum)
{
char *p;
int len = strlen(name) + strlen(value) + 2; /* = \0 */
char *ptr = emalloc(len);
char *ptr = bmake_malloc(len);
(void) dum;

View File

@ -1,4 +1,4 @@
/* $NetBSD: var.c,v 1.133 2008/07/31 15:19:19 joerg Exp $ */
/* $NetBSD: var.c,v 1.134 2008/10/06 22:09:21 joerg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: var.c,v 1.133 2008/07/31 15:19:19 joerg Exp $";
static char rcsid[] = "$NetBSD: var.c,v 1.134 2008/10/06 22:09:21 joerg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: var.c,v 1.133 2008/07/31 15:19:19 joerg Exp $");
__RCSID("$NetBSD: var.c,v 1.134 2008/10/06 22:09:21 joerg Exp $");
#endif
#endif /* not lint */
#endif
@ -399,8 +399,8 @@ VarFind(const char *name, GNode *ctxt, int flags)
if ((env = getenv(name)) != NULL) {
int len;
v = emalloc(sizeof(Var));
v->name = estrdup(name);
v = bmake_malloc(sizeof(Var));
v->name = bmake_strdup(name);
len = strlen(env);
@ -481,7 +481,7 @@ VarAdd(const char *name, const char *val, GNode *ctxt)
int len;
Hash_Entry *h;
v = emalloc(sizeof(Var));
v = bmake_malloc(sizeof(Var));
len = val ? strlen(val) : 0;
v->val = Buf_Init(len+1);
@ -1443,7 +1443,7 @@ VarREError(int errnum, regex_t *pat, const char *str)
int errlen;
errlen = regerror(errnum, pat, 0, 0);
errbuf = emalloc(errlen);
errbuf = bmake_malloc(errlen);
regerror(errnum, pat, errbuf, errlen);
Error("%s: %s", str, errbuf);
free(errbuf);
@ -1666,8 +1666,8 @@ VarSelectWords(GNode *ctx __unused, Var_Parse_State *vpstate,
if (vpstate->oneBigWord) {
/* fake what brk_string() would do if there were only one word */
ac = 1;
av = emalloc((ac + 1) * sizeof(char *));
as = estrdup(str);
av = bmake_malloc((ac + 1) * sizeof(char *));
as = bmake_strdup(str);
av[0] = as;
av[1] = NULL;
} else {
@ -1759,8 +1759,8 @@ VarModify(GNode *ctx, Var_Parse_State *vpstate,
if (vpstate->oneBigWord) {
/* fake what brk_string() would do if there were only one word */
ac = 1;
av = emalloc((ac + 1) * sizeof(char *));
as = estrdup(str);
av = bmake_malloc((ac + 1) * sizeof(char *));
as = bmake_strdup(str);
av[0] = as;
av[1] = NULL;
} else {
@ -2290,11 +2290,11 @@ ApplyModifiers(char *nstr, const char *tstr,
++tstr;
if (v->flags & VAR_JUNK) {
/*
* We need to estrdup() it incase
* We need to bmake_strdup() it incase
* VarGetPattern() recurses.
*/
sv_name = v->name;
v->name = estrdup(v->name);
v->name = bmake_strdup(v->name);
} else if (ctxt != VAR_GLOBAL) {
Var *gv = VarFind(v->name, ctxt, 0);
if (gv == (Var *)NIL)
@ -2454,7 +2454,7 @@ ApplyModifiers(char *nstr, const char *tstr,
{
if ((v->flags & VAR_JUNK) != 0)
v->flags |= VAR_KEEP;
newStr = estrdup(v->name);
newStr = bmake_strdup(v->name);
cp = ++tstr;
termc = *tstr;
break;
@ -2469,12 +2469,12 @@ ApplyModifiers(char *nstr, const char *tstr,
if (gn == NILGNODE || gn->type & OP_NOPATH) {
newStr = NULL;
} else if (gn->path) {
newStr = estrdup(gn->path);
newStr = bmake_strdup(gn->path);
} else {
newStr = Dir_FindFile(v->name, Suff_FindPath(gn));
}
if (!newStr) {
newStr = estrdup(v->name);
newStr = bmake_strdup(v->name);
}
cp = ++tstr;
termc = *tstr;
@ -2548,7 +2548,7 @@ ApplyModifiers(char *nstr, const char *tstr,
int newStrSize =
(sizeof(int) * CHAR_BIT + 2) / 3 + 2;
newStr = emalloc(newStrSize);
newStr = bmake_malloc(newStrSize);
if (parsestate.oneBigWord) {
strncpy(newStr, "1", newStrSize);
} else {
@ -2794,7 +2794,7 @@ ApplyModifiers(char *nstr, const char *tstr,
* cp - tstr takes the null byte into account) and
* compress the pattern into the space.
*/
pattern = emalloc(cp - tstr);
pattern = bmake_malloc(cp - tstr);
for (cp2 = pattern, cp = tstr + 1;
cp < endpat;
cp++, cp2++)
@ -2812,7 +2812,7 @@ ApplyModifiers(char *nstr, const char *tstr,
* Either Var_Subst or VarModify will need a
* nul-terminated string soon, so construct one now.
*/
pattern = estrndup(tstr+1, endpat - (tstr + 1));
pattern = bmake_strndup(tstr+1, endpat - (tstr + 1));
copy = TRUE;
}
if (strchr(pattern, '$') != NULL) {
@ -3007,7 +3007,7 @@ ApplyModifiers(char *nstr, const char *tstr,
pattern.nsub = 1;
if (pattern.nsub > 10)
pattern.nsub = 10;
pattern.matches = emalloc(pattern.nsub *
pattern.matches = bmake_malloc(pattern.nsub *
sizeof(regmatch_t));
newStr = VarModify(ctxt, &tmpparsestate, nstr,
VarRESubstitute,
@ -3483,7 +3483,7 @@ Var_Parse(const char *str, GNode *ctxt, Boolean errnum, int *lengthPtr,
*/
*lengthPtr = tstr - start + 1;
if (dynamic) {
char *pstr = estrndup(start, *lengthPtr);
char *pstr = bmake_strndup(start, *lengthPtr);
*freePtr = pstr;
Buf_Destroy(buf, TRUE);
return(pstr);
@ -3496,7 +3496,7 @@ Var_Parse(const char *str, GNode *ctxt, Boolean errnum, int *lengthPtr,
* Still need to get to the end of the variable specification,
* so kludge up a Var structure for the modifications
*/
v = emalloc(sizeof(Var));
v = bmake_malloc(sizeof(Var));
v->name = UNCONST(str);
v->val = Buf_Init(1);
v->flags = VAR_JUNK;
@ -3571,7 +3571,7 @@ Var_Parse(const char *str, GNode *ctxt, Boolean errnum, int *lengthPtr,
*freePtr = NULL;
}
if (dynamic) {
nstr = estrndup(start, *lengthPtr);
nstr = bmake_strndup(start, *lengthPtr);
*freePtr = nstr;
} else {
nstr = var_Error;