HardenedBSD/contrib/libf2c/libF77/getenv_.c

57 lines
1.1 KiB
C
Raw Normal View History

1999-09-18 12:51:31 +02:00
#include "f2c.h"
1999-09-19 07:59:11 +02:00
#undef abs
#ifdef KR_headers
extern char *F77_aloc(), *getenv();
#else
#include <stdlib.h>
#include <string.h>
extern char *F77_aloc(ftnlen, char*);
#endif
1999-09-18 12:51:31 +02:00
/*
* getenv - f77 subroutine to return environment variables
*
* called by:
* call getenv (ENV_NAME, char_var)
* where:
* ENV_NAME is the name of an environment variable
* char_var is a character variable which will receive
* the current value of ENV_NAME, or all blanks
* if ENV_NAME is not defined
*/
#ifdef KR_headers
1999-09-19 07:59:11 +02:00
VOID
G77_getenv_0 (fname, value, flen, vlen) char *value, *fname; ftnlen vlen, flen;
1999-09-18 12:51:31 +02:00
#else
1999-09-19 07:59:11 +02:00
void
G77_getenv_0 (char *fname, char *value, ftnlen flen, ftnlen vlen)
1999-09-18 12:51:31 +02:00
#endif
{
1999-09-19 07:59:11 +02:00
char buf[256], *ep, *fp;
integer i;
1999-09-18 12:51:31 +02:00
1999-09-19 07:59:11 +02:00
if (flen <= 0)
goto add_blanks;
for(i = 0; i < sizeof(buf); i++) {
if (i == flen || (buf[i] = fname[i]) == ' ') {
buf[i] = 0;
ep = getenv(buf);
goto have_ep;
}
1999-09-18 12:51:31 +02:00
}
1999-09-19 07:59:11 +02:00
while(i < flen && fname[i] != ' ')
i++;
strncpy(fp = F77_aloc(i+1, "getenv_"), fname, (int)i);
fp[i] = 0;
ep = getenv(fp);
free(fp);
have_ep:
if (ep)
while(*ep && vlen-- > 0)
1999-09-18 12:51:31 +02:00
*value++ = *ep++;
1999-09-19 07:59:11 +02:00
add_blanks:
while(vlen-- > 0)
1999-09-18 12:51:31 +02:00
*value++ = ' ';
1999-09-19 07:59:11 +02:00
}