Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/coreutils/printenv.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 532 by niro, Sat Sep 1 22:45:15 2007 UTC revision 984 by niro, Sun May 30 11:32:42 2010 UTC
# Line 8  Line 8 
8   * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.   * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
9   */   */
10    
11  #include <stdio.h>  #include "libbb.h"
 #include <string.h>  
 #include <stdlib.h>  
 #include "busybox.h"  
12    
13  int printenv_main(int argc, char **argv)  int printenv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
14    int printenv_main(int argc UNUSED_PARAM, char **argv)
15  {  {
16   extern char **environ;   int exit_code = EXIT_SUCCESS;
  int e = 0;  
17    
18   /* no variables specified, show whole env */   /* no variables specified, show whole env */
19   if (argc == 1)   if (!argv[1]) {
20     int e = 0;
21   while (environ[e])   while (environ[e])
22   puts(environ[e++]);   puts(environ[e++]);
23     } else {
24   /* search for specified variables and print them out if found */   /* search for specified variables and print them out if found */
  else {  
  int i;  
  size_t l;  
25   char *arg, *env;   char *arg, *env;
26    
27   for (i=1; (arg = argv[i]); ++i)   while ((arg = *++argv) != NULL) {
28   for (; (env = environ[e]); ++e) {   env = getenv(arg);
29   l = strlen(arg);   if (env)
30   if (!strncmp(env, arg, l) && env[l] == '=')   puts(env);
31   puts(env + l + 1);   else
32   }   exit_code = EXIT_FAILURE;
33     }
34   }   }
35    
36   fflush_stdout_and_exit(0);   fflush_stdout_and_exit(exit_code);
37  }  }

Legend:
Removed from v.532  
changed lines
  Added in v.984