use /tmp/resolv.conf when using a static nameserver (#177)
[openwrt.git] / package / nvram / src / main.c
1 /*
2 * Frontend command-line utility for Linux NVRAM layer
3 *
4 * Copyright 2004, Broadcom Corporation
5 * All Rights Reserved.
6 *
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
11 *
12 * $Id$
13 */
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18
19 #include <typedefs.h>
20 #include <bcmnvram.h>
21
22 static void
23 usage(void)
24 {
25 fprintf(stderr, "usage: nvram [get name] [set name=value] [unset name] [show]\n");
26 exit(0);
27 }
28
29 /* NVRAM utility */
30 int
31 main(int argc, char **argv)
32 {
33 char *name, *value, buf[NVRAM_SPACE];
34 int size;
35
36 /* Skip program name */
37 --argc;
38 ++argv;
39
40 if (!*argv)
41 usage();
42
43 /* Process the remaining arguments. */
44 for (; *argv; argv++) {
45 if (!strncmp(*argv, "get", 3)) {
46 if (*++argv) {
47 if ((value = nvram_get(*argv)))
48 puts(value);
49 }
50 }
51 else if (!strncmp(*argv, "set", 3)) {
52 if (*++argv) {
53 strncpy(value = buf, *argv, sizeof(buf));
54 name = strsep(&value, "=");
55 nvram_set(name, value);
56 }
57 }
58 else if (!strncmp(*argv, "unset", 5)) {
59 if (*++argv)
60 nvram_unset(*argv);
61 }
62 else if (!strncmp(*argv, "commit", 5)) {
63 nvram_commit();
64 }
65 else if (!strncmp(*argv, "show", 4) ||
66 !strncmp(*argv, "getall", 6)) {
67 nvram_getall(buf, sizeof(buf));
68 for (name = buf; *name; name += strlen(name) + 1)
69 puts(name);
70 size = sizeof(struct nvram_header) + (int) name - (int) buf;
71 fprintf(stderr, "size: %d bytes (%d left)\n", size, NVRAM_SPACE - size);
72 }
73 if (!*argv)
74 break;
75 }
76
77 return 0;
78 }
This page took 0.047407 seconds and 5 git commands to generate.