Updating usr.bin/make

Change-Id: I66b137a0368cf99267cd47a9625da8a12d8a1df7
This commit is contained in:
2012-12-11 18:41:20 +01:00
parent 71c7dcb9ce
commit 2bc7c627ac
24 changed files with 421 additions and 182 deletions

View File

@@ -1,15 +1,15 @@
/* $NetBSD: util.c,v 1.51 2011/04/02 07:58:30 mbalmer Exp $ */
/* $NetBSD: util.c,v 1.53 2012/06/04 22:45:05 sjg Exp $ */
/*
* Missing stuff from OS's
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: util.c,v 1.51 2011/04/02 07:58:30 mbalmer Exp $";
static char rcsid[] = "$NetBSD: util.c,v 1.53 2012/06/04 22:45:05 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: util.c,v 1.51 2011/04/02 07:58:30 mbalmer Exp $");
__RCSID("$NetBSD: util.c,v 1.53 2012/06/04 22:45:05 sjg Exp $");
#endif
#endif
@@ -48,11 +48,12 @@ findenv(const char *name, int *offset)
size_t i, len;
char *p, *q;
len = strlen(name);
for (i = 0; (q = environ[i]); i++) {
p = strchr(q, '=');
if (p == NULL)
if (p == NULL || p - q != len)
continue;
if (strncmp(name, q, len = p - q) == 0) {
if (strncmp(name, q, len) == 0) {
*offset = i;
return q + len + 1;
}
@@ -61,6 +62,14 @@ findenv(const char *name, int *offset)
return NULL;
}
char *
getenv(const char *name)
{
int offset;
return(findenv(name, &offset));
}
int
unsetenv(const char *name)
{
@@ -83,7 +92,6 @@ unsetenv(const char *name)
int
setenv(const char *name, const char *value, int rewrite)
{
static char **saveenv; /* copy of previously allocated space */
char *c, **newenv;
const char *cc;
size_t l_value, size;
@@ -106,20 +114,20 @@ setenv(const char *name, const char *value, int rewrite)
goto copy;
} else { /* create new slot */
size = sizeof(char *) * (offset + 2);
if (saveenv == environ) { /* just increase size */
if ((newenv = realloc(saveenv, size)) == NULL)
if (savedEnv == environ) { /* just increase size */
if ((newenv = realloc(savedEnv, size)) == NULL)
return -1;
saveenv = newenv;
savedEnv = newenv;
} else { /* get new space */
/*
* We don't free here because we don't know if
* the first allocation is valid on all OS's
*/
if ((saveenv = malloc(size)) == NULL)
if ((savedEnv = malloc(size)) == NULL)
return -1;
(void)memcpy(saveenv, environ, size - sizeof(char *));
(void)memcpy(savedEnv, environ, size - sizeof(char *));
}
environ = saveenv;
environ = savedEnv;
environ[offset + 1] = NULL;
}
for (cc = name; *cc && *cc != '='; ++cc) /* no `=' in name */