3 <<_getenv_r>>---look up environment variable
12 char *_getenv_r(struct _reent *<[reent_ptr]>, const char *<[name]>);
15 <<_getenv_r>> searches the list of environment variable names and values
16 (using the global pointer ``<<char **environ>>'') for a variable whose
17 name matches the string at <[name]>. If a variable name matches,
18 <<_getenv_r>> returns a pointer to the associated value.
21 A pointer to the (string) value of the environment variable, or
22 <<NULL>> if there is no such environment variable.
25 <<_getenv_r>> is not ANSI; the rules for properly forming names of environment
26 variables vary from one system to another. This implementation does not
27 permit '=' to be in identifiers.
29 <<_getenv_r>> requires a global pointer <<environ>>.
32 /* This file may have been modified by DJ Delorie (Jan 1991). If so,
33 ** these modifications are Copyright (C) 1991 DJ Delorie.
37 * Copyright (c) 1987 Regents of the University of California.
38 * All rights reserved.
40 * Redistribution and use in source and binary forms are permitted
41 * provided that: (1) source distributions retain this entire copyright
42 * notice and comment, and (2) distributions including binaries display
43 * the following acknowledgement: ``This product includes software
44 * developed by the University of California, Berkeley and its contributors''
45 * in the documentation or other materials provided with the distribution.
46 * Neither the name of the University nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
50 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
51 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
59 extern char **environ
;
61 /* Only deal with a pointer to environ, to work around subtle bugs with shared
62 libraries and/or small data systems where the user declares his own
64 static char ***p_environ
= &environ
;
68 * Returns pointer to value associated with name, if any, else NULL.
69 * Sets offset to be the offset of the name/value combination in the
70 * environmental array, for use by setenv(3) and unsetenv(3).
72 * This routine *should* be a static; don't use it.
76 _findenv_r (struct _reent
*reent_ptr
,
77 register const char *name
,
86 /* In some embedded systems, this does not get set. This protects
87 newlib from dereferencing a bad pointer. */
95 while (*c
&& *c
!= '=') c
++;
97 /* Identifiers may not contain an '=', so cannot match if does */
101 for (p
= *p_environ
; *p
; ++p
)
102 if (!strncmp (*p
, name
, len
))
103 if (*(c
= *p
+ len
) == '=')
105 *offset
= p
- *p_environ
;
107 return (char *) (++c
);
116 * Returns ptr to value associated with name, if any, else NULL.
120 _getenv_r (struct _reent
*reent_ptr
,
125 return _findenv_r (reent_ptr
, name
, &offset
);