OpenCoverage

wc.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/wc.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* wc - print the number of lines, words, and bytes in files-
2 Copyright (C) 1985-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/* Written by Paul Rubin, phr@ocf.berkeley.edu-
18 and David MacKenzie, djm@gnu.ai.mit.edu. */-
19-
20#include <config.h>-
21-
22#include <stdio.h>-
23#include <assert.h>-
24#include <getopt.h>-
25#include <sys/types.h>-
26#include <wchar.h>-
27#include <wctype.h>-
28-
29#include "system.h"-
30#include "argv-iter.h"-
31#include "die.h"-
32#include "error.h"-
33#include "fadvise.h"-
34#include "mbchar.h"-
35#include "physmem.h"-
36#include "readtokens0.h"-
37#include "safe-read.h"-
38#include "stat-size.h"-
39#include "xbinary-io.h"-
40-
41#if !defined iswspace && !HAVE_ISWSPACE-
42# define iswspace(wc) \-
43 ((wc) == to_uchar (wc) && isspace (to_uchar (wc)))-
44#endif-
45-
46/* The official name of this program (e.g., no 'g' prefix). */-
47#define PROGRAM_NAME "wc"-
48-
49#define AUTHORS \-
50 proper_name ("Paul Rubin"), \-
51 proper_name ("David MacKenzie")-
52-
53/* Size of atomic reads. */-
54#define BUFFER_SIZE (16 * 1024)-
55-
56/* Cumulative number of lines, words, chars and bytes in all files so far.-
57 max_line_length is the maximum over all files processed so far. */-
58static uintmax_t total_lines;-
59static uintmax_t total_words;-
60static uintmax_t total_chars;-
61static uintmax_t total_bytes;-
62static uintmax_t max_line_length;-
63-
64/* Which counts to print. */-
65static bool print_lines, print_words, print_chars, print_bytes;-
66static bool print_linelength;-
67-
68/* The print width of each count. */-
69static int number_width;-
70-
71/* True if we have ever read the standard input. */-
72static bool have_read_stdin;-
73-
74/* Used to determine if file size can be determined without reading. */-
75static size_t page_size;-
76-
77/* The result of calling fstat or stat on a file descriptor or file. */-
78struct fstatus-
79{-
80 /* If positive, fstat or stat has not been called yet. Otherwise,-
81 this is the value returned from fstat or stat. */-
82 int failed;-
83-
84 /* If FAILED is zero, this is the file's status. */-
85 struct stat st;-
86};-
87-
88/* For long options that have no equivalent short option, use a-
89 non-character as a pseudo short option, starting with CHAR_MAX + 1. */-
90enum-
91{-
92 FILES0_FROM_OPTION = CHAR_MAX + 1-
93};-
94-
95static struct option const longopts[] =-
96{-
97 {"bytes", no_argument, NULL, 'c'},-
98 {"chars", no_argument, NULL, 'm'},-
99 {"lines", no_argument, NULL, 'l'},-
100 {"words", no_argument, NULL, 'w'},-
101 {"files0-from", required_argument, NULL, FILES0_FROM_OPTION},-
102 {"max-line-length", no_argument, NULL, 'L'},-
103 {GETOPT_HELP_OPTION_DECL},-
104 {GETOPT_VERSION_OPTION_DECL},-
105 {NULL, 0, NULL, 0}-
106};-
107-
108void-
109usage (int status)-
110{-
111 if (status != EXIT_SUCCESS)
status != 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 14 times by 1 test
Evaluated by:
  • wc
4-14
112 emit_try_help ();
executed 4 times by 1 test: end of block
Executed by:
  • wc
4
113 else-
114 {-
115 printf (_("\-
116Usage: %s [OPTION]... [FILE]...\n\-
117 or: %s [OPTION]... --files0-from=F\n\-
118"),-
119 program_name, program_name);-
120 fputs (_("\-
121Print newline, word, and byte counts for each FILE, and a total line if\n\-
122more than one FILE is specified. A word is a non-zero-length sequence of\n\-
123characters delimited by white space.\n\-
124"), stdout);-
125-
126 emit_stdin_note ();-
127-
128 fputs (_("\-
129\n\-
130The options below may be used to select which counts are printed, always in\n\-
131the following order: newline, word, character, byte, maximum line length.\n\-
132 -c, --bytes print the byte counts\n\-
133 -m, --chars print the character counts\n\-
134 -l, --lines print the newline counts\n\-
135"), stdout);-
136 fputs (_("\-
137 --files0-from=F read input from the files specified by\n\-
138 NUL-terminated names in file F;\n\-
139 If F is - then read names from standard input\n\-
140 -L, --max-line-length print the maximum display width\n\-
141 -w, --words print the word counts\n\-
142"), stdout);-
143 fputs (HELP_OPTION_DESCRIPTION, stdout);-
144 fputs (VERSION_OPTION_DESCRIPTION, stdout);-
145 emit_ancillary_info (PROGRAM_NAME);-
146 }
executed 14 times by 1 test: end of block
Executed by:
  • wc
14
147 exit (status);
executed 18 times by 1 test: exit (status);
Executed by:
  • wc
18
148}-
149-
150/* FILE is the name of the file (or NULL for standard input)-
151 associated with the specified counters. */-
152static void-
153write_counts (uintmax_t lines,-
154 uintmax_t words,-
155 uintmax_t chars,-
156 uintmax_t bytes,-
157 uintmax_t linelength,-
158 const char *file)-
159{-
160 static char const format_sp_int[] = " %*s";-
161 char const *format_int = format_sp_int + 1;-
162 char buf[INT_BUFSIZE_BOUND (uintmax_t)];-
163-
164 if (print_lines)
print_linesDescription
TRUEevaluated 6643 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 1244 times by 1 test
Evaluated by:
  • wc
1244-6643
165 {-
166 printf (format_int, number_width, umaxtostr (lines, buf));-
167 format_int = format_sp_int;-
168 }
executed 6643 times by 1 test: end of block
Executed by:
  • wc
6643
169 if (print_words)
print_wordsDescription
TRUEevaluated 6029 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 1858 times by 1 test
Evaluated by:
  • wc
1858-6029
170 {-
171 printf (format_int, number_width, umaxtostr (words, buf));-
172 format_int = format_sp_int;-
173 }
executed 6029 times by 1 test: end of block
Executed by:
  • wc
6029
174 if (print_chars)
print_charsDescription
TRUEnever evaluated
FALSEevaluated 7887 times by 1 test
Evaluated by:
  • wc
0-7887
175 {-
176 printf (format_int, number_width, umaxtostr (chars, buf));-
177 format_int = format_sp_int;-
178 }
never executed: end of block
0
179 if (print_bytes)
print_bytesDescription
TRUEevaluated 6926 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 961 times by 1 test
Evaluated by:
  • wc
961-6926
180 {-
181 printf (format_int, number_width, umaxtostr (bytes, buf));-
182 format_int = format_sp_int;-
183 }
executed 6926 times by 1 test: end of block
Executed by:
  • wc
6926
184 if (print_linelength)
print_linelengthDescription
TRUEevaluated 339 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 7548 times by 1 test
Evaluated by:
  • wc
339-7548
185 {-
186 printf (format_int, number_width, umaxtostr (linelength, buf));-
187 }
executed 339 times by 1 test: end of block
Executed by:
  • wc
339
188 if (file)
fileDescription
TRUEevaluated 6027 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 1860 times by 1 test
Evaluated by:
  • wc
1860-6027
189 printf (" %s", strchr (file, '\n') ? quotef (file) : file);
executed 6027 times by 1 test: printf (" %s", (__extension__ (__builtin_constant_p ( '\n' ) && !__builtin_constant_p ( file ) && ( '\n' ) == '\0' ? (char *) __rawmemchr ( file , '\n' ) : __builtin_strchr ( file , '\n' ))) ? quotearg_n_style_colon (0, shell_escape_quoting_style, file) : file);
Executed by:
  • wc
6027
190 putchar ('\n');-
191}
executed 7887 times by 1 test: end of block
Executed by:
  • wc
7887
192-
193/* Count words. FILE_X is the name of the file (or NULL for standard-
194 input) that is open on descriptor FD. *FSTATUS is its status.-
195 CURRENT_POS is the current file offset if known, negative if unknown.-
196 Return true if successful. */-
197static bool-
198wc (int fd, char const *file_x, struct fstatus *fstatus, off_t current_pos)-
199{-
200 bool ok = true;-
201 char buf[BUFFER_SIZE + 1];-
202 size_t bytes_read;-
203 uintmax_t lines, words, chars, bytes, linelength;-
204 bool count_bytes, count_chars, count_complicated;-
205 char const *file = file_x ? file_x : _("standard input");
file_xDescription
TRUEevaluated 6016 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 1860 times by 1 test
Evaluated by:
  • wc
1860-6016
206-
207 lines = words = chars = bytes = linelength = 0;-
208-
209 /* If in the current locale, chars are equivalent to bytes, we prefer-
210 counting bytes, because that's easier. */-
211#if MB_LEN_MAX > 1-
212 if (MB_CUR_MAX > 1)
(__ctype_get_m...ur_max ()) > 1Description
TRUEnever evaluated
FALSEevaluated 7876 times by 1 test
Evaluated by:
  • wc
0-7876
213 {-
214 count_bytes = print_bytes;-
215 count_chars = print_chars;-
216 }
never executed: end of block
0
217 else-
218#endif-
219 {-
220 count_bytes = print_bytes || print_chars;
print_bytesDescription
TRUEevaluated 6915 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 961 times by 1 test
Evaluated by:
  • wc
print_charsDescription
TRUEnever evaluated
FALSEevaluated 961 times by 1 test
Evaluated by:
  • wc
0-6915
221 count_chars = false;-
222 }
executed 7876 times by 1 test: end of block
Executed by:
  • wc
7876
223 count_complicated = print_words || print_linelength;
print_wordsDescription
TRUEevaluated 6020 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 1856 times by 1 test
Evaluated by:
  • wc
print_linelengthDescription
TRUEevaluated 339 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 1517 times by 1 test
Evaluated by:
  • wc
339-6020
224-
225 /* Advise the kernel of our access pattern only if we will read(). */-
226 if (!count_bytes || count_chars || print_lines || count_complicated)
!count_bytesDescription
TRUEevaluated 961 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 6915 times by 1 test
Evaluated by:
  • wc
count_charsDescription
TRUEnever evaluated
FALSEevaluated 6915 times by 1 test
Evaluated by:
  • wc
print_linesDescription
TRUEevaluated 6016 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 899 times by 1 test
Evaluated by:
  • wc
count_complicatedDescription
TRUEnever evaluated
FALSEevaluated 899 times by 1 test
Evaluated by:
  • wc
0-6915
227 fdadvise (fd, 0, 0, FADVISE_SEQUENTIAL);
executed 6977 times by 1 test: fdadvise (fd, 0, 0, FADVISE_SEQUENTIAL);
Executed by:
  • wc
6977
228-
229 /* When counting only bytes, save some line- and word-counting-
230 overhead. If FD is a 'regular' Unix file, using lseek is enough-
231 to get its 'size' in bytes. Otherwise, read blocks of BUFFER_SIZE-
232 bytes at a time until EOF. Note that the 'size' (number of bytes)-
233 that wc reports is smaller than stats.st_size when the file is not-
234 positioned at its beginning. That's why the lseek calls below are-
235 necessary. For example the command-
236 '(dd ibs=99k skip=1 count=0; ./wc -c) < /etc/group'-
237 should make wc report '0' bytes. */-
238-
239 if (count_bytes && !count_chars && !print_lines && !count_complicated)
count_bytesDescription
TRUEevaluated 6915 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 961 times by 1 test
Evaluated by:
  • wc
!count_charsDescription
TRUEevaluated 6915 times by 1 test
Evaluated by:
  • wc
FALSEnever evaluated
!print_linesDescription
TRUEevaluated 899 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 6016 times by 1 test
Evaluated by:
  • wc
!count_complicatedDescription
TRUEevaluated 899 times by 1 test
Evaluated by:
  • wc
FALSEnever evaluated
0-6915
240 {-
241 bool skip_read = false;-
242-
243 if (0 < fstatus->failed)
0 < fstatus->failedDescription
TRUEevaluated 897 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 2 times by 1 test
Evaluated by:
  • wc
2-897
244 fstatus->failed = fstat (fd, &fstatus->st);
executed 897 times by 1 test: fstatus->failed = fstat (fd, &fstatus->st);
Executed by:
  • wc
897
245-
246 /* For sized files, seek to one st_blksize before EOF rather than to EOF.-
247 This works better for files in proc-like file systems where-
248 the size is only approximate. */-
249 if (! fstatus->failed && usable_st_size (&fstatus->st)
! fstatus->failedDescription
TRUEevaluated 899 times by 1 test
Evaluated by:
  • wc
FALSEnever evaluated
usable_st_size (&fstatus->st)Description
TRUEevaluated 453 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 446 times by 1 test
Evaluated by:
  • wc
0-899
250 && 0 <= fstatus->st.st_size)
0 <= fstatus->st.st_sizeDescription
TRUEevaluated 453 times by 1 test
Evaluated by:
  • wc
FALSEnever evaluated
0-453
251 {-
252 size_t end_pos = fstatus->st.st_size;-
253 if (current_pos < 0)
current_pos < 0Description
TRUEevaluated 449 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 4 times by 1 test
Evaluated by:
  • wc
4-449
254 current_pos = lseek (fd, 0, SEEK_CUR);
executed 449 times by 1 test: current_pos = lseek (fd, 0, 1 );
Executed by:
  • wc
449
255-
256 if (end_pos % page_size)
end_pos % page_sizeDescription
TRUEevaluated 447 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 6 times by 1 test
Evaluated by:
  • wc
6-447
257 {-
258 /* We only need special handling of /proc and /sys files etc.-
259 when they're a multiple of PAGE_SIZE. In the common case-
260 for files with st_size not a multiple of PAGE_SIZE,-
261 it's more efficient and accurate to use st_size.-
262-
263 Be careful here. The current position may actually be-
264 beyond the end of the file. As in the example above. */-
265-
266 bytes = end_pos < current_pos ? 0 : end_pos - current_pos;
end_pos < current_posDescription
TRUEnever evaluated
FALSEevaluated 447 times by 1 test
Evaluated by:
  • wc
0-447
267 skip_read = true;-
268 }
executed 447 times by 1 test: end of block
Executed by:
  • wc
447
269 else-
270 {-
271 off_t hi_pos = end_pos - end_pos % (ST_BLKSIZE (fstatus->st) + 1);
0 < (fstatus->st).st_blksizeDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • wc
FALSEnever evaluated
(fstatus->st)...._t)-1) / 8 + 1Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • wc
FALSEnever evaluated
0-6
272 if (0 <= current_pos && current_pos < hi_pos
0 <= current_posDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • wc
FALSEnever evaluated
current_pos < hi_posDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 4 times by 1 test
Evaluated by:
  • wc
0-6
273 && 0 <= lseek (fd, hi_pos, SEEK_CUR))
0 <= lseek (fd, hi_pos, 1 )Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • wc
FALSEnever evaluated
0-2
274 bytes = hi_pos - current_pos;
executed 2 times by 1 test: bytes = hi_pos - current_pos;
Executed by:
  • wc
2
275 }
executed 6 times by 1 test: end of block
Executed by:
  • wc
6
276 }-
277-
278 if (! skip_read)
! skip_readDescription
TRUEevaluated 452 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 447 times by 1 test
Evaluated by:
  • wc
447-452
279 {-
280 fdadvise (fd, 0, 0, FADVISE_SEQUENTIAL);-
281 while ((bytes_read = safe_read (fd, buf, BUFFER_SIZE)) > 0)
(bytes_read = ... * 1024))) > 0Description
TRUEevaluated 31047 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 452 times by 1 test
Evaluated by:
  • wc
452-31047
282 {-
283 if (bytes_read == SAFE_READ_ERROR)
bytes_read == ((size_t) -1)Description
TRUEnever evaluated
FALSEevaluated 31047 times by 1 test
Evaluated by:
  • wc
0-31047
284 {-
285 error (0, errno, "%s", quotef (file));-
286 ok = false;-
287 break;
never executed: break;
0
288 }-
289 bytes += bytes_read;-
290 }
executed 31047 times by 1 test: end of block
Executed by:
  • wc
31047
291 }
executed 452 times by 1 test: end of block
Executed by:
  • wc
452
292 }
executed 899 times by 1 test: end of block
Executed by:
  • wc
899
293 else if (!count_chars && !count_complicated)
!count_charsDescription
TRUEevaluated 6977 times by 1 test
Evaluated by:
  • wc
FALSEnever evaluated
!count_complicatedDescription
TRUEevaluated 618 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 6359 times by 1 test
Evaluated by:
  • wc
0-6977
294 {-
295 /* Use a separate loop when counting only lines or lines and bytes ---
296 but not chars or words. */-
297 bool long_lines = false;-
298 while ((bytes_read = safe_read (fd, buf, BUFFER_SIZE)) > 0)
(bytes_read = ... * 1024))) > 0Description
TRUEevaluated 735 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 618 times by 1 test
Evaluated by:
  • wc
618-735
299 {-
300 if (bytes_read == SAFE_READ_ERROR)
bytes_read == ((size_t) -1)Description
TRUEnever evaluated
FALSEevaluated 735 times by 1 test
Evaluated by:
  • wc
0-735
301 {-
302 error (0, errno, "%s", quotef (file));-
303 ok = false;-
304 break;
never executed: break;
0
305 }-
306-
307 bytes += bytes_read;-
308-
309 char *p = buf;-
310 char *end = p + bytes_read;-
311 uintmax_t plines = lines;-
312-
313 if (! long_lines)
! long_linesDescription
TRUEevaluated 735 times by 1 test
Evaluated by:
  • wc
FALSEnever evaluated
0-735
314 {-
315 /* Avoid function call overhead for shorter lines. */-
316 while (p != end)
p != endDescription
TRUEevaluated 1164258 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 735 times by 1 test
Evaluated by:
  • wc
735-1164258
317 lines += *p++ == '\n';
executed 1164258 times by 1 test: lines += *p++ == '\n';
Executed by:
  • wc
1164258
318 }
executed 735 times by 1 test: end of block
Executed by:
  • wc
735
319 else-
320 {-
321 /* memchr is more efficient with longer lines. */-
322 while ((p = memchr (p, '\n', end - p)))
(p = memchr (p...\n', end - p))Description
TRUEnever evaluated
FALSEnever evaluated
0
323 {-
324 ++p;-
325 ++lines;-
326 }
never executed: end of block
0
327 }
never executed: end of block
0
328-
329 /* If the average line length in the block is >= 15, then use-
330 memchr for the next block, where system specific optimizations-
331 may outweigh function call overhead.-
332 FIXME: This line length was determined in 2015, on both-
333 x86_64 and ppc64, but it's worth re-evaluating in future with-
334 newer compilers, CPUs, or memchr() implementations etc. */-
335 if (lines - plines <= bytes_read / 15)
lines - plines...ytes_read / 15Description
TRUEevaluated 534 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 201 times by 1 test
Evaluated by:
  • wc
201-534
336 long_lines = true;
executed 534 times by 1 test: long_lines = 1 ;
Executed by:
  • wc
534
337 else-
338 long_lines = false;
executed 201 times by 1 test: long_lines = 0 ;
Executed by:
  • wc
201
339 }-
340 }
executed 618 times by 1 test: end of block
Executed by:
  • wc
618
341#if MB_LEN_MAX > 1-
342# define SUPPORT_OLD_MBRTOWC 1-
343 else if (MB_CUR_MAX > 1)
(__ctype_get_m...ur_max ()) > 1Description
TRUEnever evaluated
FALSEevaluated 6359 times by 1 test
Evaluated by:
  • wc
0-6359
344 {-
345 bool in_word = false;-
346 uintmax_t linepos = 0;-
347 mbstate_t state = { 0, };-
348 bool in_shift = false;-
349# if SUPPORT_OLD_MBRTOWC-
350 /* Back-up the state before each multibyte character conversion and-
351 move the last incomplete character of the buffer to the front-
352 of the buffer. This is needed because we don't know whether-
353 the 'mbrtowc' function updates the state when it returns -2, ---
354 this is the ISO C 99 and glibc-2.2 behaviour - or not - amended-
355 ANSI C, glibc-2.1 and Solaris 5.7 behaviour. We don't have an-
356 autoconf test for this, yet. */-
357 size_t prev = 0; /* number of bytes carried over from previous round */-
358# else-
359 const size_t prev = 0;-
360# endif-
361-
362 while ((bytes_read = safe_read (fd, buf + prev, BUFFER_SIZE - prev)) > 0)
(bytes_read = ...) - prev)) > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
363 {-
364 const char *p;-
365# if SUPPORT_OLD_MBRTOWC-
366 mbstate_t backup_state;-
367# endif-
368 if (bytes_read == SAFE_READ_ERROR)
bytes_read == ((size_t) -1)Description
TRUEnever evaluated
FALSEnever evaluated
0
369 {-
370 error (0, errno, "%s", quotef (file));-
371 ok = false;-
372 break;
never executed: break;
0
373 }-
374-
375 bytes += bytes_read;-
376 p = buf;-
377 bytes_read += prev;-
378 do-
379 {-
380 wchar_t wide_char;-
381 size_t n;-
382-
383 if (!in_shift && is_basic (*p))
!in_shiftDescription
TRUEnever evaluated
FALSEnever evaluated
is_basic (*p)Description
TRUEnever evaluated
FALSEnever evaluated
0
384 {-
385 /* Handle most ASCII characters quickly, without calling-
386 mbrtowc(). */-
387 n = 1;-
388 wide_char = *p;-
389 }
never executed: end of block
0
390 else-
391 {-
392 in_shift = true;-
393# if SUPPORT_OLD_MBRTOWC-
394 backup_state = state;-
395# endif-
396 n = mbrtowc (&wide_char, p, bytes_read, &state);-
397 if (n == (size_t) -2)
n == (size_t) -2Description
TRUEnever evaluated
FALSEnever evaluated
0
398 {-
399# if SUPPORT_OLD_MBRTOWC-
400 state = backup_state;-
401# endif-
402 break;
never executed: break;
0
403 }-
404 if (n == (size_t) -1)
n == (size_t) -1Description
TRUEnever evaluated
FALSEnever evaluated
0
405 {-
406 /* Remember that we read a byte, but don't complain-
407 about the error. Because of the decoding error,-
408 this is a considered to be byte but not a-
409 character (that is, chars is not incremented). */-
410 p++;-
411 bytes_read--;-
412 continue;
never executed: continue;
0
413 }-
414 if (mbsinit (&state))
mbsinit (&state)Description
TRUEnever evaluated
FALSEnever evaluated
0
415 in_shift = false;
never executed: in_shift = 0 ;
0
416 if (n == 0)
n == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
417 {-
418 wide_char = 0;-
419 n = 1;-
420 }
never executed: end of block
0
421 }
never executed: end of block
0
422 p += n;-
423 bytes_read -= n;-
424 chars++;-
425 switch (wide_char)-
426 {-
427 case '\n':
never executed: case '\n':
0
428 lines++;-
429 FALLTHROUGH;-
430 case '\r':
code before this statement never executed: case '\r':
never executed: case '\r':
0
431 case '\f':
never executed: case '\f':
0
432 if (linepos > linelength)
linepos > linelengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
433 linelength = linepos;
never executed: linelength = linepos;
0
434 linepos = 0;-
435 goto mb_word_separator;
never executed: goto mb_word_separator;
0
436 case '\t':
never executed: case '\t':
0
437 linepos += 8 - (linepos % 8);-
438 goto mb_word_separator;
never executed: goto mb_word_separator;
0
439 case ' ':
never executed: case ' ':
0
440 linepos++;-
441 FALLTHROUGH;-
442 case '\v':
code before this statement never executed: case '\v':
never executed: case '\v':
0
443 mb_word_separator:-
444 words += in_word;-
445 in_word = false;-
446 break;
never executed: break;
0
447 default:
never executed: default:
0
448 if (iswprint (wide_char))
iswprint (wide_char)Description
TRUEnever evaluated
FALSEnever evaluated
0
449 {-
450 int width = wcwidth (wide_char);-
451 if (width > 0)
width > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
452 linepos += width;
never executed: linepos += width;
0
453 if (iswspace (wide_char))
iswspace (wide_char)Description
TRUEnever evaluated
FALSEnever evaluated
0
454 goto mb_word_separator;
never executed: goto mb_word_separator;
0
455 in_word = true;-
456 }
never executed: end of block
0
457 break;
never executed: break;
0
458 }-
459 }-
460 while (bytes_read > 0);
bytes_read > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
461-
462# if SUPPORT_OLD_MBRTOWC-
463 if (bytes_read > 0)
bytes_read > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
464 {-
465 if (bytes_read == BUFFER_SIZE)
bytes_read == (16 * 1024)Description
TRUEnever evaluated
FALSEnever evaluated
0
466 {-
467 /* Encountered a very long redundant shift sequence. */-
468 p++;-
469 bytes_read--;-
470 }
never executed: end of block
0
471 memmove (buf, p, bytes_read);-
472 }
never executed: end of block
0
473 prev = bytes_read;-
474# endif-
475 }
never executed: end of block
0
476 if (linepos > linelength)
linepos > linelengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
477 linelength = linepos;
never executed: linelength = linepos;
0
478 words += in_word;-
479 }
never executed: end of block
0
480#endif-
481 else-
482 {-
483 bool in_word = false;-
484 uintmax_t linepos = 0;-
485-
486 while ((bytes_read = safe_read (fd, buf, BUFFER_SIZE)) > 0)
(bytes_read = ... * 1024))) > 0Description
TRUEevaluated 349 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 6359 times by 1 test
Evaluated by:
  • wc
349-6359
487 {-
488 const char *p = buf;-
489 if (bytes_read == SAFE_READ_ERROR)
bytes_read == ((size_t) -1)Description
TRUEnever evaluated
FALSEevaluated 349 times by 1 test
Evaluated by:
  • wc
0-349
490 {-
491 error (0, errno, "%s", quotef (file));-
492 ok = false;-
493 break;
never executed: break;
0
494 }-
495-
496 bytes += bytes_read;-
497 do-
498 {-
499 switch (*p++)-
500 {-
501 case '\n':
executed 352 times by 1 test: case '\n':
Executed by:
  • wc
352
502 lines++;-
503 FALLTHROUGH;-
504 case '\r':
code before this statement executed 352 times by 1 test: case '\r':
Executed by:
  • wc
never executed: case '\r':
0-352
505 case '\f':
never executed: case '\f':
0
506 if (linepos > linelength)
linepos > linelengthDescription
TRUEevaluated 349 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 3 times by 1 test
Evaluated by:
  • wc
3-349
507 linelength = linepos;
executed 349 times by 1 test: linelength = linepos;
Executed by:
  • wc
349
508 linepos = 0;-
509 goto word_separator;
executed 352 times by 1 test: goto word_separator;
Executed by:
  • wc
352
510 case '\t':
never executed: case '\t':
0
511 linepos += 8 - (linepos % 8);-
512 goto word_separator;
never executed: goto word_separator;
0
513 case ' ':
executed 7 times by 1 test: case ' ':
Executed by:
  • wc
7
514 linepos++;-
515 FALLTHROUGH;-
516 case '\v':
code before this statement executed 7 times by 1 test: case '\v':
Executed by:
  • wc
never executed: case '\v':
0-7
517 word_separator:-
518 words += in_word;-
519 in_word = false;-
520 break;
executed 359 times by 1 test: break;
Executed by:
  • wc
359
521 default:
executed 1394 times by 1 test: default:
Executed by:
  • wc
1394
522 if (isprint (to_uchar (p[-1])))
((*__ctype_b_l...int) _ISprint)Description
TRUEevaluated 1394 times by 1 test
Evaluated by:
  • wc
FALSEnever evaluated
0-1394
523 {-
524 linepos++;-
525 if (isspace (to_uchar (p[-1])))
((*__ctype_b_l...int) _ISspace)Description
TRUEnever evaluated
FALSEevaluated 1394 times by 1 test
Evaluated by:
  • wc
0-1394
526 goto word_separator;
never executed: goto word_separator;
0
527 in_word = true;-
528 }
executed 1394 times by 1 test: end of block
Executed by:
  • wc
1394
529 break;
executed 1394 times by 1 test: break;
Executed by:
  • wc
1394
530 }-
531 }-
532 while (--bytes_read);
--bytes_readDescription
TRUEevaluated 1404 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 349 times by 1 test
Evaluated by:
  • wc
349-1404
533 }
executed 349 times by 1 test: end of block
Executed by:
  • wc
349
534 if (linepos > linelength)
linepos > linelengthDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 6357 times by 1 test
Evaluated by:
  • wc
2-6357
535 linelength = linepos;
executed 2 times by 1 test: linelength = linepos;
Executed by:
  • wc
2
536 words += in_word;-
537 }
executed 6359 times by 1 test: end of block
Executed by:
  • wc
6359
538-
539 if (count_chars < print_chars)
count_chars < print_charsDescription
TRUEnever evaluated
FALSEevaluated 7876 times by 1 test
Evaluated by:
  • wc
0-7876
540 chars = bytes;
never executed: chars = bytes;
0
541-
542 write_counts (lines, words, chars, bytes, linelength, file_x);-
543 total_lines += lines;-
544 total_words += words;-
545 total_chars += chars;-
546 total_bytes += bytes;-
547 if (linelength > max_line_length)
linelength > max_line_lengthDescription
TRUEevaluated 349 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 7527 times by 1 test
Evaluated by:
  • wc
349-7527
548 max_line_length = linelength;
executed 349 times by 1 test: max_line_length = linelength;
Executed by:
  • wc
349
549-
550 return ok;
executed 7876 times by 1 test: return ok;
Executed by:
  • wc
7876
551}-
552-
553static bool-
554wc_file (char const *file, struct fstatus *fstatus)-
555{-
556 if (! file || STREQ (file, "-"))
never executed: __result = (((const unsigned char *) (const char *) ( file ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "-" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
! fileDescription
TRUEevaluated 1860 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 6016 times by 1 test
Evaluated by:
  • wc
( __extension_...)))); }) == 0)Description
TRUEnever evaluated
FALSEevaluated 6016 times by 1 test
Evaluated by:
  • wc
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEevaluated 6016 times by 1 test
Evaluated by:
  • wc
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEevaluated 6016 times by 1 test
Evaluated by:
  • wc
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-6016
557 {-
558 have_read_stdin = true;-
559 xset_binary_mode (STDIN_FILENO, O_BINARY);-
560 return wc (STDIN_FILENO, file, fstatus, -1);
executed 1860 times by 1 test: return wc ( 0 , file, fstatus, -1);
Executed by:
  • wc
1860
561 }-
562 else-
563 {-
564 int fd = open (file, O_RDONLY | O_BINARY);-
565 if (fd == -1)
fd == -1Description
TRUEnever evaluated
FALSEevaluated 6016 times by 1 test
Evaluated by:
  • wc
0-6016
566 {-
567 error (0, errno, "%s", quotef (file));-
568 return false;
never executed: return 0 ;
0
569 }-
570 else-
571 {-
572 bool ok = wc (fd, file, fstatus, 0);-
573 if (close (fd) != 0)
close (fd) != 0Description
TRUEnever evaluated
FALSEevaluated 6016 times by 1 test
Evaluated by:
  • wc
0-6016
574 {-
575 error (0, errno, "%s", quotef (file));-
576 return false;
never executed: return 0 ;
0
577 }-
578 return ok;
executed 6016 times by 1 test: return ok;
Executed by:
  • wc
6016
579 }-
580 }-
581}-
582-
583/* Return the file status for the NFILES files addressed by FILE.-
584 Optimize the case where only one number is printed, for just one-
585 file; in that case we can use a print width of 1, so we don't need-
586 to stat the file. Handle the case of (nfiles == 0) in the same way;-
587 that happens when we don't know how long the list of file names will be. */-
588-
589static struct fstatus *-
590get_input_fstatus (size_t nfiles, char *const *file)-
591{-
592 struct fstatus *fstatus = xnmalloc (nfiles ? nfiles : 1, sizeof *fstatus);-
593-
594 if (nfiles == 0
nfiles == 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 1874 times by 1 test
Evaluated by:
  • wc
5-1874
595 || (nfiles == 1
nfiles == 1Description
TRUEevaluated 1864 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 10 times by 1 test
Evaluated by:
  • wc
10-1864
596 && ((print_lines + print_words + print_chars
((print_lines ...elength) == 1)Description
TRUEevaluated 1856 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 8 times by 1 test
Evaluated by:
  • wc
8-1856
597 + print_bytes + print_linelength)
((print_lines ...elength) == 1)Description
TRUEevaluated 1856 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 8 times by 1 test
Evaluated by:
  • wc
8-1856
598 == 1)))
((print_lines ...elength) == 1)Description
TRUEevaluated 1856 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 8 times by 1 test
Evaluated by:
  • wc
8-1856
599 fstatus[0].failed = 1;
executed 1861 times by 1 test: fstatus[0].failed = 1;
Executed by:
  • wc
1861
600 else-
601 {-
602 for (size_t i = 0; i < nfiles; i++)
i < nfilesDescription
TRUEevaluated 6022 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 18 times by 1 test
Evaluated by:
  • wc
18-6022
603 fstatus[i].failed = (! file[i] || STREQ (file[i], "-")
executed 6022 times by 1 test: fstatus[i].failed = (! file[i] || ( __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p ( file[i] ) && __builtin_constant_p ( "-" ) && (__s1_len = __builtin_strlen ( file[i] ), __s2_len = __builtin_strlen ( "-" ), (!((size_t)(const void *)((... __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ( "-" ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp ( file[i] , "-" )))); }) == 0) ? fstat ( 0 , &fstatus[i].st) : stat (file[i], &fstatus[i].st));
Executed by:
  • wc
never executed: __result = (((const unsigned char *) (const char *) ( file[i] ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "-" ))[3] - __s2[3]);
never executed: end of block
executed 1 time by 1 test: end of block
Executed by:
  • wc
! file[i]Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 6018 times by 1 test
Evaluated by:
  • wc
( __extension_...)))); }) == 0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • wc
FALSEevaluated 6017 times by 1 test
Evaluated by:
  • wc
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEevaluated 6018 times by 1 test
Evaluated by:
  • wc
FALSEnever evaluated
__result == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • wc
FALSEevaluated 6017 times by 1 test
Evaluated by:
  • wc
__s2_len > 1Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • wc
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-6022
604 ? fstat (STDIN_FILENO, &fstatus[i].st)
executed 6022 times by 1 test: fstatus[i].failed = (! file[i] || ( __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p ( file[i] ) && __builtin_constant_p ( "-" ) && (__s1_len = __builtin_strlen ( file[i] ), __s2_len = __builtin_strlen ( "-" ), (!((size_t)(const void *)((... __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ( "-" ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp ( file[i] , "-" )))); }) == 0) ? fstat ( 0 , &fstatus[i].st) : stat (file[i], &fstatus[i].st));
Executed by:
  • wc
6022
605 : stat (file[i], &fstatus[i].st));
executed 6022 times by 1 test: fstatus[i].failed = (! file[i] || ( __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p ( file[i] ) && __builtin_constant_p ( "-" ) && (__s1_len = __builtin_strlen ( file[i] ), __s2_len = __builtin_strlen ( "-" ), (!((size_t)(const void *)((... __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ( "-" ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp ( file[i] , "-" )))); }) == 0) ? fstat ( 0 , &fstatus[i].st) : stat (file[i], &fstatus[i].st));
Executed by:
  • wc
6022
606 }
executed 18 times by 1 test: end of block
Executed by:
  • wc
18
607-
608 return fstatus;
executed 1879 times by 1 test: return fstatus;
Executed by:
  • wc
1879
609}-
610-
611/* Return a print width suitable for the NFILES files whose status is-
612 recorded in FSTATUS. Optimize the same special case that-
613 get_input_fstatus optimizes. */-
614-
615static int _GL_ATTRIBUTE_PURE-
616compute_number_width (size_t nfiles, struct fstatus const *fstatus)-
617{-
618 int width = 1;-
619-
620 if (0 < nfiles && fstatus[0].failed <= 0)
0 < nfilesDescription
TRUEevaluated 1874 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 5 times by 1 test
Evaluated by:
  • wc
fstatus[0].failed <= 0Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 1856 times by 1 test
Evaluated by:
  • wc
5-1874
621 {-
622 int minimum_width = 1;-
623 uintmax_t regular_total = 0;-
624-
625 for (size_t i = 0; i < nfiles; i++)
i < nfilesDescription
TRUEevaluated 6022 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 18 times by 1 test
Evaluated by:
  • wc
18-6022
626 if (! fstatus[i].failed)
! fstatus[i].failedDescription
TRUEevaluated 6017 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 5 times by 1 test
Evaluated by:
  • wc
5-6017
627 {-
628 if (S_ISREG (fstatus[i].st.st_mode))
(((( fstatus[i... == (0100000))Description
TRUEevaluated 6014 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 3 times by 1 test
Evaluated by:
  • wc
3-6014
629 regular_total += fstatus[i].st.st_size;
executed 6014 times by 1 test: regular_total += fstatus[i].st.st_size;
Executed by:
  • wc
6014
630 else-
631 minimum_width = 7;
executed 3 times by 1 test: minimum_width = 7;
Executed by:
  • wc
3
632 }-
633-
634 for (; 10 <= regular_total; regular_total /= 10)
10 <= regular_totalDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 18 times by 1 test
Evaluated by:
  • wc
9-18
635 width++;
executed 9 times by 1 test: width++;
Executed by:
  • wc
9
636 if (width < minimum_width)
width < minimum_widthDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 15 times by 1 test
Evaluated by:
  • wc
3-15
637 width = minimum_width;
executed 3 times by 1 test: width = minimum_width;
Executed by:
  • wc
3
638 }
executed 18 times by 1 test: end of block
Executed by:
  • wc
18
639-
640 return width;
executed 1879 times by 1 test: return width;
Executed by:
  • wc
1879
641}-
642-
643-
644int-
645main (int argc, char **argv)-
646{-
647 bool ok;-
648 int optc;-
649 size_t nfiles;-
650 char **files;-
651 char *files_from = NULL;-
652 struct fstatus *fstatus;-
653 struct Tokens tok;-
654-
655 initialize_main (&argc, &argv);-
656 set_program_name (argv[0]);-
657 setlocale (LC_ALL, "");-
658 bindtextdomain (PACKAGE, LOCALEDIR);-
659 textdomain (PACKAGE);-
660-
661 atexit (close_stdout);-
662-
663 page_size = getpagesize ();-
664 /* Line buffer stdout to ensure lines are written atomically and immediately-
665 so that processes running in parallel do not intersperse their output. */-
666 setvbuf (stdout, NULL, _IOLBF, 0);-
667-
668 print_lines = print_words = print_chars = print_bytes = false;-
669 print_linelength = false;-
670 total_lines = total_words = total_chars = total_bytes = max_line_length = 0;-
671-
672 while ((optc = getopt_long (argc, argv, "clLmw", longopts, NULL)) != -1)
(optc = getopt... *)0) )) != -1Description
TRUEevaluated 1912 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 1881 times by 1 test
Evaluated by:
  • wc
1881-1912
673 switch (optc)-
674 {-
675 case 'c':
executed 899 times by 1 test: case 'c':
Executed by:
  • wc
899
676 print_bytes = true;-
677 break;
executed 899 times by 1 test: break;
Executed by:
  • wc
899
678-
679 case 'm':
executed 2 times by 1 test: case 'm':
Executed by:
  • wc
2
680 print_chars = true;-
681 break;
executed 2 times by 1 test: break;
Executed by:
  • wc
2
682-
683 case 'l':
executed 620 times by 1 test: case 'l':
Executed by:
  • wc
620
684 print_lines = true;-
685 break;
executed 620 times by 1 test: break;
Executed by:
  • wc
620
686-
687 case 'w':
executed 6 times by 1 test: case 'w':
Executed by:
  • wc
6
688 print_words = true;-
689 break;
executed 6 times by 1 test: break;
Executed by:
  • wc
6
690-
691 case 'L':
executed 341 times by 1 test: case 'L':
Executed by:
  • wc
341
692 print_linelength = true;-
693 break;
executed 341 times by 1 test: break;
Executed by:
  • wc
341
694-
695 case FILES0_FROM_OPTION:
executed 18 times by 1 test: case FILES0_FROM_OPTION:
Executed by:
  • wc
18
696 files_from = optarg;-
697 break;
executed 18 times by 1 test: break;
Executed by:
  • wc
18
698-
699 case_GETOPT_HELP_CHAR;
never executed: break;
executed 14 times by 1 test: case GETOPT_HELP_CHAR:
Executed by:
  • wc
0-14
700-
701 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
executed 9 times by 1 test: exit ( 0 );
Executed by:
  • wc
never executed: break;
executed 9 times by 1 test: case GETOPT_VERSION_CHAR:
Executed by:
  • wc
0-9
702-
703 default:
executed 3 times by 1 test: default:
Executed by:
  • wc
3
704 usage (EXIT_FAILURE);-
705 }
never executed: end of block
0
706-
707 if (! (print_lines || print_words || print_chars || print_bytes
print_linesDescription
TRUEevaluated 618 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 1263 times by 1 test
Evaluated by:
  • wc
print_wordsDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 1259 times by 1 test
Evaluated by:
  • wc
print_charsDescription
TRUEnever evaluated
FALSEevaluated 1259 times by 1 test
Evaluated by:
  • wc
print_bytesDescription
TRUEevaluated 897 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 362 times by 1 test
Evaluated by:
  • wc
0-1263
708 || print_linelength))
print_linelengthDescription
TRUEevaluated 339 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 23 times by 1 test
Evaluated by:
  • wc
23-339
709 print_lines = print_words = print_bytes = true;
executed 23 times by 1 test: print_lines = print_words = print_bytes = 1 ;
Executed by:
  • wc
23
710-
711 bool read_tokens = false;-
712 struct argv_iterator *ai;-
713 if (files_from)
files_fromDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 1864 times by 1 test
Evaluated by:
  • wc
17-1864
714 {-
715 FILE *stream;-
716-
717 /* When using --files0-from=F, you may not specify any files-
718 on the command-line. */-
719 if (optind < argc)
optind < argcDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • wc
FALSEevaluated 16 times by 1 test
Evaluated by:
  • wc
1-16
720 {-
721 error (0, 0, _("extra operand %s"), quoteaf (argv[optind]));-
722 fprintf (stderr, "%s\n",-
723 _("file operands cannot be combined with --files0-from"));-
724 usage (EXIT_FAILURE);-
725 }
never executed: end of block
0
726-
727 if (STREQ (files_from, "-"))
never executed: __result = (((const unsigned char *) (const char *) ( files_from ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "-" ))[3] - __s2[3]);
never executed: end of block
executed 11 times by 1 test: end of block
Executed by:
  • wc
( __extension_...)))); }) == 0)Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 5 times by 1 test
Evaluated by:
  • wc
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • wc
FALSEnever evaluated
__result == 0Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 5 times by 1 test
Evaluated by:
  • wc
__s2_len > 1Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • wc
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-16
728 stream = stdin;
executed 11 times by 1 test: stream = stdin ;
Executed by:
  • wc
11
729 else-
730 {-
731 stream = fopen (files_from, "r");-
732 if (stream == NULL)
stream == ((void *)0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • wc
FALSEevaluated 4 times by 1 test
Evaluated by:
  • wc
1-4
733 die (EXIT_FAILURE, errno, _("cannot open %s for reading"),
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"cannot open %s for reading\", 5), quotearg_style (shell_escape_always_quoting_style, files_from)), assume (false))" ")"); int ...(void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "cannot open %s for reading" , 5) , quotearg_style (shell_escape_always_quoting_style, files_from)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • wc
1
734 quoteaf (files_from));
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"cannot open %s for reading\", 5), quotearg_style (shell_escape_always_quoting_style, files_from)), assume (false))" ")"); int ...(void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "cannot open %s for reading" , 5) , quotearg_style (shell_escape_always_quoting_style, files_from)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • wc
1
735 }
executed 4 times by 1 test: end of block
Executed by:
  • wc
4
736-
737 /* Read the file list into RAM if we can detect its size and that-
738 size is reasonable. Otherwise, we'll read a name at a time. */-
739 struct stat st;-
740 if (fstat (fileno (stream), &st) == 0
fstat (fileno ...am), &st) == 0Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • wc
FALSEnever evaluated
0-15
741 && S_ISREG (st.st_mode)
(((( st.st_mod... == (0100000))Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 4 times by 1 test
Evaluated by:
  • wc
4-11
742 && st.st_size <= MIN (10 * 1024 * 1024, physmem_available () / 2))
(( 10 * 1024 *...able () / 2 ))Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • wc
FALSEnever evaluated
st.st_size <= ...able () / 2 ))Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • wc
FALSEnever evaluated
0-11
743 {-
744 read_tokens = true;-
745 readtokens0_init (&tok);-
746 if (! readtokens0 (stream, &tok) || fclose (stream) != 0)
! readtokens0 (stream, &tok)Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • wc
rpl_fclose (stream) != 0Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • wc
0-11
747 die (EXIT_FAILURE, 0, _("cannot read file names from %s"),
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"cannot read file names from %s\", 5), quotearg_style (shell_escape_always_quoting_style, files_from)), assume (false))" ")"); int _gl_dummy; })) ? ..._from)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "cannot read file names from %s" , 5) , quotearg_style (shell_escape_always_quoting_style, files_from)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
748 quoteaf (files_from));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"cannot read file names from %s\", 5), quotearg_style (shell_escape_always_quoting_style, files_from)), assume (false))" ")"); int _gl_dummy; })) ? ..._from)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , 0, dcgettext (((void *)0), "cannot read file names from %s" , 5) , quotearg_style (shell_escape_always_quoting_style, files_from)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
749 files = tok.tok;-
750 nfiles = tok.n_tok;-
751 ai = argv_iter_init_argv (files);-
752 }
executed 11 times by 1 test: end of block
Executed by:
  • wc
11
753 else-
754 {-
755 files = NULL;-
756 nfiles = 0;-
757 ai = argv_iter_init_stream (stream);-
758 }
executed 4 times by 1 test: end of block
Executed by:
  • wc
4
759 }-
760 else-
761 {-
762 static char *stdin_only[] = { NULL };-
763 files = (optind < argc ? argv + optind : stdin_only);
optind < argcDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 1860 times by 1 test
Evaluated by:
  • wc
4-1860
764 nfiles = (optind < argc ? argc - optind : 1);
optind < argcDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 1860 times by 1 test
Evaluated by:
  • wc
4-1860
765 ai = argv_iter_init_argv (files);-
766 }
executed 1864 times by 1 test: end of block
Executed by:
  • wc
1864
767-
768 if (!ai)
!aiDescription
TRUEnever evaluated
FALSEevaluated 1879 times by 1 test
Evaluated by:
  • wc
0-1879
769 xalloc_die ();
never executed: xalloc_die ();
0
770-
771 fstatus = get_input_fstatus (nfiles, files);-
772 number_width = compute_number_width (nfiles, fstatus);-
773-
774 ok = true;-
775 for (int i = 0; /* */; i++)-
776 {-
777 bool skip_file = false;-
778 enum argv_iter_err ai_err;-
779 char *file_name = argv_iter (ai, &ai_err);-
780 if (!file_name)
!file_nameDescription
TRUEevaluated 1879 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 6021 times by 1 test
Evaluated by:
  • wc
1879-6021
781 {-
782 switch (ai_err)-
783 {-
784 case AI_ERR_EOF:
executed 1878 times by 1 test: case AI_ERR_EOF:
Executed by:
  • wc
1878
785 goto argv_iter_done;
executed 1878 times by 1 test: goto argv_iter_done;
Executed by:
  • wc
1878
786 case AI_ERR_READ:
executed 1 time by 1 test: case AI_ERR_READ:
Executed by:
  • wc
1
787 error (0, errno, _("%s: read error"),-
788 quotef (files_from));-
789 ok = false;-
790 goto argv_iter_done;
executed 1 time by 1 test: goto argv_iter_done;
Executed by:
  • wc
1
791 case AI_ERR_MEM:
never executed: case AI_ERR_MEM:
0
792 xalloc_die ();-
793 default:
code before this statement never executed: default:
never executed: default:
0
794 assert (!"unexpected error code from argv_iter");-
795 }
never executed: end of block
0
796 }-
797 if (files_from && STREQ (files_from, "-") && STREQ (file_name, "-"))
never executed: __result = (((const unsigned char *) (const char *) ( files_from ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "-" ))[3] - __s2[3]);
never executed: end of block
executed 17 times by 1 test: end of block
Executed by:
  • wc
never executed: __result = (((const unsigned char *) (const char *) ( file_name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "-" ))[3] - __s2[3]);
never executed: end of block
executed 1 time by 1 test: end of block
Executed by:
  • wc
files_fromDescription
TRUEevaluated 19 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 6002 times by 1 test
Evaluated by:
  • wc
( __extension_...)))); }) == 0)Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 2 times by 1 test
Evaluated by:
  • wc
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • wc
FALSEnever evaluated
__result == 0Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 2 times by 1 test
Evaluated by:
  • wc
__s2_len > 1Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • wc
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
( __extension_...)))); }) == 0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • wc
FALSEevaluated 16 times by 1 test
Evaluated by:
  • wc
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • wc
FALSEnever evaluated
__result == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • wc
FALSEevaluated 16 times by 1 test
Evaluated by:
  • wc
__s2_len > 1Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • wc
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-6002
798 {-
799 /* Give a better diagnostic in an unusual case:-
800 printf - | wc --files0-from=- */-
801 error (0, 0, _("when reading file names from stdin, "-
802 "no file name of %s allowed"),-
803 quoteaf (file_name));-
804 skip_file = true;-
805 }
executed 1 time by 1 test: end of block
Executed by:
  • wc
1
806-
807 if (!file_name[0])
!file_name[0]Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 6017 times by 1 test
Evaluated by:
  • wc
4-6017
808 {-
809 /* Diagnose a zero-length file name. When it's one-
810 among many, knowing the record number may help.-
811 FIXME: currently print the record number only with-
812 --files0-from=FILE. Maybe do it for argv, too? */-
813 if (files_from == NULL)
files_from == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • wc
0-4
814 error (0, 0, "%s", _("invalid zero-length file name"));
never executed: error (0, 0, "%s", dcgettext (((void *)0), "invalid zero-length file name" , 5) );
0
815 else-
816 {-
817 /* Using the standard 'filename:line-number:' prefix here is-
818 not totally appropriate, since NUL is the separator, not NL,-
819 but it might be better than nothing. */-
820 unsigned long int file_number = argv_iter_n_args (ai);-
821 error (0, 0, "%s:%lu: %s", quotef (files_from),-
822 file_number, _("invalid zero-length file name"));-
823 }
executed 4 times by 1 test: end of block
Executed by:
  • wc
4
824 skip_file = true;-
825 }
executed 4 times by 1 test: end of block
Executed by:
  • wc
4
826-
827 if (skip_file)
skip_fileDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 6016 times by 1 test
Evaluated by:
  • wc
5-6016
828 ok = false;
executed 5 times by 1 test: ok = 0 ;
Executed by:
  • wc
5
829 else-
830 ok &= wc_file (file_name, &fstatus[nfiles ? i : 0]);
executed 6016 times by 1 test: ok &= wc_file (file_name, &fstatus[nfiles ? i : 0]);
Executed by:
  • wc
6016
831-
832 if (! nfiles)
! nfilesDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 6018 times by 1 test
Evaluated by:
  • wc
3-6018
833 fstatus[0].failed = 1;
executed 3 times by 1 test: fstatus[0].failed = 1;
Executed by:
  • wc
3
834 }
executed 6021 times by 1 test: end of block
Executed by:
  • wc
6021
835 argv_iter_done:
code before this statement never executed: argv_iter_done:
0
836-
837 /* No arguments on the command line is fine. That means read from stdin.-
838 However, no arguments on the --files0-from input stream is an error-
839 means don't read anything. */-
840 if (ok && !files_from && argv_iter_n_args (ai) == 0)
okDescription
TRUEevaluated 1874 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 5 times by 1 test
Evaluated by:
  • wc
!files_fromDescription
TRUEevaluated 1864 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 10 times by 1 test
Evaluated by:
  • wc
argv_iter_n_args (ai) == 0Description
TRUEevaluated 1860 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 4 times by 1 test
Evaluated by:
  • wc
4-1874
841 ok &= wc_file (NULL, &fstatus[0]);
executed 1860 times by 1 test: ok &= wc_file ( ((void *)0) , &fstatus[0]);
Executed by:
  • wc
1860
842-
843 if (read_tokens)
read_tokensDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 1868 times by 1 test
Evaluated by:
  • wc
11-1868
844 readtokens0_free (&tok);
executed 11 times by 1 test: readtokens0_free (&tok);
Executed by:
  • wc
11
845-
846 if (1 < argv_iter_n_args (ai))
1 < argv_iter_n_args (ai)Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 1868 times by 1 test
Evaluated by:
  • wc
11-1868
847 write_counts (total_lines, total_words, total_chars, total_bytes,
executed 11 times by 1 test: write_counts (total_lines, total_words, total_chars, total_bytes, max_line_length, dcgettext (((void *)0), "total" , 5) );
Executed by:
  • wc
11
848 max_line_length, _("total"));
executed 11 times by 1 test: write_counts (total_lines, total_words, total_chars, total_bytes, max_line_length, dcgettext (((void *)0), "total" , 5) );
Executed by:
  • wc
11
849-
850 argv_iter_free (ai);-
851-
852 free (fstatus);-
853-
854 if (have_read_stdin && close (STDIN_FILENO) != 0)
have_read_stdinDescription
TRUEevaluated 1860 times by 1 test
Evaluated by:
  • wc
FALSEevaluated 19 times by 1 test
Evaluated by:
  • wc
close ( 0 ) != 0Description
TRUEnever evaluated
FALSEevaluated 1860 times by 1 test
Evaluated by:
  • wc
0-1860
855 die (EXIT_FAILURE, errno, "-");
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), \"-\"), assume (false))" ")"); int _gl_dummy; })) ? ((error ( 1 , (*__errno_location ()) , "-"), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((error ( 1 , (*__errno_location ()) , "-"), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
856-
857 return ok ? EXIT_SUCCESS : EXIT_FAILURE;
executed 1879 times by 1 test: return ok ? 0 : 1 ;
Executed by:
  • wc
1879
858}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2