- (dtucker) [openbsd-compat/setenv.c] Sync changes from OpenBSD setenv.c
revs 1.7 - 1.9.
This commit is contained in:
parent
32b531067d
commit
063ba7455f
|
@ -1,9 +1,11 @@
|
||||||
20051110
|
20051110
|
||||||
- (dtucker) [openbsd-compat/getenv.c] Merge changes for __findenv from
|
- (dtucker) [openbsd-compat/setenv.c] Merge changes for __findenv from
|
||||||
OpenBSD getenv.c revs 1.4 - 1.8 (ANSIfication of arguments, removal of
|
OpenBSD getenv.c revs 1.4 - 1.8 (ANSIfication of arguments, removal of
|
||||||
"register").
|
"register").
|
||||||
- (dtucker) [openbsd-compat/getenv.c] Make __findenv static, remove
|
- (dtucker) [openbsd-compat/setenv.c] Make __findenv static, remove
|
||||||
unnecessary prototype.
|
unnecessary prototype.
|
||||||
|
- (dtucker) [openbsd-compat/setenv.c] Sync changes from OpenBSD setenv.c
|
||||||
|
revs 1.7 - 1.9.
|
||||||
|
|
||||||
20051105
|
20051105
|
||||||
- (djm) OpenBSD CVS Sync
|
- (djm) OpenBSD CVS Sync
|
||||||
|
@ -3246,4 +3248,4 @@
|
||||||
- (djm) Trim deprecated options from INSTALL. Mention UsePAM
|
- (djm) Trim deprecated options from INSTALL. Mention UsePAM
|
||||||
- (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
|
- (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
|
||||||
|
|
||||||
$Id: ChangeLog,v 1.3956 2005/11/09 23:13:06 dtucker Exp $
|
$Id: ChangeLog,v 1.3957 2005/11/09 23:38:45 dtucker Exp $
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/* OPENBSD ORIGINAL: lib/libc/stdlib/setenv.c */
|
/* OPENBSD ORIGINAL: lib/libc/stdlib/setenv.c */
|
||||||
|
|
||||||
|
/* $OpenBSD: setenv.c,v 1.9 2005/08/08 08:05:37 espie Exp $ */
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1987 Regents of the University of California.
|
* Copyright (c) 1987 Regents of the University of California.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
|
@ -32,15 +33,12 @@
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
#if !defined(HAVE_SETENV) || !defined(HAVE_UNSETENV)
|
#if !defined(HAVE_SETENV) || !defined(HAVE_UNSETENV)
|
||||||
|
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
|
||||||
static char *rcsid = "$OpenBSD: setenv.c,v 1.6 2003/06/02 20:18:38 millert Exp $";
|
|
||||||
#endif /* LIBC_SCCS and not lint */
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* OpenSSH Portable: __findenv is from getenv.c rev 1.8, made static */
|
extern char **environ;
|
||||||
|
|
||||||
|
/* OpenSSH Portable: __findenv is from getenv.c rev 1.8, made static */
|
||||||
/*
|
/*
|
||||||
* __findenv --
|
* __findenv --
|
||||||
* Returns pointer to value associated with name, if any, else NULL.
|
* Returns pointer to value associated with name, if any, else NULL.
|
||||||
|
@ -80,14 +78,10 @@ __findenv(const char *name, int *offset)
|
||||||
* "value". If rewrite is set, replace any current value.
|
* "value". If rewrite is set, replace any current value.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
setenv(name, value, rewrite)
|
setenv(const char *name, const char *value, int rewrite)
|
||||||
register const char *name;
|
|
||||||
register const char *value;
|
|
||||||
int rewrite;
|
|
||||||
{
|
{
|
||||||
extern char **environ;
|
static char **lastenv; /* last value of environ */
|
||||||
static int alloced; /* if allocated space before */
|
char *C;
|
||||||
register char *C;
|
|
||||||
int l_value, offset;
|
int l_value, offset;
|
||||||
|
|
||||||
if (*value == '=') /* no `=' in value */
|
if (*value == '=') /* no `=' in value */
|
||||||
|
@ -102,30 +96,23 @@ setenv(name, value, rewrite)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
} else { /* create new slot */
|
} else { /* create new slot */
|
||||||
register int cnt;
|
size_t cnt;
|
||||||
register char **P;
|
char **P;
|
||||||
|
|
||||||
for (P = environ, cnt = 0; *P; ++P, ++cnt);
|
for (P = environ; *P != NULL; P++)
|
||||||
if (alloced) { /* just increase size */
|
;
|
||||||
P = (char **)realloc((void *)environ,
|
cnt = P - environ;
|
||||||
(size_t)(sizeof(char *) * (cnt + 2)));
|
P = (char **)realloc(lastenv, sizeof(char *) * (cnt + 2));
|
||||||
if (!P)
|
if (!P)
|
||||||
return (-1);
|
return (-1);
|
||||||
environ = P;
|
if (lastenv != environ)
|
||||||
}
|
memcpy(P, environ, cnt * sizeof(char *));
|
||||||
else { /* get new space */
|
lastenv = environ = P;
|
||||||
alloced = 1; /* copy old entries into it */
|
|
||||||
P = (char **)malloc((size_t)(sizeof(char *) *
|
|
||||||
(cnt + 2)));
|
|
||||||
if (!P)
|
|
||||||
return (-1);
|
|
||||||
memmove(P, environ, cnt * sizeof(char *));
|
|
||||||
environ = P;
|
|
||||||
}
|
|
||||||
environ[cnt + 1] = NULL;
|
|
||||||
offset = cnt;
|
offset = cnt;
|
||||||
|
environ[cnt + 1] = NULL;
|
||||||
}
|
}
|
||||||
for (C = (char *)name; *C && *C != '='; ++C); /* no `=' in name */
|
for (C = (char *)name; *C && *C != '='; ++C)
|
||||||
|
; /* no `=' in name */
|
||||||
if (!(environ[offset] = /* name + `=' + value */
|
if (!(environ[offset] = /* name + `=' + value */
|
||||||
malloc((size_t)((int)(C - name) + l_value + 2))))
|
malloc((size_t)((int)(C - name) + l_value + 2))))
|
||||||
return (-1);
|
return (-1);
|
||||||
|
@ -143,13 +130,10 @@ setenv(name, value, rewrite)
|
||||||
* Delete environmental variable "name".
|
* Delete environmental variable "name".
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
unsetenv(name)
|
unsetenv(const char *name)
|
||||||
const char *name;
|
|
||||||
{
|
{
|
||||||
extern char **environ;
|
char **P;
|
||||||
register char **P;
|
|
||||||
int offset;
|
int offset;
|
||||||
char *__findenv();
|
|
||||||
|
|
||||||
while (__findenv(name, &offset)) /* if set multiple times */
|
while (__findenv(name, &offset)) /* if set multiple times */
|
||||||
for (P = &environ[offset];; ++P)
|
for (P = &environ[offset];; ++P)
|
||||||
|
|
Loading…
Reference in New Issue