xref: /original-bsd/usr.bin/f77/libU77/getenv_.c (revision f052b07a)
1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  *
6  *	@(#)getenv_.c	5.1	06/07/85
7  */
8 
9 /*
10  * return environment variables
11  *
12  * calling sequence:
13  *	character*20 evar
14  *	call getenv (ENV_NAME, evar)
15  * where:
16  *	ENV_NAME is the name of an environment variable
17  *	evar is a character variable which will receive
18  *		the current value of ENV_NAME,
19  *		or all blanks if ENV_NAME is not defined
20  */
21 
22 extern char **environ;
23 
24 getenv_(fname, value, flen, vlen)
25 char *value, *fname;
26 long int vlen, flen;
27 {
28 	register char *ep, *fp;
29 	register char **env = environ;
30 	int i;
31 
32 	while (ep = *env++) {
33 		for (fp=fname, i=0; i <= flen; i++) {
34 			if (i == flen || *fp == ' ') {
35 				if (*ep++ == '=') {
36 					b_char(ep, value, vlen);
37 					return(0);
38 				}
39 				else break;
40 			}
41 			else if (*ep++ != *fp++) break;
42 		}
43 	}
44 	b_char(" ", value, vlen);
45 	return(0);
46 }
47