Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/readlink.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | - | |||||||||||||
8 | - | |||||||||||||
9 | static | - | ||||||||||||
10 | _Bool | - | ||||||||||||
11 | no_newline; | - | ||||||||||||
12 | - | |||||||||||||
13 | - | |||||||||||||
14 | static | - | ||||||||||||
15 | _Bool | - | ||||||||||||
16 | verbose; | - | ||||||||||||
17 | - | |||||||||||||
18 | static struct option const longopts[] = | - | ||||||||||||
19 | { | - | ||||||||||||
20 | {"canonicalize", | - | ||||||||||||
21 | 0 | - | ||||||||||||
22 | , | - | ||||||||||||
23 | ((void *)0) | - | ||||||||||||
24 | , 'f'}, | - | ||||||||||||
25 | {"canonicalize-existing", | - | ||||||||||||
26 | 0 | - | ||||||||||||
27 | , | - | ||||||||||||
28 | ((void *)0) | - | ||||||||||||
29 | , 'e'}, | - | ||||||||||||
30 | {"canonicalize-missing", | - | ||||||||||||
31 | 0 | - | ||||||||||||
32 | , | - | ||||||||||||
33 | ((void *)0) | - | ||||||||||||
34 | , 'm'}, | - | ||||||||||||
35 | {"no-newline", | - | ||||||||||||
36 | 0 | - | ||||||||||||
37 | , | - | ||||||||||||
38 | ((void *)0) | - | ||||||||||||
39 | , 'n'}, | - | ||||||||||||
40 | {"quiet", | - | ||||||||||||
41 | 0 | - | ||||||||||||
42 | , | - | ||||||||||||
43 | ((void *)0) | - | ||||||||||||
44 | , 'q'}, | - | ||||||||||||
45 | {"silent", | - | ||||||||||||
46 | 0 | - | ||||||||||||
47 | , | - | ||||||||||||
48 | ((void *)0) | - | ||||||||||||
49 | , 's'}, | - | ||||||||||||
50 | {"verbose", | - | ||||||||||||
51 | 0 | - | ||||||||||||
52 | , | - | ||||||||||||
53 | ((void *)0) | - | ||||||||||||
54 | , 'v'}, | - | ||||||||||||
55 | {"zero", | - | ||||||||||||
56 | 0 | - | ||||||||||||
57 | , | - | ||||||||||||
58 | ((void *)0) | - | ||||||||||||
59 | , 'z'}, | - | ||||||||||||
60 | {"help", | - | ||||||||||||
61 | 0 | - | ||||||||||||
62 | , | - | ||||||||||||
63 | ((void *)0) | - | ||||||||||||
64 | , GETOPT_HELP_CHAR}, | - | ||||||||||||
65 | {"version", | - | ||||||||||||
66 | 0 | - | ||||||||||||
67 | , | - | ||||||||||||
68 | ((void *)0) | - | ||||||||||||
69 | , GETOPT_VERSION_CHAR}, | - | ||||||||||||
70 | { | - | ||||||||||||
71 | ((void *)0) | - | ||||||||||||
72 | , 0, | - | ||||||||||||
73 | ((void *)0) | - | ||||||||||||
74 | , 0} | - | ||||||||||||
75 | }; | - | ||||||||||||
76 | - | |||||||||||||
77 | void | - | ||||||||||||
78 | usage (int status) | - | ||||||||||||
79 | { | - | ||||||||||||
80 | if (status !=
| 3-19 | ||||||||||||
81 | 0
| 3-19 | ||||||||||||
82 | ) | - | ||||||||||||
83 | do { fprintf ( | - | ||||||||||||
84 | stderr | - | ||||||||||||
85 | , | - | ||||||||||||
86 | dcgettext (((void *)0), | - | ||||||||||||
87 | "Try '%s --help' for more information.\n" | - | ||||||||||||
88 | , 5) | - | ||||||||||||
89 | , program_name); } executed 3 times by 1 test: while (0);end of block Executed by:
| 3 | ||||||||||||
90 | else | - | ||||||||||||
91 | { | - | ||||||||||||
92 | printf ( | - | ||||||||||||
93 | dcgettext (((void *)0), | - | ||||||||||||
94 | "Usage: %s [OPTION]... FILE...\n" | - | ||||||||||||
95 | , 5) | - | ||||||||||||
96 | , program_name); | - | ||||||||||||
97 | fputs_unlocked ( | - | ||||||||||||
98 | dcgettext (((void *)0), | - | ||||||||||||
99 | "Print value of a symbolic link or canonical file name\n\n" | - | ||||||||||||
100 | , 5) | - | ||||||||||||
101 | , | - | ||||||||||||
102 | stdout | - | ||||||||||||
103 | ) | - | ||||||||||||
104 | ; | - | ||||||||||||
105 | fputs_unlocked ( | - | ||||||||||||
106 | dcgettext (((void *)0), | - | ||||||||||||
107 | " -f, --canonicalize canonicalize by following every symlink in\n every component of the given name recursively;\n all but the last component must exist\n -e, --canonicalize-existing canonicalize by following every symlink in\n every component of the given name recursively,\n all components must exist\n" | - | ||||||||||||
108 | , 5) | - | ||||||||||||
109 | , | - | ||||||||||||
110 | stdout | - | ||||||||||||
111 | ) | - | ||||||||||||
112 | ; | - | ||||||||||||
113 | fputs_unlocked ( | - | ||||||||||||
114 | dcgettext (((void *)0), | - | ||||||||||||
115 | " -m, --canonicalize-missing canonicalize by following every symlink in\n every component of the given name recursively,\n without requirements on components existence\n -n, --no-newline do not output the trailing delimiter\n -q, --quiet\n -s, --silent suppress most error messages (on by default)\n -v, --verbose report error messages\n -z, --zero end each output line with NUL, not newline\n" | - | ||||||||||||
116 | , 5) | - | ||||||||||||
117 | , | - | ||||||||||||
118 | stdout | - | ||||||||||||
119 | ) | - | ||||||||||||
120 | ; | - | ||||||||||||
121 | fputs_unlocked ( | - | ||||||||||||
122 | dcgettext (((void *)0), | - | ||||||||||||
123 | " --help display this help and exit\n" | - | ||||||||||||
124 | , 5) | - | ||||||||||||
125 | , | - | ||||||||||||
126 | stdout | - | ||||||||||||
127 | ); | - | ||||||||||||
128 | fputs_unlocked ( | - | ||||||||||||
129 | dcgettext (((void *)0), | - | ||||||||||||
130 | " --version output version information and exit\n" | - | ||||||||||||
131 | , 5) | - | ||||||||||||
132 | , | - | ||||||||||||
133 | stdout | - | ||||||||||||
134 | ); | - | ||||||||||||
135 | emit_ancillary_info ("readlink"); | - | ||||||||||||
136 | } executed 19 times by 1 test: end of block Executed by:
| 19 | ||||||||||||
137 | exit (status); executed 22 times by 1 test: exit (status); Executed by:
| 22 | ||||||||||||
138 | } | - | ||||||||||||
139 | - | |||||||||||||
140 | int | - | ||||||||||||
141 | main (int argc, char **argv) | - | ||||||||||||
142 | { | - | ||||||||||||
143 | - | |||||||||||||
144 | int can_mode = -1; | - | ||||||||||||
145 | int status = | - | ||||||||||||
146 | 0 | - | ||||||||||||
147 | ; | - | ||||||||||||
148 | int optc; | - | ||||||||||||
149 | - | |||||||||||||
150 | _Bool | - | ||||||||||||
151 | use_nuls = | - | ||||||||||||
152 | 0 | - | ||||||||||||
153 | ; | - | ||||||||||||
154 | - | |||||||||||||
155 | ; | - | ||||||||||||
156 | set_program_name (argv[0]); | - | ||||||||||||
157 | setlocale ( | - | ||||||||||||
158 | 6 | - | ||||||||||||
159 | , ""); | - | ||||||||||||
160 | bindtextdomain ("coreutils", "/usr/local/share/locale"); | - | ||||||||||||
161 | textdomain ("coreutils"); | - | ||||||||||||
162 | - | |||||||||||||
163 | atexit (close_stdout); | - | ||||||||||||
164 | - | |||||||||||||
165 | while ((
| 216-256 | ||||||||||||
166 | ((void *)0)
| 216-256 | ||||||||||||
167 | )) != -1
| 216-256 | ||||||||||||
168 | { | - | ||||||||||||
169 | switch (optc) | - | ||||||||||||
170 | { | - | ||||||||||||
171 | case executed 63 times by 1 test: 'e':case 'e': Executed by:
executed 63 times by 1 test: case 'e': Executed by:
| 63 | ||||||||||||
172 | can_mode = CAN_EXISTING; | - | ||||||||||||
173 | break; executed 63 times by 1 test: break; Executed by:
| 63 | ||||||||||||
174 | case executed 73 times by 1 test: 'f':case 'f': Executed by:
executed 73 times by 1 test: case 'f': Executed by:
| 73 | ||||||||||||
175 | can_mode = CAN_ALL_BUT_LAST; | - | ||||||||||||
176 | break; executed 73 times by 1 test: break; Executed by:
| 73 | ||||||||||||
177 | case executed 67 times by 1 test: 'm':case 'm': Executed by:
executed 67 times by 1 test: case 'm': Executed by:
| 67 | ||||||||||||
178 | can_mode = CAN_MISSING; | - | ||||||||||||
179 | break; executed 67 times by 1 test: break; Executed by:
| 67 | ||||||||||||
180 | case executed 5 times by 1 test: 'n':case 'n': Executed by:
executed 5 times by 1 test: case 'n': Executed by:
| 5 | ||||||||||||
181 | no_newline = | - | ||||||||||||
182 | 1 | - | ||||||||||||
183 | ; | - | ||||||||||||
184 | break; executed 5 times by 1 test: break; Executed by:
| 5 | ||||||||||||
185 | case executed 2 times by 1 test: 'q':case 'q': Executed by:
executed 2 times by 1 test: case 'q': Executed by:
| 2 | ||||||||||||
186 | case executed 2 times by 1 test: 's':case 's': Executed by:
executed 2 times by 1 test: case 's': Executed by:
| 2 | ||||||||||||
187 | verbose = | - | ||||||||||||
188 | 0 | - | ||||||||||||
189 | ; | - | ||||||||||||
190 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||
191 | case executed 6 times by 1 test: 'v':case 'v': Executed by:
executed 6 times by 1 test: case 'v': Executed by:
| 6 | ||||||||||||
192 | verbose = | - | ||||||||||||
193 | 1 | - | ||||||||||||
194 | ; | - | ||||||||||||
195 | break; executed 6 times by 1 test: break; Executed by:
| 6 | ||||||||||||
196 | case executed 6 times by 1 test: 'z':case 'z': Executed by:
executed 6 times by 1 test: case 'z': Executed by:
| 6 | ||||||||||||
197 | use_nuls = | - | ||||||||||||
198 | 1 | - | ||||||||||||
199 | ; | - | ||||||||||||
200 | break; executed 6 times by 1 test: break; Executed by:
| 6 | ||||||||||||
201 | case executed 19 times by 1 test: GETOPT_HELP_CHAR:case GETOPT_HELP_CHAR: Executed by:
executed 19 times by 1 test: usage (case GETOPT_HELP_CHAR: Executed by:
| 19 | ||||||||||||
202 | 0 | - | ||||||||||||
203 | ); break; never executed: ;break; | 0 | ||||||||||||
204 | case executed 10 times by 1 test: GETOPT_VERSION_CHAR:case GETOPT_VERSION_CHAR: Executed by:
executed 10 times by 1 test: version_etc (case GETOPT_VERSION_CHAR: Executed by:
| 10 | ||||||||||||
205 | stdout | - | ||||||||||||
206 | , "readlink", "GNU coreutils", Version, ("Dmitry V. Levin"), (char *) | - | ||||||||||||
207 | ((void *)0) | - | ||||||||||||
208 | ); exit ( executed 10 times by 1 test: exit ( 0 ); Executed by:
| 10 | ||||||||||||
209 | 0 executed 10 times by 1 test: exit ( 0 ); Executed by:
| 10 | ||||||||||||
210 | ); executed 10 times by 1 test: break;exit ( 0 ); Executed by:
never executed: ;break; | 0-10 | ||||||||||||
211 | default executed 3 times by 1 test: :default: Executed by:
executed 3 times by 1 test: default: Executed by:
| 3 | ||||||||||||
212 | usage ( | - | ||||||||||||
213 | 1 | - | ||||||||||||
214 | ); | - | ||||||||||||
215 | } never executed: end of block | 0 | ||||||||||||
216 | } | - | ||||||||||||
217 | - | |||||||||||||
218 | if (optind >= argc
| 0-216 | ||||||||||||
219 | { | - | ||||||||||||
220 | error (0, 0, | - | ||||||||||||
221 | dcgettext (((void *)0), | - | ||||||||||||
222 | "missing operand" | - | ||||||||||||
223 | , 5) | - | ||||||||||||
224 | ); | - | ||||||||||||
225 | usage ( | - | ||||||||||||
226 | 1 | - | ||||||||||||
227 | ); | - | ||||||||||||
228 | } never executed: end of block | 0 | ||||||||||||
229 | - | |||||||||||||
230 | if (argc - optind > 1
| 7-209 | ||||||||||||
231 | { | - | ||||||||||||
232 | if (no_newline
| 2-5 | ||||||||||||
233 | error (0, 0, executed 2 times by 1 test: error (0, 0, dcgettext (((void *)0), "ignoring --no-newline with multiple arguments" , 5) ); Executed by:
| 2 | ||||||||||||
234 | dcgettext (((void *)0), executed 2 times by 1 test: error (0, 0, dcgettext (((void *)0), "ignoring --no-newline with multiple arguments" , 5) ); Executed by:
| 2 | ||||||||||||
235 | "ignoring --no-newline with multiple arguments" executed 2 times by 1 test: error (0, 0, dcgettext (((void *)0), "ignoring --no-newline with multiple arguments" , 5) ); Executed by:
| 2 | ||||||||||||
236 | , 5) executed 2 times by 1 test: error (0, 0, dcgettext (((void *)0), "ignoring --no-newline with multiple arguments" , 5) ); Executed by:
| 2 | ||||||||||||
237 | ); executed 2 times by 1 test: error (0, 0, dcgettext (((void *)0), "ignoring --no-newline with multiple arguments" , 5) ); Executed by:
| 2 | ||||||||||||
238 | no_newline = | - | ||||||||||||
239 | 0 | - | ||||||||||||
240 | ; | - | ||||||||||||
241 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||
242 | - | |||||||||||||
243 | for (; optind < argc
| 216-224 | ||||||||||||
244 | { | - | ||||||||||||
245 | const char *fname = argv[optind]; | - | ||||||||||||
246 | char *value = (can_mode != -1
| 23-201 | ||||||||||||
247 | ? canonicalize_filename_mode (fname, can_mode) | - | ||||||||||||
248 | : areadlink_with_size (fname, 63)); | - | ||||||||||||
249 | if (value
| 70-154 | ||||||||||||
250 | { | - | ||||||||||||
251 | fputs_unlocked (value, | - | ||||||||||||
252 | stdout | - | ||||||||||||
253 | ); | - | ||||||||||||
254 | if (! no_newline
| 1-153 | ||||||||||||
255 | putchar_unlocked (use_nuls ? '\0' : '\n'); executed 153 times by 1 test: putchar_unlocked (use_nuls ? '\0' : '\n'); Executed by:
| 153 | ||||||||||||
256 | free (value); | - | ||||||||||||
257 | } executed 154 times by 1 test: end of block Executed by:
| 154 | ||||||||||||
258 | else | - | ||||||||||||
259 | { | - | ||||||||||||
260 | status = | - | ||||||||||||
261 | 1 | - | ||||||||||||
262 | ; | - | ||||||||||||
263 | if (verbose
| 2-68 | ||||||||||||
264 | error (0, executed 2 times by 1 test: error (0, (*__errno_location ()) , "%s", quotearg_n_style_colon (0, shell_escape_quoting_style, fname)); Executed by:
| 2 | ||||||||||||
265 | (*__errno_location ()) executed 2 times by 1 test: error (0, (*__errno_location ()) , "%s", quotearg_n_style_colon (0, shell_escape_quoting_style, fname)); Executed by:
| 2 | ||||||||||||
266 | , "%s", quotearg_n_style_colon (0, shell_escape_quoting_style, fname)); executed 2 times by 1 test: error (0, (*__errno_location ()) , "%s", quotearg_n_style_colon (0, shell_escape_quoting_style, fname)); Executed by:
| 2 | ||||||||||||
267 | } executed 70 times by 1 test: end of block Executed by:
| 70 | ||||||||||||
268 | } | - | ||||||||||||
269 | - | |||||||||||||
270 | return executed 216 times by 1 test: status;return status; Executed by:
executed 216 times by 1 test: return status; Executed by:
| 216 | ||||||||||||
271 | } | - | ||||||||||||
Switch to Source code | Preprocessed file |