getenv.c

来自「德州仪器(TI) 的超低功耗16 位RISC 混合信号处理器的MSP430 平台」· C语言 代码 · 共 47 行

C
47
字号
/*******************
 *
 * Copyright 1998-2003 IAR Systems. All rights reserved.
 *
 * $Revision: 1.6 $
 *
 * This is the default implementation of the "getenv" function of the
 * standard library.  It can be replaced with a system-specific
 * implementation.  (Note: Typically the global variable __environ
 * should be used to specify the environment used.  This function
 * should only be replaced if that is not sufficient.)
 *
 * The "getenv" function is called with name of an environment
 * variable and should return a pointer to a string representing the
 * value of that variable, or 0.  An environment variable is used on
 * many host system to specify system or user information.  The
 * standard library does not rely on the presence of any environment
 * variables.
 *
 ********************/

#include <stdlib.h>
#include <string.h>
#include "yfuns.h"
_STD_BEGIN

#pragma module_name = "?getenv"

char *(getenv)(const char *name)
	{	/* search environment list for named entry */
	const char *s;
	size_t n = strlen(name);

	for (s = __environ; *s; s += strlen(s) + 1)
		{	/* look for name match */
		if (!strncmp(s, name, n) && s[n] == '=')
			return ((char *)&s[n + 1]);
		}
	return (0);
	}
_STD_END

/*
 * Copyright (c) 1992-2002 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
V3.12:0576 */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?