1 /* @(#)unsetenv.c 1.1 18/01/17 Copyright 2009-2018 J. Schilling */ 2 /* 3 * Our unsetenv implementation for systems that don't have it. 4 * Note that this implementation may not work correctly on platforms 5 * that support multi threading. 6 * 7 * Copyright (c) 2009-2018 J. Schilling 8 */ 9 /* 10 * The contents of this file are subject to the terms of the 11 * Common Development and Distribution License, Version 1.0 only 12 * (the "License"). You may not use this file except in compliance 13 * with the License. 14 * 15 * See the file CDDL.Schily.txt in this distribution for details. 16 * A copy of the CDDL is also available via the Internet at 17 * http://www.opensource.org/licenses/cddl1.txt 18 * 19 * When distributing Covered Code, include this CDDL HEADER in each 20 * file and include the License file CDDL.Schily.txt from this distribution. 21 */ 22 23 #include <schily/standard.h> 24 #include <schily/unistd.h> 25 #include <schily/schily.h> 26 27 #ifndef HAVE_UNSETENV 28 29 EXPORT int unsetenv __PR((const char *name)); 30 31 EXPORT int unsetenv(name)32unsetenv(name) 33 const char *name; 34 { 35 register int i = 0; 36 register const char *ep; 37 register const char *s2; 38 39 if (name == NULL || name[0] == '\0') 40 return (0); 41 42 for (i = 0; environ[i] != NULL; i++) { 43 /* 44 * Find string in environment entry. 45 */ 46 for (ep = environ[i], s2 = name; *ep++ == *s2++; ) 47 ; 48 if (*--ep == '=' && *--s2 == '\0') 49 goto found; 50 } 51 return (0); 52 found: 53 for (; environ[i] != NULL; i++) 54 environ[i] = environ[i+1]; 55 return (0); 56 } 57 #endif /* HAVE_UNSETENV */ 58