System V IPC code from Danny Boulet, chewed on a bit by the NetBSD group
[unix-history] / lib / libF77 / getenv_.c
CommitLineData
547779a8
WH
1#include "f2c.h"
2
3/*
4 * getenv - f77 subroutine to return environment variables
5 *
6 * called by:
7 * call getenv (ENV_NAME, char_var)
8 * where:
9 * ENV_NAME is the name of an environment variable
10 * char_var is a character variable which will receive
11 * the current value of ENV_NAME, or all blanks
12 * if ENV_NAME is not defined
13 */
14
15#ifdef KR_headers
16VOID getenv_(fname, value, flen, vlen) char *value, *fname; ftnlen vlen, flen;
17#else
18void getenv_(char *fname, char *value, ftnlen flen, ftnlen vlen)
19#endif
20{
21extern char **environ;
22register char *ep, *fp, *flast;
23register char **env = environ;
24
25flast = fname + flen;
26for(fp = fname ; fp < flast ; ++fp)
27 if(*fp == ' ')
28 {
29 flast = fp;
30 break;
31 }
32
33while (ep = *env++)
34 {
35 for(fp = fname; fp<flast ; )
36 if(*fp++ != *ep++)
37 goto endloop;
38
39 if(*ep++ == '=') { /* copy right hand side */
40 while( *ep && --vlen>=0 )
41 *value++ = *ep++;
42
43 goto blank;
44 }
45endloop: ;
46 }
47
48blank:
49 while( --vlen >= 0 )
50 *value++ = ' ';
51}