blob: 2531d5a235081096faec61e0c447ea84b041f3aa [file] [log] [blame]
"Robert P. J. Day"63fc1a92006-07-02 19:47:05 +00001/* vi: set sw=4 ts=4: */
Mike Frysinger6d1d2e52005-04-21 23:23:13 +00002/*
3 * printenv implementation for busybox
4 *
5 * Copyright (C) 2005 by Erik Andersen <andersen@codepoet.org>
6 * Copyright (C) 2005 by Mike Frysinger <vapier@gentoo.org>
7 *
"Robert P. J. Day"801ab142006-07-12 07:56:04 +00008 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Mike Frysinger6d1d2e52005-04-21 23:23:13 +00009 */
10
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000011#include "libbb.h"
Denis Vlasenko5b340832007-05-17 23:02:14 +000012extern char **environ;
Mike Frysinger6d1d2e52005-04-21 23:23:13 +000013
Denis Vlasenko06af2162007-02-03 17:28:39 +000014int printenv_main(int argc, char **argv);
Mike Frysinger6d1d2e52005-04-21 23:23:13 +000015int printenv_main(int argc, char **argv)
16{
Mike Frysinger6d1d2e52005-04-21 23:23:13 +000017 int e = 0;
18
19 /* no variables specified, show whole env */
20 if (argc == 1)
21 while (environ[e])
22 puts(environ[e++]);
23
24 /* search for specified variables and print them out if found */
25 else {
26 int i;
27 size_t l;
28 char *arg, *env;
29
30 for (i=1; (arg = argv[i]); ++i)
31 for (; (env = environ[e]); ++e) {
32 l = strlen(arg);
33 if (!strncmp(env, arg, l) && env[l] == '=')
34 puts(env + l + 1);
35 }
36 }
37
Denis Vlasenkof0ed3762006-10-26 23:21:47 +000038 fflush_stdout_and_exit(0);
Mike Frysinger6d1d2e52005-04-21 23:23:13 +000039}