source: trunk/minix/commands/simple/sysenv.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 1.5 KB
Line 
1/* sysenv 1.0 - request system boot parameter Author: Kees J. Bot
2 * 23 Dec 2000
3 */
4#define nil ((void*)0)
5#include <sys/types.h>
6#include <sys/svrctl.h>
7#include <stdarg.h>
8#include <stdlib.h>
9#include <unistd.h>
10#include <errno.h>
11#include <string.h>
12
13#define NIL ((char*)0)
14
15static void tell(int fd, ...)
16{
17 va_list ap;
18 char *s;
19
20 va_start(ap, fd);
21 while ((s= va_arg(ap, char *)) != NIL) {
22 (void) write(fd, s, strlen(s));
23 }
24 va_end(ap);
25}
26
27int main(int argc, char **argv)
28{
29 struct sysgetenv sysgetenv;
30 int i;
31 int ex= 0;
32 char *e;
33 char val[1024];
34
35 i= 1;
36 while (i < argc && argv[i][0] == '-') {
37 char *opt= argv[i++]+1;
38
39 if (opt[0] == '-' && opt[1] == 0) break; /* -- */
40
41 if (*opt != 0) {
42 tell(2, "Usage: sysenv [name ...]\n", NIL);
43 exit(1);
44 }
45 }
46
47 do {
48 if (i < argc) {
49 sysgetenv.key= argv[i];
50 sysgetenv.keylen= strlen(sysgetenv.key) + 1;
51 } else {
52 sysgetenv.key= nil;
53 sysgetenv.keylen= 0;
54 }
55 sysgetenv.val= val;
56 sysgetenv.vallen= sizeof(val);
57
58 if (svrctl(MMGETPARAM, &sysgetenv) == -1) {
59 if (errno == ESRCH) {
60 ex |= 2;
61 } else {
62 ex |= 1;
63 tell(2, "sysenv: ", strerror(errno), "\n", NIL);
64 }
65 continue;
66 }
67
68 e= sysgetenv.val;
69 do {
70 e += strlen(e);
71 *e++ = '\n';
72 } while (i == argc && *e != 0);
73
74 if (write(1, sysgetenv.val, e - sysgetenv.val) < 0) {
75 ex |= 1;
76 tell(2, "sysenv: ", strerror(errno), "\n", NIL);
77 }
78 } while (++i < argc);
79 return ex;
80}
Note: See TracBrowser for help on using the repository browser.