setenv.c (126274) | setenv.c (128456) |
---|---|
1/* OPENBSD ORIGINAL: lib/libc/stdlib/setenv.c */ 2 3/* 4 * Copyright (c) 1987 Regents of the University of California. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 16 unchanged lines hidden (view full) --- 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32#include "includes.h" | 1/* OPENBSD ORIGINAL: lib/libc/stdlib/setenv.c */ 2 3/* 4 * Copyright (c) 1987 Regents of the University of California. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 16 unchanged lines hidden (view full) --- 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32#include "includes.h" |
33#ifndef HAVE_SETENV | 33#if !defined(HAVE_SETENV) || !defined(HAVE_UNSETENV) |
34 35#if defined(LIBC_SCCS) && !defined(lint) 36static char *rcsid = "$OpenBSD: setenv.c,v 1.6 2003/06/02 20:18:38 millert Exp $"; 37#endif /* LIBC_SCCS and not lint */ 38 39#include <stdlib.h> 40#include <string.h> 41 --- 30 unchanged lines hidden (view full) --- 72 if (i == 0 && *cp++ == '=') { 73 *offset = p - environ; 74 return (cp); 75 } 76 } 77 return (NULL); 78} 79 | 34 35#if defined(LIBC_SCCS) && !defined(lint) 36static char *rcsid = "$OpenBSD: setenv.c,v 1.6 2003/06/02 20:18:38 millert Exp $"; 37#endif /* LIBC_SCCS and not lint */ 38 39#include <stdlib.h> 40#include <string.h> 41 --- 30 unchanged lines hidden (view full) --- 72 if (i == 0 && *cp++ == '=') { 73 *offset = p - environ; 74 return (cp); 75 } 76 } 77 return (NULL); 78} 79 |
80#ifndef HAVE_SETENV |
|
80/* 81 * setenv -- 82 * Set the value of the environmental variable "name" to be 83 * "value". If rewrite is set, replace any current value. 84 */ 85int 86setenv(name, value, rewrite) 87 register const char *name; --- 45 unchanged lines hidden (view full) --- 133 malloc((size_t)((int)(C - name) + l_value + 2)))) 134 return (-1); 135 for (C = environ[offset]; (*C = *name++) && *C != '='; ++C) 136 ; 137 for (*C++ = '='; (*C++ = *value++); ) 138 ; 139 return (0); 140} | 81/* 82 * setenv -- 83 * Set the value of the environmental variable "name" to be 84 * "value". If rewrite is set, replace any current value. 85 */ 86int 87setenv(name, value, rewrite) 88 register const char *name; --- 45 unchanged lines hidden (view full) --- 134 malloc((size_t)((int)(C - name) + l_value + 2)))) 135 return (-1); 136 for (C = environ[offset]; (*C = *name++) && *C != '='; ++C) 137 ; 138 for (*C++ = '='; (*C++ = *value++); ) 139 ; 140 return (0); 141} |
142#endif /* HAVE_SETENV */ |
|
141 | 143 |
144#ifndef HAVE_UNSETENV |
|
142/* 143 * unsetenv(name) -- 144 * Delete environmental variable "name". 145 */ 146void 147unsetenv(name) 148 const char *name; 149{ 150 extern char **environ; 151 register char **P; 152 int offset; 153 char *__findenv(); 154 155 while (__findenv(name, &offset)) /* if set multiple times */ 156 for (P = &environ[offset];; ++P) 157 if (!(*P = *(P + 1))) 158 break; 159} | 145/* 146 * unsetenv(name) -- 147 * Delete environmental variable "name". 148 */ 149void 150unsetenv(name) 151 const char *name; 152{ 153 extern char **environ; 154 register char **P; 155 int offset; 156 char *__findenv(); 157 158 while (__findenv(name, &offset)) /* if set multiple times */ 159 for (P = &environ[offset];; ++P) 160 if (!(*P = *(P + 1))) 161 break; 162} |
163#endif /* HAVE_UNSETENV */ |
|
160 | 164 |
161#endif /* HAVE_SETENV */ | 165#endif /* !defined(HAVE_SETENV) || !defined(HAVE_UNSETENV) */ |