Mercurial > illumos > onarm
annotate usr/src/cmd/fmli/sys/getepenv.c @ 4:1a15d5aaf794
synchronized with onnv_86 (6202) in onnv-gate
author | Koji Uno <koji.uno@sun.com> |
---|---|
date | Mon, 31 Aug 2009 14:38:03 +0900 |
parents | c9caec207d52 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 * CDDL HEADER START | |
3 * | |
4 * The contents of this file are subject to the terms of the | |
5 * Common Development and Distribution License, Version 1.0 only | |
6 * (the "License"). You may not use this file except in compliance | |
7 * with the License. | |
8 * | |
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
10 * or http://www.opensolaris.org/os/licensing. | |
11 * See the License for the specific language governing permissions | |
12 * and limitations under the License. | |
13 * | |
14 * When distributing Covered Code, include this CDDL HEADER in each | |
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
16 * If applicable, add the following below this CDDL HEADER, with the | |
17 * fields enclosed by brackets "[]" replaced with your own identifying | |
18 * information: Portions Copyright [yyyy] [name of copyright owner] | |
19 * | |
20 * CDDL HEADER END | |
21 */ | |
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ | |
23 /* All Rights Reserved */ | |
24 | |
25 | |
26 /* | |
27 * Copyright (c) 1985 AT&T | |
28 * All Rights Reserved | |
29 */ | |
4
1a15d5aaf794
synchronized with onnv_86 (6202) in onnv-gate
Koji Uno <koji.uno@sun.com>
parents:
0
diff
changeset
|
30 #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.4 */ |
0 | 31 |
32 #include <stdio.h> | |
33 #include "wish.h" | |
34 #include "moremacros.h" | |
35 #include "sizes.h" | |
36 | |
37 /* | |
38 * getepenv looks for name=value in environment and in $HOME/pref/.environ | |
39 * If not present, return NULL. | |
40 */ | |
41 char * | |
42 getepenv(name) | |
43 char *name; | |
44 { | |
45 char path[PATHSIZ]; | |
46 register char *ptr; | |
47 extern char *Home; | |
48 char *anyenv(); | |
49 char *getenv(); | |
50 | |
51 if ((ptr = getAltenv(name)) || (ptr = getenv(name))) | |
52 return strsave(ptr); | |
53 strcpy(path, Home); | |
54 strcat(path, "/pref/.environ"); | |
55 return anyenv(path, name); | |
56 } | |
57 | |
58 /* | |
59 * anyenv lloks in path for name=value and returns value | |
60 * value is backslash processed and expanded before it is returned | |
61 */ | |
62 char * | |
63 anyenv(path, name) | |
64 char *path; | |
65 char *name; | |
66 { | |
67 char buf[BUFSIZ]; | |
68 char fpbuf[BUFSIZ]; | |
69 register char *ptr; | |
70 register int c; | |
71 register FILE *fp; | |
72 char *fgets(); | |
73 char *expand(); | |
74 char *unbackslash(); | |
75 | |
76 if ((fp = fopen(path, "r")) == NULL) | |
77 return NULL; | |
78 setbuf(fp, fpbuf); | |
79 /* for (each line of .environ file) */ | |
80 for (c = !EOF; c != EOF; ) { | |
81 ptr = name; | |
82 while (*ptr && (c = getc(fp)) == *ptr) | |
83 ptr++; | |
84 /* if ("name=" found) get rest of line */ | |
85 if (*ptr == '\0' && (c = getc(fp)) == '=' && fgets(buf, sizeof(buf), fp)) { | |
86 if (buf[c = strlen(buf) - 1] == '\n') | |
87 buf[c] = '\0'; | |
88 fclose(fp); | |
89 return expand(unbackslash(buf)); | |
90 } | |
91 /* skip rest of line */ | |
92 while (c != EOF && c != '\n') | |
93 c = getc(fp); | |
94 } | |
95 fclose(fp); | |
96 return NULL; | |
97 } |