Module Name:    src
Committed By:   tron
Date:           Sun Nov 14 22:09:16 UTC 2010

Modified Files:
        src/libexec/ld.elf_so: xenv.c

Log Message:
Don't use internal libc function __findenv().


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/libexec/ld.elf_so/xenv.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/libexec/ld.elf_so/xenv.c
diff -u src/libexec/ld.elf_so/xenv.c:1.1 src/libexec/ld.elf_so/xenv.c:1.2
--- src/libexec/ld.elf_so/xenv.c:1.1	Fri Oct 29 15:08:17 2010
+++ src/libexec/ld.elf_so/xenv.c	Sun Nov 14 22:09:16 2010
@@ -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) {
+		errno = EINVAL;
+		return -1;
+	}
 
-	if (name == NULL || *name == '\0' || strchr(name, '=') != NULL) {
+	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;
 }

Reply via email to