1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
Index: coreutils/Makefile.in
===================================================================
--- coreutils/Makefile.in (revision 10146)
+++ coreutils/Makefile.in (revision 10147)
@@ -60,6 +60,7 @@
COREUTILS-$(CONFIG_MV) += mv.o
COREUTILS-$(CONFIG_NICE) += nice.o
COREUTILS-$(CONFIG_OD) += od.o
+COREUTILS-$(CONFIG_PRINTENV) += printenv.o
COREUTILS-$(CONFIG_PRINTF) += printf.o
COREUTILS-$(CONFIG_PWD) += pwd.o
COREUTILS-$(CONFIG_REALPATH) += realpath.o
Index: coreutils/printenv.c
===================================================================
--- coreutils/printenv.c (revision 0)
+++ coreutils/printenv.c (revision 10147)
@@ -0,0 +1,52 @@
+/*
+ * printenv implementation for busybox
+ *
+ * Copyright (C) 2005 by Erik Andersen <andersen@codepoet.org>
+ * Copyright (C) 2005 by Mike Frysinger <vapier@gentoo.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+int printenv_main(int argc, char **argv)
+{
+ extern char **environ;
+ int e = 0;
+
+ /* no variables specified, show whole env */
+ if (argc == 1)
+ while (environ[e])
+ puts(environ[e++]);
+
+ /* search for specified variables and print them out if found */
+ else {
+ int i;
+ size_t l;
+ char *arg, *env;
+
+ for (i=1; (arg = argv[i]); ++i)
+ for (; (env = environ[e]); ++e) {
+ l = strlen(arg);
+ if (!strncmp(env, arg, l) && env[l] == '=')
+ puts(env + l + 1);
+ }
+ }
+
+ exit(EXIT_SUCCESS);
+}
Index: coreutils/Config.in
===================================================================
--- coreutils/Config.in (revision 10146)
+++ coreutils/Config.in (revision 10147)
@@ -164,6 +164,12 @@
a command; without options it displays the current
environment.
+config CONFIG_PRINTENV
+ bool "printenv"
+ default n
+ help
+ printenv is used to print all or part of environment.
+
config CONFIG_EXPR
bool "expr"
default n
--- include/usage.h
+++ include/usage.h
@@ -1949,6 +1949,12 @@
"Options:\n" \
"\t-d\t\tdelay interval for shutting off."
+#define printenv_trivial_usage \
+ "[VARIABLES...]"
+#define printenv_full_usage \
+ "print all or part of environment\n\n" \
+ "If no environment VARIABLE specified, print them all."
+
#define printf_trivial_usage \
"FORMAT [ARGUMENT...]"
#define printf_full_usage \
--- include/applets.h
+++ include/applets.h
@@ -452,6 +452,9 @@
#ifdef CONFIG_POWEROFF
APPLET(poweroff, poweroff_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
#endif
+#ifdef CONFIG_PRINTENV
+ APPLET(printenv, printenv_main, _BB_DIR_BIN, _BB_SUID_NEVER)
+#endif
#ifdef CONFIG_PRINTF
APPLET(printf, printf_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
#endif
|