FreeBSD/Linux Kernel Cross Reference
sys/ipsc/bootenv.c
1 /*
2 * Mach Operating System
3 * Copyright (c) 1991 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26 /*
27 * Copyright 1988, 1989, 1990, 1991 by Intel Corporation,
28 * Santa Clara, California.
29 *
30 * All Rights Reserved
31 *
32 * Permission to use, copy, modify, and distribute this software and its
33 * documentation for any purpose and without fee is hereby granted,
34 * provided that the above copyright notice appears in all copies and that
35 * both the copyright notice and this permission notice appear in
36 * supporting documentation, and that the name of Intel not be used in
37 * advertising or publicity pertaining to distribution of the software
38 * without specific, written prior permission.
39 *
40 * INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING
41 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
42 * SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL
43 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
44 * PROFITS, WHETHER IN ACTION OF CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS
45 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
46 * THIS SOFTWARE.
47 */
48 /*
49 * HISTORY
50 * $Log: bootenv.c,v $
51 * Revision 2.2 91/12/10 16:32:26 jsb
52 * New files from Intel
53 * [91/12/10 16:12:46 jsb]
54 *
55 */
56
57 /*
58 * andyp
59 */
60
61 #define MAXENVSIZE 1024 /* I checked w/ bootcube sources */
62
63 char **bootenv = 0;
64
65 /*
66 * Save the Environment!
67 *
68 * Apparently, the pointer passed to us points to a single
69 * string with embedded newlines. eg:
70 *
71 * char *bnv = "BOOT_MY_NODE=002\nBOOT_INIT_NODE=3\n...";
72 *
73 * We need to make it look like an "ordinary" environment.
74 */
75 char **envcopy(bnv)
76 char *bnv;
77 {
78 static char saveenv[MAXENVSIZE];
79 char **env, *src, *dst, c;
80 int i, len, nl, pspc;
81
82 if (!bnv) {
83 env = (char **) saveenv;
84 env[0] = 0;
85 bootenv = (char **) env;
86 return bootenv;
87 }
88
89 /*
90 * find the length and the number of newlines
91 */
92 len = nl = 0;
93 src = bnv;
94 while ((c = *src++)) {
95 len++;
96 if (c == '\n')
97 nl++;
98 }
99
100 /*
101 * sanity check
102 */
103 pspc = (nl + 1) * sizeof(char *);
104 if ((len + pspc) > MAXENVSIZE)
105 panic("envcopy: bootenv is too big");
106
107
108 /*
109 * copy the strings, substituting 0 for '\n'.
110 */
111 env = (char **) saveenv;
112 src = bnv;
113 dst = &saveenv[pspc];
114 for (i = 0; i < nl; i++) {
115 *env++ = dst;
116 while ((c = *src++) != '\n')
117 *dst++ = c;
118 *dst++ = 0;
119 }
120 *env = 0;
121
122 bootenv = (char **) saveenv;
123 return bootenv;
124 }
125
126
127 /*
128 * funny string compare
129 */
130 static char *upto(a, b, t)
131 char *a, *b, t;
132 {
133 char c1, c2;
134
135 for (;;) {
136 c1 = *a++;
137 c2 = *b++;
138 if ((c1 == t) && (c2 == 0))
139 return a;
140 if (c1 != c2)
141 return (char *) 0;
142 if ((c1 == 0) || (c2 == 0))
143 return (char *) 0;
144 }
145 /*NOTREACHED*/
146 }
147
148
149 /*
150 * similar to getenv()
151 */
152 char *getbootenv(var)
153 char *var;
154 {
155 char *val, **env;
156
157 for (env = bootenv; *env; ++env) {
158 if ((val = upto(*env, var, '=')))
159 return val;
160 }
161
162 return (char *) 0;
163 }
164
165
166 #define PASS_BOOT_MAGIC 0
167
168 /*
169 * Collapse the boot environment into one big string.
170 */
171 char *ipsc_boot_environ()
172 {
173 static char saveenv[MAXENVSIZE];
174 char *s, **ep = bootenv;
175 int len;
176
177 #if PASS_BOOT_MAGIC
178 s = saveenv;
179 s[0] = 0;
180 while (*ep) {
181 len = strlen(*ep);
182 strcpy(s, *ep);
183 s[len] = '\n';
184 s += (len + 1);
185 s[0] = 0;
186 ep++;
187 }
188
189 return saveenv;
190 #else /* PASS_BOOT_MAGIC */
191 return (char *) 0;
192 #endif /* PASS_BOOT_MAGIC */
193 }
Cache object: 0804acacf2017129d738a175c28062bc
|