OpenCoverage

basename.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/basename.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8static struct option const longopts[] =-
9{-
10 {"multiple", -
11 0-
12 , -
13 ((void *)0)-
14 , 'a'},-
15 {"suffix", -
16 1-
17 , -
18 ((void *)0)-
19 , 's'},-
20 {"zero", -
21 0-
22 , -
23 ((void *)0)-
24 , 'z'},-
25 {"help", -
26 0-
27 , -
28 ((void *)0)-
29 , GETOPT_HELP_CHAR},-
30 {"version", -
31 0-
32 , -
33 ((void *)0)-
34 , GETOPT_VERSION_CHAR},-
35 {-
36 ((void *)0)-
37 , 0, -
38 ((void *)0)-
39 , 0}-
40};-
41-
42void-
43usage (int status)-
44{-
45 if (status !=
status != 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • basename
FALSEevaluated 9 times by 1 test
Evaluated by:
  • basename
5-9
46 0
status != 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • basename
FALSEevaluated 9 times by 1 test
Evaluated by:
  • basename
5-9
47 )-
48 do { fprintf (-
49 stderr-
50 , -
51 dcgettext (((void *)0), -
52 "Try '%s --help' for more information.\n"-
53 , 5)-
54 , program_name); }
executed 5 times by 1 test: end of block
Executed by:
  • basename
while (0);
5
55 else-
56 {-
57 printf (-
58 dcgettext (((void *)0), -
59 "Usage: %s NAME [SUFFIX]\n or: %s OPTION... NAME...\n"-
60 , 5)-
61-
62-
63 -
64 ,-
65 program_name, program_name);-
66 fputs_unlocked (-
67 dcgettext (((void *)0), -
68 "Print NAME with any leading directory components removed.\nIf specified, also remove a trailing SUFFIX.\n"-
69 , 5)-
70 ,-
71 stdout-
72 )-
73-
74-
75 ;-
76-
77 emit_mandatory_arg_note ();-
78-
79 fputs_unlocked (-
80 dcgettext (((void *)0), -
81 " -a, --multiple support multiple arguments and treat each as a NAME\n -s, --suffix=SUFFIX remove a trailing SUFFIX; implies -a\n -z, --zero end each output line with NUL, not newline\n"-
82 , 5)-
83 ,-
84 stdout-
85 )-
86-
87-
88-
89 ;-
90 fputs_unlocked (-
91 dcgettext (((void *)0), -
92 " --help display this help and exit\n"-
93 , 5)-
94 ,-
95 stdout-
96 );-
97 fputs_unlocked (-
98 dcgettext (((void *)0), -
99 " --version output version information and exit\n"-
100 , 5)-
101 ,-
102 stdout-
103 );-
104 printf (-
105 dcgettext (((void *)0), -
106 "\nExamples:\n %s /usr/bin/sort -> \"sort\"\n %s include/stdio.h .h -> \"stdio\"\n %s -s .h include/stdio.h -> \"stdio\"\n %s -a any/str1 any/str2 -> \"str1\" followed by \"str2\"\n"-
107 , 5)-
108-
109-
110-
111-
112-
113-
114 -
115 ,-
116 program_name, program_name, program_name, program_name);-
117 emit_ancillary_info ("basename");-
118 }
executed 9 times by 1 test: end of block
Executed by:
  • basename
9
119 exit (status);
executed 14 times by 1 test: exit (status);
Executed by:
  • basename
14
120}-
121-
122-
123-
124-
125static void-
126remove_suffix (char *name, const char *suffix)-
127{-
128 char *np;-
129 const char *sp;-
130-
131 np = name + strlen (name);-
132 sp = suffix + strlen (suffix);-
133-
134 while (np > name
np > nameDescription
TRUEevaluated 31 times by 1 test
Evaluated by:
  • basename
FALSEevaluated 1 time by 1 test
Evaluated by:
  • basename
&& sp > suffix
sp > suffixDescription
TRUEevaluated 20 times by 1 test
Evaluated by:
  • basename
FALSEevaluated 11 times by 1 test
Evaluated by:
  • basename
)
1-31
135 if (*--
*--np != *--spDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • basename
FALSEevaluated 17 times by 1 test
Evaluated by:
  • basename
np != *--sp
*--np != *--spDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • basename
FALSEevaluated 17 times by 1 test
Evaluated by:
  • basename
)
3-17
136 return;
executed 3 times by 1 test: return;
Executed by:
  • basename
3
137 if (np > name
np > nameDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • basename
FALSEevaluated 1 time by 1 test
Evaluated by:
  • basename
)
1-11
138 *
executed 11 times by 1 test: *np = '\0';
Executed by:
  • basename
np = '\0';
executed 11 times by 1 test: *np = '\0';
Executed by:
  • basename
11
139}
executed 12 times by 1 test: end of block
Executed by:
  • basename
12
140-
141-
142-
143-
144static void-
145perform_basename (const char *string, const char *suffix, -
146 _Bool -
147 use_nuls)-
148{-
149 char *name = base_name (string);-
150 strip_trailing_slashes (name);-
151-
152-
153-
154-
155-
156-
157-
158 if (suffix
suffixDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • basename
FALSEevaluated 23 times by 1 test
Evaluated by:
  • basename
&& (! ((((
(((name)[0]) == '/')Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • basename
FALSEevaluated 15 times by 1 test
Evaluated by:
  • basename
name)[0]) == '/')
(((name)[0]) == '/')Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • basename
FALSEevaluated 15 times by 1 test
Evaluated by:
  • basename
|| 0 != 0
0 != 0Description
TRUEnever evaluated
FALSEevaluated 15 times by 1 test
Evaluated by:
  • basename
)) && ! 0)
0-23
159 remove_suffix (name, suffix);
executed 15 times by 1 test: remove_suffix (name, suffix);
Executed by:
  • basename
15
160-
161 fputs_unlocked (name,-
162 stdout-
163 );-
164 putchar_unlocked (use_nuls ? '\0' : '\n');-
165 free (name);-
166}
executed 40 times by 1 test: end of block
Executed by:
  • basename
40
167-
168int-
169main (int argc, char **argv)-
170{-
171 -
172 _Bool -
173 multiple_names = -
174 0-
175 ;-
176 -
177 _Bool -
178 use_nuls = -
179 0-
180 ;-
181 const char *suffix = -
182 ((void *)0)-
183 ;-
184-
185 ;-
186 set_program_name (argv[0]);-
187 setlocale (-
188 6-
189 , "");-
190 bindtextdomain ("coreutils", "/usr/local/share/locale");-
191 textdomain ("coreutils");-
192-
193 atexit (close_stdout);-
194-
195 while (-
196 1-
197 )-
198 {-
199 int c = getopt_long (argc, argv, "+as:z", longopts, -
200 ((void *)0)-
201 );-
202-
203 if (c == -1
c == -1Description
TRUEevaluated 38 times by 1 test
Evaluated by:
  • basename
FALSEevaluated 31 times by 1 test
Evaluated by:
  • basename
)
31-38
204 break;
executed 38 times by 1 test: break;
Executed by:
  • basename
38
205-
206 switch (c)-
207 {-
208 case
executed 4 times by 1 test: case 's':
Executed by:
  • basename
's':
executed 4 times by 1 test: case 's':
Executed by:
  • basename
4
209 suffix = optarg;-
210-
211 ((void) 0);-
212-
213 case
executed 4 times by 1 test: case 'a':
Executed by:
  • basename
'a':
executed 4 times by 1 test: case 'a':
Executed by:
  • basename
code before this statement executed 4 times by 1 test: case 'a':
Executed by:
  • basename
4
214 multiple_names = -
215 1-
216 ;-
217 break;
executed 8 times by 1 test: break;
Executed by:
  • basename
8
218-
219 case
executed 7 times by 1 test: case 'z':
Executed by:
  • basename
'z':
executed 7 times by 1 test: case 'z':
Executed by:
  • basename
7
220 use_nuls = -
221 1-
222 ;-
223 break;
executed 7 times by 1 test: break;
Executed by:
  • basename
7
224-
225 case
executed 9 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • basename
GETOPT_HELP_CHAR:
executed 9 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • basename
usage (
9
226 0-
227 ); break;
never executed: break;
;
0
228 case
executed 4 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • basename
GETOPT_VERSION_CHAR:
executed 4 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • basename
version_etc (
4
229 stdout-
230 , "basename", "GNU coreutils", Version, ("David MacKenzie"), (char *) -
231 ((void *)0)-
232 ); exit (
executed 4 times by 1 test: exit ( 0 );
Executed by:
  • basename
4
233 0
executed 4 times by 1 test: exit ( 0 );
Executed by:
  • basename
4
234 );
executed 4 times by 1 test: exit ( 0 );
Executed by:
  • basename
break;
never executed: break;
;
0-4
235-
236 default
executed 3 times by 1 test: default:
Executed by:
  • basename
:
executed 3 times by 1 test: default:
Executed by:
  • basename
3
237 usage (-
238 1-
239 );-
240 }
never executed: end of block
0
241 }-
242-
243 if (argc < optind + 1
argc < optind + 1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • basename
FALSEevaluated 37 times by 1 test
Evaluated by:
  • basename
)
1-37
244 {-
245 error (0, 0, -
246 dcgettext (((void *)0), -
247 "missing operand"-
248 , 5)-
249 );-
250 usage (-
251 1-
252 );-
253 }
never executed: end of block
0
254-
255 if (!multiple_names
!multiple_namesDescription
TRUEevaluated 33 times by 1 test
Evaluated by:
  • basename
FALSEevaluated 4 times by 1 test
Evaluated by:
  • basename
&& optind + 2 < argc
optind + 2 < argcDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • basename
FALSEevaluated 32 times by 1 test
Evaluated by:
  • basename
)
1-33
256 {-
257 error (0, 0, -
258 dcgettext (((void *)0), -
259 "extra operand %s"-
260 , 5)-
261 , quote (argv[optind + 2]));-
262 usage (-
263 1-
264 );-
265 }
never executed: end of block
0
266-
267 if (multiple_names
multiple_namesDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • basename
FALSEevaluated 32 times by 1 test
Evaluated by:
  • basename
)
4-32
268 {-
269 for (; optind < argc
optind < argcDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • basename
FALSEevaluated 4 times by 1 test
Evaluated by:
  • basename
; optind++)
4-8
270 perform_basename (argv[optind], suffix, use_nuls);
executed 8 times by 1 test: perform_basename (argv[optind], suffix, use_nuls);
Executed by:
  • basename
8
271 }
executed 4 times by 1 test: end of block
Executed by:
  • basename
4
272 else-
273 perform_basename (argv[optind],
executed 32 times by 1 test: perform_basename (argv[optind], optind + 2 == argc ? argv[optind + 1] : ((void *)0) , use_nuls);
Executed by:
  • basename
32
274 optind + 2 == argc ? argv[optind + 1] :
executed 32 times by 1 test: perform_basename (argv[optind], optind + 2 == argc ? argv[optind + 1] : ((void *)0) , use_nuls);
Executed by:
  • basename
32
275 ((void *)0)
executed 32 times by 1 test: perform_basename (argv[optind], optind + 2 == argc ? argv[optind + 1] : ((void *)0) , use_nuls);
Executed by:
  • basename
32
276 , use_nuls);
executed 32 times by 1 test: perform_basename (argv[optind], optind + 2 == argc ? argv[optind + 1] : ((void *)0) , use_nuls);
Executed by:
  • basename
32
277-
278 return
executed 36 times by 1 test: return 0 ;
Executed by:
  • basename
executed 36 times by 1 test: return 0 ;
Executed by:
  • basename
36
279 0
executed 36 times by 1 test: return 0 ;
Executed by:
  • basename
36
280 ;
executed 36 times by 1 test: return 0 ;
Executed by:
  • basename
36
281}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.1.2