OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [newlib/] [libc/] [stdlib/] [getenv_r.c] - Blame information for rev 207

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/*
2
FUNCTION
3
<<_getenv_r>>---look up environment variable
4
 
5
INDEX
6
        _getenv_r
7
INDEX
8
        environ
9
 
10
ANSI_SYNOPSIS
11
        #include <stdlib.h>
12
        char *_getenv_r(struct _reent *<[reent_ptr]>, const char *<[name]>);
13
 
14
TRAD_SYNOPSIS
15
        #include <stdlib.h>
16
        char *_getenv_r(<[reent_ptr]>, <[name]>)
17
        struct _reent *<[reent_ptr]>;
18
        char *<[name]>;
19
 
20
DESCRIPTION
21
<<_getenv_r>> searches the list of environment variable names and values
22
(using the global pointer ``<<char **environ>>'') for a variable whose
23
name matches the string at <[name]>.  If a variable name matches,
24
<<_getenv_r>> returns a pointer to the associated value.
25
 
26
RETURNS
27
A pointer to the (string) value of the environment variable, or
28
<<NULL>> if there is no such environment variable.
29
 
30
PORTABILITY
31
<<_getenv_r>> is not ANSI; the rules for properly forming names of environment
32
variables vary from one system to another.  This implementation does not
33
permit '=' to be in identifiers.
34
 
35
<<_getenv_r>> requires a global pointer <<environ>>.
36
*/
37
 
38
/* This file may have been modified by DJ Delorie (Jan 1991).  If so,
39
** these modifications are Copyright (C) 1991 DJ Delorie.
40
*/
41
 
42
/*
43
 * Copyright (c) 1987 Regents of the University of California.
44
 * All rights reserved.
45
 *
46
 * Redistribution and use in source and binary forms are permitted
47
 * provided that: (1) source distributions retain this entire copyright
48
 * notice and comment, and (2) distributions including binaries display
49
 * the following acknowledgement:  ``This product includes software
50
 * developed by the University of California, Berkeley and its contributors''
51
 * in the documentation or other materials provided with the distribution
52
 * and in all advertising materials mentioning features or use of this
53
 * software. Neither the name of the University nor the names of its
54
 * contributors may be used to endorse or promote products derived
55
 * from this software without specific prior written permission.
56
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
57
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
58
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
59
 */
60
 
61
#include <stdlib.h>
62
#include <stddef.h>
63
#include <string.h>
64
#include "envlock.h"
65
 
66
extern char **environ;
67
 
68
/* Only deal with a pointer to environ, to work around subtle bugs with shared
69
   libraries and/or small data systems where the user declares his own
70
   'environ'.  */
71
static char ***p_environ = &environ;
72
 
73
/*
74
 * _findenv --
75
 *      Returns pointer to value associated with name, if any, else NULL.
76
 *      Sets offset to be the offset of the name/value combination in the
77
 *      environmental array, for use by setenv(3) and unsetenv(3).
78
 *
79
 *      This routine *should* be a static; don't use it.
80
 */
81
 
82
char *
83
_DEFUN (_findenv_r, (reent_ptr, name, offset),
84
        struct _reent *reent_ptr   _AND
85
        register _CONST char *name _AND
86
        int *offset)
87
{
88
  register int len;
89
  register char **p;
90
  _CONST char *c;
91
 
92
  ENV_LOCK;
93
 
94
  /* In some embedded systems, this does not get set.  This protects
95
     newlib from dereferencing a bad pointer.  */
96
  if (!*p_environ)
97
    {
98
      ENV_UNLOCK;
99
      return NULL;
100
    }
101
 
102
  c = name;
103
  while (*c && *c != '=')  c++;
104
 
105
  /* Identifiers may not contain an '=', so cannot match if does */
106
  if(*c != '=')
107
    {
108
    len = c - name;
109
    for (p = *p_environ; *p; ++p)
110
      if (!strncmp (*p, name, len))
111
        if (*(c = *p + len) == '=')
112
        {
113
          *offset = p - *p_environ;
114
          ENV_UNLOCK;
115
          return (char *) (++c);
116
        }
117
    }
118
  ENV_UNLOCK;
119
  return NULL;
120
}
121
 
122
/*
123
 * _getenv_r --
124
 *      Returns ptr to value associated with name, if any, else NULL.
125
 */
126
 
127
char *
128
_DEFUN (_getenv_r, (reent_ptr, name),
129
        struct _reent *reent_ptr _AND
130
        _CONST char *name)
131
{
132
  int offset;
133
  char *_findenv_r ();
134
 
135
  return _findenv_r (reent_ptr, name, &offset);
136
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.