OpenCoverage

dirname.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/dirname.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* dirname -- strip suffix from file name-
2-
3 Copyright (C) 1990-2018 Free Software Foundation, Inc.-
4-
5 This program is free software: you can redistribute it and/or modify-
6 it under the terms of the GNU General Public License as published by-
7 the Free Software Foundation, either version 3 of the License, or-
8 (at your option) any later version.-
9-
10 This program is distributed in the hope that it will be useful,-
11 but WITHOUT ANY WARRANTY; without even the implied warranty of-
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
13 GNU General Public License for more details.-
14-
15 You should have received a copy of the GNU General Public License-
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */-
17-
18/* Written by David MacKenzie and Jim Meyering. */-
19-
20#include <config.h>-
21#include <getopt.h>-
22#include <stdio.h>-
23#include <sys/types.h>-
24-
25#include "system.h"-
26#include "error.h"-
27-
28/* The official name of this program (e.g., no 'g' prefix). */-
29#define PROGRAM_NAME "dirname"-
30-
31#define AUTHORS \-
32 proper_name ("David MacKenzie"), \-
33 proper_name ("Jim Meyering")-
34-
35static struct option const longopts[] =-
36{-
37 {"zero", no_argument, NULL, 'z'},-
38 {GETOPT_HELP_OPTION_DECL},-
39 {GETOPT_VERSION_OPTION_DECL},-
40 {NULL, 0, NULL, 0}-
41};-
42-
43void-
44usage (int status)-
45{-
46 if (status != EXIT_SUCCESS)
status != 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • dirname
FALSEevaluated 5 times by 1 test
Evaluated by:
  • dirname
4-5
47 emit_try_help ();
executed 4 times by 1 test: end of block
Executed by:
  • dirname
4
48 else-
49 {-
50 printf (_("\-
51Usage: %s [OPTION] NAME...\n\-
52"),-
53 program_name);-
54 fputs (_("\-
55Output each NAME with its last non-slash component and trailing slashes\n\-
56removed; if NAME contains no /'s, output '.' (meaning the current directory).\n\-
57\n\-
58"), stdout);-
59 fputs (_("\-
60 -z, --zero end each output line with NUL, not newline\n\-
61"), stdout);-
62 fputs (HELP_OPTION_DESCRIPTION, stdout);-
63 fputs (VERSION_OPTION_DESCRIPTION, stdout);-
64 printf (_("\-
65\n\-
66Examples:\n\-
67 %s /usr/bin/ -> \"/usr\"\n\-
68 %s dir1/str dir2/str -> \"dir1\" followed by \"dir2\"\n\-
69 %s stdio.h -> \".\"\n\-
70"),-
71 program_name, program_name, program_name);-
72 emit_ancillary_info (PROGRAM_NAME);-
73 }
executed 5 times by 1 test: end of block
Executed by:
  • dirname
5
74 exit (status);
executed 9 times by 1 test: exit (status);
Executed by:
  • dirname
9
75}-
76-
77int-
78main (int argc, char **argv)-
79{-
80 static char const dot = '.';-
81 bool use_nuls = false;-
82 char const *result;-
83 size_t len;-
84-
85 initialize_main (&argc, &argv);-
86 set_program_name (argv[0]);-
87 setlocale (LC_ALL, "");-
88 bindtextdomain (PACKAGE, LOCALEDIR);-
89 textdomain (PACKAGE);-
90-
91 atexit (close_stdout);-
92-
93 while (true)-
94 {-
95 int c = getopt_long (argc, argv, "z", longopts, NULL);-
96-
97 if (c == -1)
c == -1Description
TRUEevaluated 22 times by 1 test
Evaluated by:
  • dirname
FALSEevaluated 14 times by 1 test
Evaluated by:
  • dirname
14-22
98 break;
executed 22 times by 1 test: break;
Executed by:
  • dirname
22
99-
100 switch (c)-
101 {-
102 case 'z':
executed 2 times by 1 test: case 'z':
Executed by:
  • dirname
2
103 use_nuls = true;-
104 break;
executed 2 times by 1 test: break;
Executed by:
  • dirname
2
105-
106 case_GETOPT_HELP_CHAR;
never executed: break;
executed 5 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • dirname
0-5
107 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
executed 4 times by 1 test: exit ( 0 );
Executed by:
  • dirname
never executed: break;
executed 4 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • dirname
0-4
108-
109 default:
executed 3 times by 1 test: default:
Executed by:
  • dirname
3
110 usage (EXIT_FAILURE);-
111 }
never executed: end of block
0
112 }-
113-
114 if (argc < optind + 1)
argc < optind + 1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dirname
FALSEevaluated 21 times by 1 test
Evaluated by:
  • dirname
1-21
115 {-
116 error (0, 0, _("missing operand"));-
117 usage (EXIT_FAILURE);-
118 }
never executed: end of block
0
119-
120 for (; optind < argc; optind++)
optind < argcDescription
TRUEevaluated 22 times by 1 test
Evaluated by:
  • dirname
FALSEevaluated 21 times by 1 test
Evaluated by:
  • dirname
21-22
121 {-
122 result = argv[optind];-
123 len = dir_len (result);-
124-
125 if (! len)
! lenDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dirname
FALSEevaluated 19 times by 1 test
Evaluated by:
  • dirname
3-19
126 {-
127 result = &dot;-
128 len = 1;-
129 }
executed 3 times by 1 test: end of block
Executed by:
  • dirname
3
130-
131 fwrite (result, 1, len, stdout);
never executed: break;
(__builtin_exp...r++))) == (-1)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • dirname
__cnt > 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dirname
FALSEevaluated 3 times by 1 test
Evaluated by:
  • dirname
__builtin_expe...write_end), 0)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dirname
FALSEnever evaluated
0-3
132 putchar (use_nuls ? '\0' :'\n');-
133 }
executed 22 times by 1 test: end of block
Executed by:
  • dirname
22
134-
135 return EXIT_SUCCESS;
executed 21 times by 1 test: return 0 ;
Executed by:
  • dirname
21
136}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2