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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libc/] [stdlib/] [getenv.c] - Blame information for rev 39

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

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

powered by: WebSVN 2.1.0

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