f8dd961144
include: * Rework the way that poll() is detected so that it more closely follows how the rest of the replacement functions are detected. * Split err*() and warn*() functions into separate err.c and warn.c files so that we can more finely isolate the objects files pulled in by the linker. This should fix building textproc/nbsed on Solaris. * Move more definitions from nbcompat.h into nbcompat/*.h. This makes it more clear which NetBSD headers are expected to provide which function declarations and macro definitions. * Clean out nbconfig.h by moving all of the relevant definitions into the correct nbcompat/*.h files. * Update all of the library functions to the latest from src HEAD. Also change the way that sources are modified when imported -- we now include <nbcompat.h> before the first system header, include <nbcompat/*.h> versions of headers instead of system ones where available, and "#if 0" the sections that make no sense when being built outside of the NetBSD source tree. This should make future updates from src HEAD, e.g. for security updates or bug fixes, easier. * Move all private headers into a subdirectory and include the headers from the private directory. This avoids any nameclashes with system headers with the same name.
117 lines
3.4 KiB
C
117 lines
3.4 KiB
C
/* $NetBSD: getenv.c,v 1.4 2004/08/23 03:32:12 jlam Exp $ */
|
|
|
|
/*
|
|
* Copyright (c) 1987, 1993
|
|
* The Regents of the University of California. All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* 3. 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 BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*/
|
|
|
|
#include <nbcompat.h>
|
|
#include <nbcompat/cdefs.h>
|
|
#if defined(LIBC_SCCS) && !defined(lint)
|
|
#if 0
|
|
static char sccsid[] = "@(#)getenv.c 8.1 (Berkeley) 6/4/93";
|
|
#else
|
|
__RCSID("$NetBSD: getenv.c,v 1.4 2004/08/23 03:32:12 jlam Exp $");
|
|
#endif
|
|
#endif /* LIBC_SCCS and not lint */
|
|
|
|
#include <nbcompat/assert.h>
|
|
#if HAVE_ERRNO_H
|
|
#include <errno.h>
|
|
#endif
|
|
#include <nbcompat/stdlib.h>
|
|
#include <nbcompat/string.h>
|
|
#if 0
|
|
#include "local.h"
|
|
#include "reentrant.h"
|
|
#endif
|
|
|
|
char *__findenv __P((const char *, int *));
|
|
|
|
#if 0
|
|
#ifdef _REENTRANT
|
|
rwlock_t __environ_lock = RWLOCK_INITIALIZER;
|
|
#endif
|
|
#endif
|
|
extern char **environ;
|
|
|
|
#ifndef rwlock_rdlock
|
|
#define rwlock_rdlock(lock) ((void)0)
|
|
#endif
|
|
#ifndef rwlock_unlock
|
|
#define rwlock_unlock(lock) ((void)0)
|
|
#endif
|
|
|
|
/*
|
|
* getenv --
|
|
* Returns ptr to value associated with name, if any, else NULL.
|
|
*/
|
|
char *
|
|
getenv(name)
|
|
const char *name;
|
|
{
|
|
int offset;
|
|
char *result;
|
|
|
|
_DIAGASSERT(name != NULL);
|
|
|
|
rwlock_rdlock(&__environ_lock);
|
|
result = __findenv(name, &offset);
|
|
rwlock_unlock(&__environ_lock);
|
|
return (result);
|
|
}
|
|
|
|
/*
|
|
* __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).
|
|
* Explicitly removes '=' in argument name.
|
|
*
|
|
* This routine *should* be a static; don't use it.
|
|
*/
|
|
char *
|
|
__findenv(name, offset)
|
|
const char *name;
|
|
int *offset;
|
|
{
|
|
size_t len;
|
|
const char *np;
|
|
char **p, *c;
|
|
|
|
if (name == NULL || environ == NULL)
|
|
return (NULL);
|
|
for (np = name; *np && *np != '='; ++np)
|
|
continue;
|
|
len = np - name;
|
|
for (p = environ; (c = *p) != NULL; ++p)
|
|
if (strncmp(c, name, len) == 0 && c[len] == '=') {
|
|
*offset = p - environ;
|
|
return (c + len + 1);
|
|
}
|
|
return (NULL);
|
|
}
|