Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/libexec/ld.elf_so Don't use internal libc function __findenv().
details: https://anonhg.NetBSD.org/src/rev/02f756e4a322
branches: trunk
changeset: 758750:02f756e4a322
user: tron <tron%NetBSD.org@localhost>
date: Sun Nov 14 22:09:16 2010 +0000
description:
Don't use internal libc function __findenv().
diffstat:
libexec/ld.elf_so/xenv.c | 29 ++++++++++++++++++++---------
1 files changed, 20 insertions(+), 9 deletions(-)
diffs (66 lines):
diff -r 8bbc3b4e9c7d -r 02f756e4a322 libexec/ld.elf_so/xenv.c
--- a/libexec/ld.elf_so/xenv.c Sun Nov 14 22:04:36 2010 +0000
+++ b/libexec/ld.elf_so/xenv.c Sun Nov 14 22:09:16 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xenv.c,v 1.1 2010/10/29 15:08:17 christos Exp $ */
+/* $NetBSD: xenv.c,v 1.2 2010/11/14 22:09:16 tron Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "from: @(#)setenv.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: xenv.c,v 1.1 2010/10/29 15:08:17 christos Exp $");
+__RCSID("$NetBSD: xenv.c,v 1.2 2010/11/14 22:09:16 tron Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -42,9 +42,10 @@
#include <string.h>
#include "rtldenv.h"
-extern char * __findenv(const char *, int *);
extern char **environ;
+#include <unistd.h>
+
/*
* xunsetenv(name) --
* Delete environmental variable "name".
@@ -52,19 +53,29 @@
int
xunsetenv(const char *name)
{
- int offset;
+ size_t l_name, r_offset, w_offset;
- if (name == NULL || *name == '\0' || strchr(name, '=') != NULL) {
+ if (name == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ l_name = strcspn(name, "=");
+ if (l_name == 0 || name[l_name] == '=') {
errno = EINVAL;
return -1;
}
- while (__findenv(name, &offset) != NULL) {
- while (environ[offset] != NULL) {
- environ[offset] = environ[offset + 1];
- offset++;
+ for (r_offset = 0, w_offset = 0; environ[r_offset] != NULL;
+ r_offset++) {
+ if (strncmp(name, environ[r_offset], l_name) != 0 ||
+ environ[r_offset][l_name] != '=') {
+ environ[w_offset++] = environ[r_offset];
}
}
+ while (w_offset < r_offset)
+ environ[w_offset++] = NULL;
+
return 0;
}
Home |
Main Index |
Thread Index |
Old Index