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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libc/] [stdlib/] [getenv_r.c] - Blame information for rev 56

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 56 joel
/*
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.
33
 
34
<<_getenv_r>> requires a global pointer <<environ>>.
35
*/
36
 
37
/* This file may have been modified by DJ Delorie (Jan 1991).  If so,
38
** these modifications are Coyright (C) 1991 DJ Delorie, 24 Kirsten Ave,
39
** Rochester NH, 03867-2954, USA.
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
/*
69
 * _findenv --
70
 *      Returns pointer to value associated with name, if any, else NULL.
71
 *      Sets offset to be the offset of the name/value combination in the
72
 *      environmental array, for use by setenv(3) and unsetenv(3).
73
 *      Explicitly removes '=' in argument name.
74
 *
75
 *      This routine *should* be a static; don't use it.
76
 */
77
 
78
char *
79
_DEFUN (_findenv_r, (reent_ptr, name, offset),
80
        struct _reent *reent_ptr   _AND
81
        register _CONST char *name _AND
82
        int *offset)
83
{
84
  register int len;
85
  register char **p;
86
  _CONST char *c;
87
 
88
  ENV_LOCK;
89
 
90
  /* In some embedded systems, this does not get set.  This protects
91
     newlib from dereferencing a bad pointer.  */
92
  if (!environ)
93
    return NULL;
94
 
95
  c = name;
96
  len = 0;
97
  while (*c && *c != '=')
98
    {
99
      c++;
100
      len++;
101
    }
102
 
103
  for (p = environ; *p; ++p)
104
    if (!strncmp (*p, name, len))
105
      if (*(c = *p + len) == '=')
106
        {
107
          *offset = p - environ;
108
          ENV_UNLOCK;
109
          return (char *) (++c);
110
        }
111
  ENV_UNLOCK;
112
  return NULL;
113
}
114
 
115
/*
116
 * _getenv_r --
117
 *      Returns ptr to value associated with name, if any, else NULL.
118
 */
119
 
120
char *
121
_DEFUN (_getenv_r, (reent_ptr, name),
122
        struct _reent *reent_ptr _AND
123
        _CONST char *name)
124
{
125
  int offset;
126
  char *_findenv_r ();
127
 
128
  return _findenv_r (reent_ptr, name, &offset);
129
}

powered by: WebSVN 2.1.0

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