getenv.c

来自「序列对齐 Compare a protein sequence to a pr」· C语言 代码 · 共 57 行

C
57
字号
#include <stdio.h>#include <string.h>#include <stdlib.h>#define MAXENV 1024char *envstr;char *mgetenv(str)char *str;{	static int EnvInit=0;	char *eptr, *esptr, *bp;	int i,esize;	FILE *fenv; 		if (EnvInit==0) {		EnvInit=1;		if ((fenv=fopen("environment","r"))!=NULL) {			if ((envstr=malloc((size_t)(esize=MAXENV)))==NULL) {				fclose(fenv); goto noenv;}			esptr=envstr; esize -= 10;			while (fgets(esptr,esize,fenv)!=NULL) {				if ((bp=strchr(esptr,'\n'))!=NULL) *bp='\0';				esize -= (i=strlen(esptr)+1);				esptr += i;				}			fclose(fenv);			esptr='\0';			}		else envstr=NULL;	}		if (envstr==NULL) return NULL;	else {				for (eptr=envstr; *eptr; eptr += strlen(eptr)+1) {			if (strncmp(str,eptr,(long)strlen(str))==0) {				return strchr(eptr,'=')+1;				}			}		return NULL;		}noenv:	envstr=NULL; return NULL;	}strnpcpy(to,from,max)	char *to; Str255 from; size_t max;{	size_t i, n;		n = (*from<max) ? *from : max;	from++;	for (i=0; i<n; i++) *to++ = *from++;	if (n<max) *to='\0';	}

⌨️ 快捷键说明

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