OpenCoverage

rmdir.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/rmdir.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9static -
10 _Bool -
11 remove_empty_parents;-
12-
13-
14-
15static -
16 _Bool -
17 ignore_fail_on_non_empty;-
18-
19-
20static -
21 _Bool -
22 verbose;-
23-
24-
25-
26enum-
27{-
28 IGNORE_FAIL_ON_NON_EMPTY_OPTION = 0x7f + 1-
29};-
30-
31static struct option const longopts[] =-
32{-
33-
34-
35 {"ignore-fail-on-non-empty", -
36 0-
37 , -
38 ((void *)0)-
39 ,-
40 IGNORE_FAIL_ON_NON_EMPTY_OPTION},-
41-
42 {"path", -
43 0-
44 , -
45 ((void *)0)-
46 , 'p'},-
47 {"parents", -
48 0-
49 , -
50 ((void *)0)-
51 , 'p'},-
52 {"verbose", -
53 0-
54 , -
55 ((void *)0)-
56 , 'v'},-
57 {"help", -
58 0-
59 , -
60 ((void *)0)-
61 , GETOPT_HELP_CHAR},-
62 {"version", -
63 0-
64 , -
65 ((void *)0)-
66 , GETOPT_VERSION_CHAR},-
67 {-
68 ((void *)0)-
69 , 0, -
70 ((void *)0)-
71 , 0}-
72};-
73-
74-
75-
76static -
77 _Bool-
78-
79errno_rmdir_non_empty (int error_number)-
80{-
81 return
executed 1 time by 1 test: return error_number == 39 || error_number == 17 ;
Executed by:
  • rmdir
error_number ==
executed 1 time by 1 test: return error_number == 39 || error_number == 17 ;
Executed by:
  • rmdir
1
82 39
executed 1 time by 1 test: return error_number == 39 || error_number == 17 ;
Executed by:
  • rmdir
1
83 || error_number ==
executed 1 time by 1 test: return error_number == 39 || error_number == 17 ;
Executed by:
  • rmdir
1
84 17
executed 1 time by 1 test: return error_number == 39 || error_number == 17 ;
Executed by:
  • rmdir
1
85 ;
executed 1 time by 1 test: return error_number == 39 || error_number == 17 ;
Executed by:
  • rmdir
1
86}-
87-
88-
89-
90static -
91 _Bool-
92-
93errno_may_be_empty (int error_number)-
94{-
95 switch (error_number)-
96 {-
97 case
never executed: case 13 :
never executed: case 13 :
0
98 13
never executed: case 13 :
0
99 :
never executed: case 13 :
0
100 case
never executed: case 1 :
never executed: case 1 :
0
101 1
never executed: case 1 :
0
102 :
never executed: case 1 :
0
103 case
never executed: case 30 :
never executed: case 30 :
0
104 30
never executed: case 30 :
0
105 :
never executed: case 30 :
0
106 case
never executed: case 17 :
never executed: case 17 :
0
107 17
never executed: case 17 :
0
108 :
never executed: case 17 :
0
109 case
never executed: case 16 :
never executed: case 16 :
0
110 16
never executed: case 16 :
0
111 :
never executed: case 16 :
0
112 return
never executed: return 1 ;
never executed: return 1 ;
0
113 1
never executed: return 1 ;
0
114 ;
never executed: return 1 ;
0
115 default
never executed: default:
:
never executed: default:
0
116 return
never executed: return 0 ;
never executed: return 0 ;
0
117 0
never executed: return 0 ;
0
118 ;
never executed: return 0 ;
0
119 }-
120}-
121-
122-
123-
124static -
125 _Bool-
126-
127ignorable_failure (int error_number, char const *dir)-
128{-
129 return
executed 3 times by 1 test: return (ignore_fail_on_non_empty && (errno_rmdir_non_empty (error_number) || (errno_may_be_empty (error_number) && is_empty_dir ( -100 , dir))));
Executed by:
  • rmdir
(ignore_fail_on_non_empty
executed 3 times by 1 test: return (ignore_fail_on_non_empty && (errno_rmdir_non_empty (error_number) || (errno_may_be_empty (error_number) && is_empty_dir ( -100 , dir))));
Executed by:
  • rmdir
3
130 && (errno_rmdir_non_empty (error_number)
executed 3 times by 1 test: return (ignore_fail_on_non_empty && (errno_rmdir_non_empty (error_number) || (errno_may_be_empty (error_number) && is_empty_dir ( -100 , dir))));
Executed by:
  • rmdir
3
131 || (errno_may_be_empty (error_number)
executed 3 times by 1 test: return (ignore_fail_on_non_empty && (errno_rmdir_non_empty (error_number) || (errno_may_be_empty (error_number) && is_empty_dir ( -100 , dir))));
Executed by:
  • rmdir
3
132 && is_empty_dir (
executed 3 times by 1 test: return (ignore_fail_on_non_empty && (errno_rmdir_non_empty (error_number) || (errno_may_be_empty (error_number) && is_empty_dir ( -100 , dir))));
Executed by:
  • rmdir
3
133 -100
executed 3 times by 1 test: return (ignore_fail_on_non_empty && (errno_rmdir_non_empty (error_number) || (errno_may_be_empty (error_number) && is_empty_dir ( -100 , dir))));
Executed by:
  • rmdir
3
134 , dir))));
executed 3 times by 1 test: return (ignore_fail_on_non_empty && (errno_rmdir_non_empty (error_number) || (errno_may_be_empty (error_number) && is_empty_dir ( -100 , dir))));
Executed by:
  • rmdir
3
135}-
136-
137-
138-
139-
140-
141-
142static -
143 _Bool-
144-
145remove_parents (char *dir)-
146{-
147 char *slash;-
148 -
149 _Bool -
150 ok = -
151 1-
152 ;-
153-
154 strip_trailing_slashes (dir);-
155 while (1)-
156 {-
157 slash = strrchr (dir, '/');-
158 if (slash ==
slash == ((void *)0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • rmdir
FALSEevaluated 3 times by 1 test
Evaluated by:
  • rmdir
1-3
159 ((void *)0)
slash == ((void *)0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • rmdir
FALSEevaluated 3 times by 1 test
Evaluated by:
  • rmdir
1-3
160 )-
161 break;
executed 1 time by 1 test: break;
Executed by:
  • rmdir
1
162-
163-
164 while (slash > dir
slash > dirDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • rmdir
FALSEnever evaluated
&& *
*slash == '/'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • rmdir
FALSEevaluated 3 times by 1 test
Evaluated by:
  • rmdir
slash == '/'
*slash == '/'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • rmdir
FALSEevaluated 3 times by 1 test
Evaluated by:
  • rmdir
)
0-6
165 --
executed 3 times by 1 test: --slash;
Executed by:
  • rmdir
slash;
executed 3 times by 1 test: --slash;
Executed by:
  • rmdir
3
166 slash[1] = 0;-
167-
168-
169 if (verbose
verboseDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • rmdir
)
0-3
170 prog_fprintf (
never executed: prog_fprintf ( stdout , dcgettext (((void *)0), "removing directory, %s" , 5) , quotearg_style (shell_escape_always_quoting_style, dir));
0
171 stdout
never executed: prog_fprintf ( stdout , dcgettext (((void *)0), "removing directory, %s" , 5) , quotearg_style (shell_escape_always_quoting_style, dir));
0
172 ,
never executed: prog_fprintf ( stdout , dcgettext (((void *)0), "removing directory, %s" , 5) , quotearg_style (shell_escape_always_quoting_style, dir));
0
173 dcgettext (((void *)0),
never executed: prog_fprintf ( stdout , dcgettext (((void *)0), "removing directory, %s" , 5) , quotearg_style (shell_escape_always_quoting_style, dir));
0
174 "removing directory, %s"
never executed: prog_fprintf ( stdout , dcgettext (((void *)0), "removing directory, %s" , 5) , quotearg_style (shell_escape_always_quoting_style, dir));
0
175 , 5)
never executed: prog_fprintf ( stdout , dcgettext (((void *)0), "removing directory, %s" , 5) , quotearg_style (shell_escape_always_quoting_style, dir));
0
176 , quotearg_style (shell_escape_always_quoting_style, dir));
never executed: prog_fprintf ( stdout , dcgettext (((void *)0), "removing directory, %s" , 5) , quotearg_style (shell_escape_always_quoting_style, dir));
0
177-
178 ok = (rmdir (dir) == 0);-
179-
180 if (!ok
!okDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • rmdir
FALSEevaluated 1 time by 1 test
Evaluated by:
  • rmdir
)
1-2
181 {-
182-
183 if (ignorable_failure (
ignorable_fail...ion ()) , dir)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • rmdir
FALSEevaluated 1 time by 1 test
Evaluated by:
  • rmdir
1
184 (*__errno_location ())
ignorable_fail...ion ()) , dir)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • rmdir
FALSEevaluated 1 time by 1 test
Evaluated by:
  • rmdir
1
185 , dir)
ignorable_fail...ion ()) , dir)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • rmdir
FALSEevaluated 1 time by 1 test
Evaluated by:
  • rmdir
)
1
186 {-
187 ok = -
188 1-
189 ;-
190 }
executed 1 time by 1 test: end of block
Executed by:
  • rmdir
1
191 else-
192 {-
193-
194 error (0, -
195 (*__errno_location ())-
196 , -
197 dcgettext (((void *)0), -
198 "failed to remove directory %s"-
199 , 5)-
200 ,-
201 quotearg_style (shell_escape_always_quoting_style, dir));-
202 }
executed 1 time by 1 test: end of block
Executed by:
  • rmdir
1
203 break;
executed 2 times by 1 test: break;
Executed by:
  • rmdir
2
204 }-
205 }
executed 1 time by 1 test: end of block
Executed by:
  • rmdir
1
206 return
executed 3 times by 1 test: return ok;
Executed by:
  • rmdir
ok;
executed 3 times by 1 test: return ok;
Executed by:
  • rmdir
3
207}-
208-
209void-
210usage (int status)-
211{-
212 if (status !=
status != 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • rmdir
FALSEevaluated 8 times by 1 test
Evaluated by:
  • rmdir
3-8
213 0
status != 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • rmdir
FALSEevaluated 8 times by 1 test
Evaluated by:
  • rmdir
3-8
214 )-
215 do { fprintf (-
216 stderr-
217 , -
218 dcgettext (((void *)0), -
219 "Try '%s --help' for more information.\n"-
220 , 5)-
221 , program_name); }
executed 3 times by 1 test: end of block
Executed by:
  • rmdir
while (0);
3
222 else-
223 {-
224 printf (-
225 dcgettext (((void *)0), -
226 "Usage: %s [OPTION]... DIRECTORY...\n"-
227 , 5)-
228 , program_name);-
229 fputs_unlocked (-
230 dcgettext (((void *)0), -
231 "Remove the DIRECTORY(ies), if they are empty.\n\n --ignore-fail-on-non-empty\n ignore each failure that is solely because a directory\n is non-empty\n"-
232 , 5)-
233 ,-
234 stdout-
235 )-
236-
237-
238-
239-
240-
241 ;-
242 fputs_unlocked (-
243 dcgettext (((void *)0), -
244 " -p, --parents remove DIRECTORY and its ancestors; e.g., 'rmdir -p a/b/c' is\n similar to 'rmdir a/b/c a/b a'\n -v, --verbose output a diagnostic for every directory processed\n"-
245 , 5)-
246 ,-
247 stdout-
248 )-
249-
250-
251-
252-
253 ;-
254 fputs_unlocked (-
255 dcgettext (((void *)0), -
256 " --help display this help and exit\n"-
257 , 5)-
258 ,-
259 stdout-
260 );-
261 fputs_unlocked (-
262 dcgettext (((void *)0), -
263 " --version output version information and exit\n"-
264 , 5)-
265 ,-
266 stdout-
267 );-
268 emit_ancillary_info ("rmdir");-
269 }
executed 8 times by 1 test: end of block
Executed by:
  • rmdir
8
270 exit (status);
executed 11 times by 1 test: exit (status);
Executed by:
  • rmdir
11
271}-
272-
273int-
274main (int argc, char **argv)-
275{-
276 -
277 _Bool -
278 ok = -
279 1-
280 ;-
281 int optc;-
282-
283 ;-
284 set_program_name (argv[0]);-
285 setlocale (-
286 6-
287 , "");-
288 bindtextdomain ("coreutils", "/usr/local/share/locale");-
289 textdomain ("coreutils");-
290-
291 atexit (close_stdout);-
292-
293 remove_empty_parents = -
294 0-
295 ;-
296-
297 while ((
(optc = getopt... *)0) )) != -1Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • rmdir
FALSEevaluated 16 times by 1 test
Evaluated by:
  • rmdir
optc = getopt_long (argc, argv, "pv", longopts,
(optc = getopt... *)0) )) != -1Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • rmdir
FALSEevaluated 16 times by 1 test
Evaluated by:
  • rmdir
16-26
298 ((void *)0)
(optc = getopt... *)0) )) != -1Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • rmdir
FALSEevaluated 16 times by 1 test
Evaluated by:
  • rmdir
16-26
299 )) != -1
(optc = getopt... *)0) )) != -1Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • rmdir
FALSEevaluated 16 times by 1 test
Evaluated by:
  • rmdir
)
16-26
300 {-
301 switch (optc)-
302 {-
303 case
executed 5 times by 1 test: case 'p':
Executed by:
  • rmdir
'p':
executed 5 times by 1 test: case 'p':
Executed by:
  • rmdir
5
304 remove_empty_parents = -
305 1-
306 ;-
307 break;
executed 5 times by 1 test: break;
Executed by:
  • rmdir
5
308 case
executed 2 times by 1 test: case IGNORE_FAIL_ON_NON_EMPTY_OPTION:
Executed by:
  • rmdir
IGNORE_FAIL_ON_NON_EMPTY_OPTION:
executed 2 times by 1 test: case IGNORE_FAIL_ON_NON_EMPTY_OPTION:
Executed by:
  • rmdir
2
309 ignore_fail_on_non_empty = -
310 1-
311 ;-
312 break;
executed 2 times by 1 test: break;
Executed by:
  • rmdir
2
313 case
executed 2 times by 1 test: case 'v':
Executed by:
  • rmdir
'v':
executed 2 times by 1 test: case 'v':
Executed by:
  • rmdir
2
314 verbose = -
315 1-
316 ;-
317 break;
executed 2 times by 1 test: break;
Executed by:
  • rmdir
2
318 case
executed 8 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • rmdir
GETOPT_HELP_CHAR:
executed 8 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • rmdir
usage (
8
319 0-
320 ); break;
never executed: break;
;
0
321 case
executed 6 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • rmdir
GETOPT_VERSION_CHAR:
executed 6 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • rmdir
version_etc (
6
322 stdout-
323 , "rmdir", "GNU coreutils", Version, ("David MacKenzie"), (char *) -
324 ((void *)0)-
325 ); exit (
executed 6 times by 1 test: exit ( 0 );
Executed by:
  • rmdir
6
326 0
executed 6 times by 1 test: exit ( 0 );
Executed by:
  • rmdir
6
327 );
executed 6 times by 1 test: exit ( 0 );
Executed by:
  • rmdir
break;
never executed: break;
;
0-6
328 default
executed 3 times by 1 test: default:
Executed by:
  • rmdir
:
executed 3 times by 1 test: default:
Executed by:
  • rmdir
3
329 usage (-
330 1-
331 );-
332 }
never executed: end of block
0
333 }-
334-
335 if (optind == argc
optind == argcDescription
TRUEnever evaluated
FALSEevaluated 16 times by 1 test
Evaluated by:
  • rmdir
)
0-16
336 {-
337 error (0, 0, -
338 dcgettext (((void *)0), -
339 "missing operand"-
340 , 5)-
341 );-
342 usage (-
343 1-
344 );-
345 }
never executed: end of block
0
346-
347 for (; optind < argc
optind < argcDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • rmdir
FALSEevaluated 16 times by 1 test
Evaluated by:
  • rmdir
; ++optind)
16-17
348 {-
349 char *dir = argv[optind];-
350-
351-
352 if (verbose
verboseDescription
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • rmdir
)
0-17
353 prog_fprintf (
never executed: prog_fprintf ( stdout , dcgettext (((void *)0), "removing directory, %s" , 5) , quotearg_style (shell_escape_always_quoting_style, dir));
0
354 stdout
never executed: prog_fprintf ( stdout , dcgettext (((void *)0), "removing directory, %s" , 5) , quotearg_style (shell_escape_always_quoting_style, dir));
0
355 ,
never executed: prog_fprintf ( stdout , dcgettext (((void *)0), "removing directory, %s" , 5) , quotearg_style (shell_escape_always_quoting_style, dir));
0
356 dcgettext (((void *)0),
never executed: prog_fprintf ( stdout , dcgettext (((void *)0), "removing directory, %s" , 5) , quotearg_style (shell_escape_always_quoting_style, dir));
0
357 "removing directory, %s"
never executed: prog_fprintf ( stdout , dcgettext (((void *)0), "removing directory, %s" , 5) , quotearg_style (shell_escape_always_quoting_style, dir));
0
358 , 5)
never executed: prog_fprintf ( stdout , dcgettext (((void *)0), "removing directory, %s" , 5) , quotearg_style (shell_escape_always_quoting_style, dir));
0
359 , quotearg_style (shell_escape_always_quoting_style, dir));
never executed: prog_fprintf ( stdout , dcgettext (((void *)0), "removing directory, %s" , 5) , quotearg_style (shell_escape_always_quoting_style, dir));
0
360-
361 if (rmdir (dir) != 0
rmdir (dir) != 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • rmdir
FALSEevaluated 16 times by 1 test
Evaluated by:
  • rmdir
)
1-16
362 {-
363 if (ignorable_failure (
ignorable_fail...ion ()) , dir)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • rmdir
0-1
364 (*__errno_location ())
ignorable_fail...ion ()) , dir)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • rmdir
0-1
365 , dir)
ignorable_fail...ion ()) , dir)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • rmdir
)
0-1
366 continue;
never executed: continue;
0
367-
368-
369-
370 error (0, -
371 (*__errno_location ())-
372 , -
373 dcgettext (((void *)0), -
374 "failed to remove %s"-
375 , 5)-
376 , quotearg_style (shell_escape_always_quoting_style, dir));-
377 ok = -
378 0-
379 ;-
380 }
executed 1 time by 1 test: end of block
Executed by:
  • rmdir
1
381 else if (remove_empty_parents
remove_empty_parentsDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • rmdir
FALSEevaluated 13 times by 1 test
Evaluated by:
  • rmdir
)
3-13
382 {-
383 ok &= remove_parents (dir);-
384 }
executed 3 times by 1 test: end of block
Executed by:
  • rmdir
3
385 }
executed 17 times by 1 test: end of block
Executed by:
  • rmdir
17
386-
387 return
executed 16 times by 1 test: return ok ? 0 : 1 ;
Executed by:
  • rmdir
ok ?
executed 16 times by 1 test: return ok ? 0 : 1 ;
Executed by:
  • rmdir
16
388 0
executed 16 times by 1 test: return ok ? 0 : 1 ;
Executed by:
  • rmdir
16
389 :
executed 16 times by 1 test: return ok ? 0 : 1 ;
Executed by:
  • rmdir
16
390 1
executed 16 times by 1 test: return ok ? 0 : 1 ;
Executed by:
  • rmdir
16
391 ;
executed 16 times by 1 test: return ok ? 0 : 1 ;
Executed by:
  • rmdir
16
392}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.1.2