env.c (e93f27e3aeb7c0778012b7732bc6376e20f80427) | env.c (fe590ffe40f49fe09d8275fbf29f0d46c5b99dc7) |
---|---|
1/* Copyright 1988,1990,1993,1994 by Paul Vixie 2 * All rights reserved | 1/* Copyright 1988,1990,1993,1994 by Paul Vixie 2 * All rights reserved |
3 */ 4 5/* 6 * Copyright (c) 1997 by Internet Software Consortium |
|
3 * | 7 * |
4 * Distribute freely, except: don't remove my name from the source or 5 * documentation (don't take credit for my work), mark your changes (don't 6 * get me blamed for your possible bugs), don't alter or remove this 7 * notice. May be sold if buildable source is provided to buyer. No 8 * warrantee of any kind, express or implied, is included with this 9 * software; use at your own risk, responsibility for damages (if any) to 10 * anyone resulting from the use of this software rests entirely with the 11 * user. | 8 * Permission to use, copy, modify, and distribute this software for any 9 * purpose with or without fee is hereby granted, provided that the above 10 * copyright notice and this permission notice appear in all copies. |
12 * | 11 * |
13 * Send bug reports, bug fixes, enhancements, requests, flames, etc., and 14 * I'll try to keep a version up to date. I can be reached as follows: 15 * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul | 12 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS 13 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES 14 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE 15 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 18 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 19 * SOFTWARE. |
16 */ 17 18#if !defined(lint) && !defined(LINT) | 20 */ 21 22#if !defined(lint) && !defined(LINT) |
19static const char rcsid[] = 20 "$FreeBSD$"; | 23static const char rcsid[] = "$Id: env.c,v 1.3 1998/08/14 00:32:39 vixie Exp $"; |
21#endif 22 23 24#include "cron.h" 25 26 27char ** 28env_init(void) 29{ | 24#endif 25 26 27#include "cron.h" 28 29 30char ** 31env_init(void) 32{ |
30 register char **p = (char **) malloc(sizeof(char *)); | 33 char **p = (char **) malloc(sizeof(char **)); |
31 32 if (p) 33 p[0] = NULL; 34 return (p); 35} 36 37 38void --- 6 unchanged lines hidden (view full) --- 45 free(*p); 46 free(envp); 47} 48 49 50char ** 51env_copy(char **envp) 52{ | 34 35 if (p) 36 p[0] = NULL; 37 return (p); 38} 39 40 41void --- 6 unchanged lines hidden (view full) --- 48 free(*p); 49 free(envp); 50} 51 52 53char ** 54env_copy(char **envp) 55{ |
53 register int count, i; 54 register char **p; | 56 int count, i; 57 char **p; |
55 56 for (count = 0; envp[count] != NULL; count++) 57 ; 58 p = (char **) malloc((count+1) * sizeof(char *)); /* 1 for the NULL */ 59 if (p == NULL) { 60 errno = ENOMEM; 61 return NULL; 62 } --- 8 unchanged lines hidden (view full) --- 71 p[count] = NULL; 72 return (p); 73} 74 75 76char ** 77env_set(char **envp, char *envstr) 78{ | 58 59 for (count = 0; envp[count] != NULL; count++) 60 ; 61 p = (char **) malloc((count+1) * sizeof(char *)); /* 1 for the NULL */ 62 if (p == NULL) { 63 errno = ENOMEM; 64 return NULL; 65 } --- 8 unchanged lines hidden (view full) --- 74 p[count] = NULL; 75 return (p); 76} 77 78 79char ** 80env_set(char **envp, char *envstr) 81{ |
79 register int count, found; 80 register char **p; 81 char *q; | 82 int count, found; 83 char **p; 84 char *q; |
82 83 /* 84 * count the number of elements, including the null pointer; 85 * also set 'found' to -1 or index of entry if already in here. 86 */ 87 found = -1; 88 for (count = 0; envp[count] != NULL; count++) { 89 if (!strcmp_until(envp[count], envstr, '=')) --- 142 unchanged lines hidden (view full) --- 232 /* End of unquoted value: trim trailing whitespace */ 233 c = val + strlen (val); 234 while (c > val && isspace (*(c - 1))) 235 *(--c) = '\0'; 236 } 237 238 /* 2 fields from parser; looks like an env setting */ 239 | 85 86 /* 87 * count the number of elements, including the null pointer; 88 * also set 'found' to -1 or index of entry if already in here. 89 */ 90 found = -1; 91 for (count = 0; envp[count] != NULL; count++) { 92 if (!strcmp_until(envp[count], envstr, '=')) --- 142 unchanged lines hidden (view full) --- 235 /* End of unquoted value: trim trailing whitespace */ 236 c = val + strlen (val); 237 while (c > val && isspace (*(c - 1))) 238 *(--c) = '\0'; 239 } 240 241 /* 2 fields from parser; looks like an env setting */ 242 |
240 if (strlen(name) + 1 + strlen(val) >= MAX_ENVSTR-1) | 243 if (snprintf(envstr, MAX_ENVSTR, "%s=%s", name, val) >= MAX_ENVSTR) |
241 return (FALSE); | 244 return (FALSE); |
242 (void) sprintf(envstr, "%s=%s", name, val); | |
243 Debug(DPARS, ("load_env, <%s> <%s> -> <%s>\n", name, val, envstr)) 244 return (TRUE); 245} 246 247 248char * 249env_get(char *name, char **envp) 250{ | 245 Debug(DPARS, ("load_env, <%s> <%s> -> <%s>\n", name, val, envstr)) 246 return (TRUE); 247} 248 249 250char * 251env_get(char *name, char **envp) 252{ |
251 register int len = strlen(name); 252 register char *p, *q; | 253 int len = strlen(name); 254 char *p, *q; |
253 | 255 |
254 while ((p = *envp++)) { | 256 while ((p = *envp++) != NULL) { |
255 if (!(q = strchr(p, '='))) 256 continue; 257 if ((q - p) == len && !strncmp(p, name, len)) 258 return (q+1); 259 } 260 return (NULL); 261} | 257 if (!(q = strchr(p, '='))) 258 continue; 259 if ((q - p) == len && !strncmp(p, name, len)) 260 return (q+1); 261 } 262 return (NULL); 263} |