Fix core WST file
[jabaws.git] / binaries / src / fasta34 / getenv.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4
5 #define MAXENV 1024
6 char *envstr;
7
8 char *mgetenv(str)
9 char *str;
10 {
11         static int EnvInit=0;
12
13         char *eptr, *esptr, *bp;
14         int i,esize;
15         FILE *fenv;
16         
17         if (EnvInit==0) {
18                 EnvInit=1;
19                 if ((fenv=fopen("environment","r"))!=NULL) {
20                         if ((envstr=malloc((size_t)(esize=MAXENV)))==NULL) {
21                                 fclose(fenv); goto noenv;}
22                         esptr=envstr; esize -= 10;
23                         while (fgets(esptr,esize,fenv)!=NULL) {
24                                 if ((bp=strchr(esptr,'\n'))!=NULL) *bp='\0';
25                                 esize -= (i=strlen(esptr)+1);
26                                 esptr += i;
27                                 }
28                         fclose(fenv);
29                         esptr='\0';
30                         }
31                 else envstr=NULL;
32         }
33         
34         if (envstr==NULL) return NULL;
35         else {          
36                 for (eptr=envstr; *eptr; eptr += strlen(eptr)+1) {
37                         if (strncmp(str,eptr,(long)strlen(str))==0) {
38                                 return strchr(eptr,'=')+1;
39                                 }
40                         }
41                 return NULL;
42                 }
43 noenv:  envstr=NULL; return NULL;
44         }
45
46 strnpcpy(to,from,max)
47         char *to; Str255 from; size_t max;
48 {
49         size_t i, n;
50         
51         n = (*from<max) ? *from : max;
52         from++;
53
54         for (i=0; i<n; i++) *to++ = *from++;
55         if (n<max) *to='\0';
56         }