Permalink
Switch branches/tags
x86_64versiong3 winsup-2000-02-17 w32api-2_2 w32api-1_5 tcltk840-20020924-branchpoint sid-snapshot-20150301 sid-snapshot-20150201 sid-snapshot-20150101 sid-snapshot-20141201 sid-snapshot-20141101 sid-snapshot-20141001 sid-snapshot-20140901 sid-snapshot-20140801 sid-snapshot-20140701 sid-snapshot-20140601 sid-snapshot-20140501 sid-snapshot-20140401 sid-snapshot-20140301 sid-snapshot-20140201 sid-snapshot-20140101 sid-snapshot-20131201 sid-snapshot-20131101 sid-snapshot-20131001 sid-snapshot-20130901 sid-snapshot-20130801 sid-snapshot-20130701 sid-snapshot-20130601 sid-snapshot-20130501 sid-snapshot-20130401 sid-snapshot-20130301 sid-snapshot-20130201 sid-snapshot-20130101 sid-snapshot-20121201 sid-snapshot-20121101 sid-snapshot-20121001 sid-snapshot-20120901 sid-snapshot-20120801 sid-snapshot-20120701 sid-snapshot-20120601 sid-snapshot-20120501 sid-snapshot-20120401 sid-snapshot-20120301 sid-snapshot-20120201 sid-snapshot-20120101 sid-snapshot-20111201 sid-snapshot-20111101 sid-snapshot-20111001 sid-snapshot-20110901 sid-snapshot-20110801 sid-snapshot-20110701 sid-snapshot-20110601 sid-snapshot-20110501 sid-snapshot-20110401 sid-snapshot-20110301 sid-snapshot-20110201 sid-snapshot-20110101 sid-snapshot-20101201 sid-snapshot-20101101 sid-snapshot-20101001 sid-snapshot-20100901 sid-snapshot-20100801 sid-snapshot-20100701 sid-snapshot-20100601 sid-snapshot-20100501 sid-snapshot-20100401 sid-snapshot-20100301 sid-snapshot-20100201 sid-snapshot-20100101 sid-snapshot-20091201 sid-snapshot-20091101 sid-snapshot-20091001 sid-snapshot-20090901 sid-snapshot-20090801 sid-snapshot-20090701 sid-snapshot-20090601 sid-snapshot-20090501 sid-snapshot-20090401 sid-snapshot-20090301 sid-snapshot-20090201 sid-snapshot-20090101 sid-snapshot-20081201 sid-snapshot-20081101 sid-snapshot-20081001 sid-snapshot-20080901 sid-snapshot-20080801 sid-snapshot-20080701 sid-snapshot-20080601 sid-snapshot-20080501 sid-snapshot-20080403 sid-snapshot-20080401 sid-snapshot-20080301 sid-snapshot-20080201 sid-snapshot-20080101 sid-snapshot-20071201 sid-snapshot-20071101 sid-snapshot-20071001 sid-20020905-branchpoint reverse-20081226-branchpoint reverse-20080930-branchpoint reverse-20080717-branchpoint
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
136 lines (114 sloc) 3.66 KB
/*
FUNCTION
<<_getenv_r>>---look up environment variable
INDEX
_getenv_r
INDEX
environ
ANSI_SYNOPSIS
#include <stdlib.h>
char *_getenv_r(struct _reent *<[reent_ptr]>, const char *<[name]>);
TRAD_SYNOPSIS
#include <stdlib.h>
char *_getenv_r(<[reent_ptr]>, <[name]>)
struct _reent *<[reent_ptr]>;
char *<[name]>;
DESCRIPTION
<<_getenv_r>> searches the list of environment variable names and values
(using the global pointer ``<<char **environ>>'') for a variable whose
name matches the string at <[name]>. If a variable name matches,
<<_getenv_r>> returns a pointer to the associated value.
RETURNS
A pointer to the (string) value of the environment variable, or
<<NULL>> if there is no such environment variable.
PORTABILITY
<<_getenv_r>> is not ANSI; the rules for properly forming names of environment
variables vary from one system to another. This implementation does not
permit '=' to be in identifiers.
<<_getenv_r>> requires a global pointer <<environ>>.
*/
/* This file may have been modified by DJ Delorie (Jan 1991). If so,
** these modifications are Copyright (C) 1991 DJ Delorie.
*/
/*
* Copyright (c) 1987 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that: (1) source distributions retain this entire copyright
* notice and comment, and (2) distributions including binaries display
* the following acknowledgement: ``This product includes software
* developed by the University of California, Berkeley and its contributors''
* in the documentation or other materials provided with the distribution
* and in all advertising materials mentioning features or use of this
* software. Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include "envlock.h"
extern char **environ;
/* Only deal with a pointer to environ, to work around subtle bugs with shared
libraries and/or small data systems where the user declares his own
'environ'. */
static char ***p_environ = &environ;
/*
* _findenv --
* Returns pointer to value associated with name, if any, else NULL.
* Sets offset to be the offset of the name/value combination in the
* environmental array, for use by setenv(3) and unsetenv(3).
*
* This routine *should* be a static; don't use it.
*/
char *
_DEFUN (_findenv_r, (reent_ptr, name, offset),
struct _reent *reent_ptr _AND
register _CONST char *name _AND
int *offset)
{
register int len;
register char **p;
_CONST char *c;
ENV_LOCK;
/* In some embedded systems, this does not get set. This protects
newlib from dereferencing a bad pointer. */
if (!*p_environ)
{
ENV_UNLOCK;
return NULL;
}
c = name;
while (*c && *c != '=') c++;
/* Identifiers may not contain an '=', so cannot match if does */
if(*c != '=')
{
len = c - name;
for (p = *p_environ; *p; ++p)
if (!strncmp (*p, name, len))
if (*(c = *p + len) == '=')
{
*offset = p - *p_environ;
ENV_UNLOCK;
return (char *) (++c);
}
}
ENV_UNLOCK;
return NULL;
}
/*
* _getenv_r --
* Returns ptr to value associated with name, if any, else NULL.
*/
char *
_DEFUN (_getenv_r, (reent_ptr, name),
struct _reent *reent_ptr _AND
_CONST char *name)
{
int offset;
return _findenv_r (reent_ptr, name, &offset);
}