OpenCoverage

printenv.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/printenv.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* printenv -- print all or part of environment-
2 Copyright (C) 1989-2018 Free Software Foundation, Inc.-
3-
4 This program is free software: you can redistribute it and/or modify-
5 it under the terms of the GNU General Public License as published by-
6 the Free Software Foundation, either version 3 of the License, or-
7 (at your option) any later version.-
8-
9 This program is distributed in the hope that it will be useful,-
10 but WITHOUT ANY WARRANTY; without even the implied warranty of-
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
12 GNU General Public License for more details.-
13-
14 You should have received a copy of the GNU General Public License-
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */-
16-
17/* Usage: printenv [variable...]-
18-
19 If no arguments are given, print the entire environment.-
20 If one or more variable names are given, print the value of-
21 each one that is set, and nothing for ones that are not set.-
22-
23 Exit status:-
24 0 if all variables specified were found-
25 1 if not-
26 2 if some other error occurred-
27-
28 David MacKenzie and Richard Mlynarik */-
29-
30#include <config.h>-
31#include <stdio.h>-
32#include <sys/types.h>-
33#include <getopt.h>-
34-
35#include "system.h"-
36-
37/* Exit status for syntax errors, etc. */-
38enum { PRINTENV_FAILURE = 2 };-
39-
40/* The official name of this program (e.g., no 'g' prefix). */-
41#define PROGRAM_NAME "printenv"-
42-
43#define AUTHORS \-
44 proper_name ("David MacKenzie"), \-
45 proper_name ("Richard Mlynarik")-
46-
47static struct option const longopts[] =-
48{-
49 {"null", no_argument, NULL, '0'},-
50 {GETOPT_HELP_OPTION_DECL},-
51 {GETOPT_VERSION_OPTION_DECL},-
52 {NULL, 0, NULL, 0}-
53};-
54-
55void-
56usage (int status)-
57{-
58 if (status != EXIT_SUCCESS)
status != 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • printenv
FALSEevaluated 5 times by 1 test
Evaluated by:
  • printenv
3-5
59 emit_try_help ();
executed 3 times by 1 test: end of block
Executed by:
  • printenv
3
60 else-
61 {-
62 printf (_("\-
63Usage: %s [OPTION]... [VARIABLE]...\n\-
64Print the values of the specified environment VARIABLE(s).\n\-
65If no VARIABLE is specified, print name and value pairs for them all.\n\-
66\n\-
67"),-
68 program_name);-
69 fputs (_("\-
70 -0, --null end each output line with NUL, not newline\n\-
71"), stdout);-
72 fputs (HELP_OPTION_DESCRIPTION, stdout);-
73 fputs (VERSION_OPTION_DESCRIPTION, stdout);-
74 printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME);-
75 emit_ancillary_info (PROGRAM_NAME);-
76 }
executed 5 times by 1 test: end of block
Executed by:
  • printenv
5
77 exit (status);
executed 8 times by 1 test: exit (status);
Executed by:
  • printenv
8
78}-
79-
80int-
81main (int argc, char **argv)-
82{-
83 char **env;-
84 char *ep, *ap;-
85 int i;-
86 bool ok;-
87 int optc;-
88 bool opt_nul_terminate_output = false;-
89-
90 initialize_main (&argc, &argv);-
91 set_program_name (argv[0]);-
92 setlocale (LC_ALL, "");-
93 bindtextdomain (PACKAGE, LOCALEDIR);-
94 textdomain (PACKAGE);-
95-
96 initialize_exit_failure (PRINTENV_FAILURE);-
97 atexit (close_stdout);-
98-
99 while ((optc = getopt_long (argc, argv, "+iu:0", longopts, NULL)) != -1)
(optc = getopt... *)0) )) != -1Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • printenv
FALSEevaluated 16 times by 1 test
Evaluated by:
  • printenv
16-20
100 {-
101 switch (optc)-
102 {-
103 case '0':
executed 7 times by 1 test: case '0':
Executed by:
  • printenv
7
104 opt_nul_terminate_output = true;-
105 break;
executed 7 times by 1 test: break;
Executed by:
  • printenv
7
106 case_GETOPT_HELP_CHAR;
never executed: break;
executed 5 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • printenv
0-5
107 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
executed 5 times by 1 test: exit ( 0 );
Executed by:
  • printenv
never executed: break;
executed 5 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • printenv
0-5
108 default:
executed 3 times by 1 test: default:
Executed by:
  • printenv
3
109 usage (PRINTENV_FAILURE);-
110 }
never executed: end of block
0
111 }-
112-
113 if (optind >= argc)
optind >= argcDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • printenv
FALSEevaluated 11 times by 1 test
Evaluated by:
  • printenv
5-11
114 {-
115 for (env = environ; *env != NULL; ++env)
*env != ((void *)0)Description
TRUEevaluated 185 times by 1 test
Evaluated by:
  • printenv
FALSEevaluated 5 times by 1 test
Evaluated by:
  • printenv
5-185
116 printf ("%s%c", *env, opt_nul_terminate_output ? '\0' : '\n');
executed 185 times by 1 test: printf ("%s%c", *env, opt_nul_terminate_output ? '\0' : '\n');
Executed by:
  • printenv
185
117 ok = true;-
118 }
executed 5 times by 1 test: end of block
Executed by:
  • printenv
5
119 else-
120 {-
121 int matches = 0;-
122-
123 for (i = optind; i < argc; ++i)
i < argcDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • printenv
FALSEevaluated 11 times by 1 test
Evaluated by:
  • printenv
11-17
124 {-
125 bool matched = false;-
126-
127 /* 'printenv a=b' is silent, even if 'a=b=c' is in environ. */-
128 if (strchr (argv[i], '='))
(__extension__...v[i] , '=' )))Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • printenv
FALSEevaluated 16 times by 1 test
Evaluated by:
  • printenv
__builtin_constant_p ( '=' )Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • printenv
FALSEnever evaluated
!__builtin_con..._p ( argv[i] )Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • printenv
FALSEnever evaluated
( '=' ) == '\0'Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • printenv
0-17
129 continue;
executed 1 time by 1 test: continue;
Executed by:
  • printenv
1
130-
131 for (env = environ; *env; ++env)
*envDescription
TRUEevaluated 995 times by 1 test
Evaluated by:
  • printenv
FALSEevaluated 16 times by 1 test
Evaluated by:
  • printenv
16-995
132 {-
133 ep = *env;-
134 ap = argv[i];-
135 while (*ep != '\0' && *ap != '\0' && *ep++ == *ap++)
*ep != '\0'Description
TRUEevaluated 1147 times by 1 test
Evaluated by:
  • printenv
FALSEnever evaluated
*ap != '\0'Description
TRUEevaluated 1137 times by 1 test
Evaluated by:
  • printenv
FALSEevaluated 10 times by 1 test
Evaluated by:
  • printenv
*ep++ == *ap++Description
TRUEevaluated 163 times by 1 test
Evaluated by:
  • printenv
FALSEevaluated 974 times by 1 test
Evaluated by:
  • printenv
0-1147
136 {-
137 if (*ep == '=' && *ap == '\0')
*ep == '='Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • printenv
FALSEevaluated 152 times by 1 test
Evaluated by:
  • printenv
*ap == '\0'Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • printenv
FALSEnever evaluated
0-152
138 {-
139 printf ("%s%c", ep + 1,-
140 opt_nul_terminate_output ? '\0' : '\n');-
141 matched = true;-
142 break;
executed 11 times by 1 test: break;
Executed by:
  • printenv
11
143 }-
144 }
executed 152 times by 1 test: end of block
Executed by:
  • printenv
152
145 }
executed 995 times by 1 test: end of block
Executed by:
  • printenv
995
146-
147 matches += matched;-
148 }
executed 16 times by 1 test: end of block
Executed by:
  • printenv
16
149-
150 ok = (matches == argc - optind);-
151 }
executed 11 times by 1 test: end of block
Executed by:
  • printenv
11
152-
153 return ok ? EXIT_SUCCESS : EXIT_FAILURE;
executed 16 times by 1 test: return ok ? 0 : 1 ;
Executed by:
  • printenv
16
154}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2