⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 putenv.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
字号:
/*	@(#)putenv.c	4.1	ULTRIX	7/3/90	*//*	LINTLIBRARY	*//*	putenv - change environment variables	input - char *change = a pointer to a string of the form			       "name=value"	output - 0, if successful		 1, otherwise*/#define NULL 0extern char **__environ;	/* pointer to enviroment */static reall = 0;		/* flag to reallocate space, if putenv is called				   more than once */intputenv(change)char *change;{	char **newenv;		    /* points to new environment */	register int which;	    /* index of variable to replace */	char *realloc(), *malloc(); /* memory alloc routines */	if ((which = find(change)) < 0)  {		/* if a new variable */		/* which is negative of table size, so invert and		   count new element */		which = (-which) + 1;		if (reall)  {			/* we have expanded environ before */			newenv = (char **)realloc(__environ,				  which*sizeof(char *));			if (newenv == NULL)  return -1;			/* now that we have space, change environ */			__environ = newenv;		} else {			/* environ points to the original space */			reall++;			newenv = (char **)malloc(which*sizeof(char *));			if (newenv == NULL)  return -1;			(void)memcpy((char *)newenv, (char *)__environ, 				(int)(which*sizeof(char *)));			__environ = newenv;		}		__environ[which-2] = change;		__environ[which-1] = NULL;	}  else  {		/* we are replacing an old variable */		__environ[which] = change;	}	return 0;}/*	find - find where s2 is in environ * *	input - str = string of form name=value * *	output - index of name in environ that matches "name" *		 -size of table, if none exists*/staticfind(str)register char *str;{	register int ct = 0;	/* index into environ */	while(__environ[ct] != NULL)   {		if (match(__environ[ct], str)  != 0)			return ct;		ct++;	}	return -(++ct);}/* *	s1 is either name, or name=value *	s2 is name=value *	if names match, return value of 1, *	else return 0 */staticmatch(s1, s2)register char *s1, *s2;{	while(*s1 == *s2++)  {		if (*s1 == '=')			return 1;		s1++;	}	return 0;}

⌨️ 快捷键说明

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