2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster/*
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * CDDL HEADER START
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster *
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * The contents of this file are subject to the terms of the
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * Common Development and Distribution License, Version 1.0 only
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * (the "License"). You may not use this file except in compliance
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * with the License.
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster *
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * or http://www.opensolaris.org/os/licensing.
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * See the License for the specific language governing permissions
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * and limitations under the License.
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster *
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * When distributing Covered Code, include this CDDL HEADER in each
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * If applicable, add the following below this CDDL HEADER, with the
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * fields enclosed by brackets "[]" replaced with your own identifying
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * information: Portions Copyright [yyyy] [name of copyright owner]
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster *
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * CDDL HEADER END
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster */
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster/*
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * Copyright (c) 1996, by Sun Microsystems, Inc.
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * All rights reserved.
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster */
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster#pragma ident "%Z%%M% %I% %E% SMI"
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster/*
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * MKS interface extension.
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * A version of getenv() that doesn't overwrite it's return value
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * on each call.
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster *
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * Copyright 1995 by Mortice Kern Systems Inc. All rights reserved.
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster *
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster */
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster#ifdef M_RCSID
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster#ifndef lint
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Fosterstatic char const rcsID[] = "$Header: /rd/src/libc/mks/rcs/m_getenv.c 1.2 1995/07/11 16:53:01 ross Exp $";
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster#endif /*lint*/
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster#endif /*M_RCSID*/
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster#include <mks.h>
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster#include <stdlib.h>
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster#include <string.h>
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster#ifdef M_NON_STATIC_GETENV
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster#undef __m_getenv
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster/*f
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster * Assume getenv() works the way we expect it to on PC systems.
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster */
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Fosterchar *
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster__m_getenv(char const *name) {
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster return getenv(name);
2d0a88b18a041738cfe635b45bd1db56af469c91Allan Foster}
#else /* M_NON_STATIC_GETENV */
extern char **environ;
/*f
* A version of getenv safe to use in library functions. According to
* ANSI C and XPG 4 no library function shall behave as if it called
* getenv. This is a problem on systems that have getenv functions
* that overwrite their return value on each call.
*/
char *
__m_getenv(char const *name) {
if (m_setenv() != NULL) {
int len = strlen(name);
char **envp = environ;
char *s = *envp++;
while(s != NULL) {
if (strncmp(name, s, len) == 0 && s[len] == '=') {
return s + len + 1;
}
s = *envp++;
}
}
return NULL;
}
#endif /* M_NON_STATIC_GETENV */