OpenCoverage

dd.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/dd.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* dd -- convert a file while copying it.-
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, David MacKenzie, and Stuart Kemp. */-
18-
19#include <config.h>-
20-
21#define SWAB_ALIGN_OFFSET 2-
22-
23#include <sys/types.h>-
24#include <signal.h>-
25#include <getopt.h>-
26-
27#include "system.h"-
28#include "close-stream.h"-
29#include "die.h"-
30#include "error.h"-
31#include "fd-reopen.h"-
32#include "gethrxtime.h"-
33#include "human.h"-
34#include "ioblksize.h"-
35#include "long-options.h"-
36#include "quote.h"-
37#include "verror.h"-
38#include "xstrtol.h"-
39#include "xtime.h"-
40-
41/* The official name of this program (e.g., no 'g' prefix). */-
42#define PROGRAM_NAME "dd"-
43-
44#define AUTHORS \-
45 proper_name ("Paul Rubin"), \-
46 proper_name ("David MacKenzie"), \-
47 proper_name ("Stuart Kemp")-
48-
49static struct option const long_options[] =-
50{-
51 {NULL, 0, NULL, 0}-
52};-
53-
54/* Use SA_NOCLDSTOP as a proxy for whether the sigaction machinery is-
55 present. */-
56#ifndef SA_NOCLDSTOP-
57# define SA_NOCLDSTOP 0-
58# define sigprocmask(How, Set, Oset) /* empty */-
59# define sigset_t int-
60# if ! HAVE_SIGINTERRUPT-
61# define siginterrupt(sig, flag) /* empty */-
62# endif-
63#endif-
64-
65/* NonStop circa 2011 lacks SA_RESETHAND; see Bug#9076. */-
66#ifndef SA_RESETHAND-
67# define SA_RESETHAND 0-
68#endif-
69-
70#ifndef SIGINFO-
71# define SIGINFO SIGUSR1-
72#endif-
73-
74/* This may belong in GNULIB's fcntl module instead.-
75 Define O_CIO to 0 if it is not supported by this OS. */-
76#ifndef O_CIO-
77# define O_CIO 0-
78#endif-
79-
80/* On AIX 5.1 and AIX 5.2, O_NOCACHE is defined via <fcntl.h>-
81 and would interfere with our use of that name, below. */-
82#undef O_NOCACHE-
83-
84#if ! HAVE_FDATASYNC-
85# define fdatasync(fd) (errno = ENOSYS, -1)-
86#endif-
87-
88#define output_char(c) \-
89 do \-
90 { \-
91 obuf[oc++] = (c); \-
92 if (oc >= output_blocksize) \-
93 write_output (); \-
94 } \-
95 while (0)-
96-
97/* Default input and output blocksize. */-
98#define DEFAULT_BLOCKSIZE 512-
99-
100/* How many bytes to add to the input and output block sizes before invoking-
101 malloc. See dd_copy for details. INPUT_BLOCK_SLOP must be no less than-
102 OUTPUT_BLOCK_SLOP. */-
103#define INPUT_BLOCK_SLOP (2 * SWAB_ALIGN_OFFSET + 2 * page_size - 1)-
104#define OUTPUT_BLOCK_SLOP (page_size - 1)-
105-
106/* Maximum blocksize for the given SLOP.-
107 Keep it smaller than SIZE_MAX - SLOP, so that we can-
108 allocate buffers that size. Keep it smaller than SSIZE_MAX, for-
109 the benefit of system calls like "read". And keep it smaller than-
110 OFF_T_MAX, for the benefit of the large-offset seek code. */-
111#define MAX_BLOCKSIZE(slop) MIN (SIZE_MAX - (slop), MIN (SSIZE_MAX, OFF_T_MAX))-
112-
113/* Conversions bit masks. */-
114enum-
115 {-
116 C_ASCII = 01,-
117-
118 C_EBCDIC = 02,-
119 C_IBM = 04,-
120 C_BLOCK = 010,-
121 C_UNBLOCK = 020,-
122 C_LCASE = 040,-
123 C_UCASE = 0100,-
124 C_SWAB = 0200,-
125 C_NOERROR = 0400,-
126 C_NOTRUNC = 01000,-
127 C_SYNC = 02000,-
128-
129 /* Use separate input and output buffers, and combine partial-
130 input blocks. */-
131 C_TWOBUFS = 04000,-
132-
133 C_NOCREAT = 010000,-
134 C_EXCL = 020000,-
135 C_FDATASYNC = 040000,-
136 C_FSYNC = 0100000,-
137-
138 C_SPARSE = 0200000-
139 };-
140-
141/* Status levels. */-
142enum-
143 {-
144 STATUS_NONE = 1,-
145 STATUS_NOXFER = 2,-
146 STATUS_DEFAULT = 3,-
147 STATUS_PROGRESS = 4-
148 };-
149-
150/* The name of the input file, or NULL for the standard input. */-
151static char const *input_file = NULL;-
152-
153/* The name of the output file, or NULL for the standard output. */-
154static char const *output_file = NULL;-
155-
156/* The page size on this host. */-
157static size_t page_size;-
158-
159/* The number of bytes in which atomic reads are done. */-
160static size_t input_blocksize = 0;-
161-
162/* The number of bytes in which atomic writes are done. */-
163static size_t output_blocksize = 0;-
164-
165/* Conversion buffer size, in bytes. 0 prevents conversions. */-
166static size_t conversion_blocksize = 0;-
167-
168/* Skip this many records of 'input_blocksize' bytes before input. */-
169static uintmax_t skip_records = 0;-
170-
171/* Skip this many bytes before input in addition of 'skip_records'-
172 records. */-
173static size_t skip_bytes = 0;-
174-
175/* Skip this many records of 'output_blocksize' bytes before output. */-
176static uintmax_t seek_records = 0;-
177-
178/* Skip this many bytes in addition to 'seek_records' records before-
179 output. */-
180static uintmax_t seek_bytes = 0;-
181-
182/* Whether the final output was done with a seek (rather than a write). */-
183static bool final_op_was_seek;-
184-
185/* Copy only this many records. The default is effectively infinity. */-
186static uintmax_t max_records = (uintmax_t) -1;-
187-
188/* Copy this many bytes in addition to 'max_records' records. */-
189static size_t max_bytes = 0;-
190-
191/* Bit vector of conversions to apply. */-
192static int conversions_mask = 0;-
193-
194/* Open flags for the input and output files. */-
195static int input_flags = 0;-
196static int output_flags = 0;-
197-
198/* Status flags for what is printed to stderr. */-
199static int status_level = STATUS_DEFAULT;-
200-
201/* If nonzero, filter characters through the translation table. */-
202static bool translation_needed = false;-
203-
204/* Number of partial blocks written. */-
205static uintmax_t w_partial = 0;-
206-
207/* Number of full blocks written. */-
208static uintmax_t w_full = 0;-
209-
210/* Number of partial blocks read. */-
211static uintmax_t r_partial = 0;-
212-
213/* Number of full blocks read. */-
214static uintmax_t r_full = 0;-
215-
216/* Number of bytes written. */-
217static uintmax_t w_bytes = 0;-
218-
219/* Time that dd started. */-
220static xtime_t start_time;-
221-
222/* Next time to report periodic progress. */-
223static xtime_t next_time;-
224-
225/* If positive, the number of bytes output in the current progress line. */-
226static int progress_len;-
227-
228/* True if input is seekable. */-
229static bool input_seekable;-
230-
231/* Error number corresponding to initial attempt to lseek input.-
232 If ESPIPE, do not issue any more diagnostics about it. */-
233static int input_seek_errno;-
234-
235/* File offset of the input, in bytes, along with a flag recording-
236 whether it overflowed. */-
237static uintmax_t input_offset;-
238static bool input_offset_overflow;-
239-
240/* True if a partial read should be diagnosed. */-
241static bool warn_partial_read;-
242-
243/* Records truncated by conv=block. */-
244static uintmax_t r_truncate = 0;-
245-
246/* Output representation of newline and space characters.-
247 They change if we're converting to EBCDIC. */-
248static char newline_character = '\n';-
249static char space_character = ' ';-
250-
251/* Input buffer. */-
252static char *ibuf;-
253-
254/* Output buffer. */-
255static char *obuf;-
256-
257/* Current index into 'obuf'. */-
258static size_t oc = 0;-
259-
260/* Index into current line, for 'conv=block' and 'conv=unblock'. */-
261static size_t col = 0;-
262-
263/* The set of signals that are caught. */-
264static sigset_t caught_signals;-
265-
266/* If nonzero, the value of the pending fatal signal. */-
267static sig_atomic_t volatile interrupt_signal;-
268-
269/* A count of the number of pending info signals that have been received. */-
270static sig_atomic_t volatile info_signal_count;-
271-
272/* Whether to discard cache for input or output. */-
273static bool i_nocache, o_nocache;-
274-
275/* Whether to instruct the kernel to discard the complete file. */-
276static bool i_nocache_eof, o_nocache_eof;-
277-
278/* Function used for read (to handle iflag=fullblock parameter). */-
279static ssize_t (*iread_fnc) (int fd, char *buf, size_t size);-
280-
281/* A longest symbol in the struct symbol_values tables below. */-
282#define LONGEST_SYMBOL "count_bytes"-
283-
284/* A symbol and the corresponding integer value. */-
285struct symbol_value-
286{-
287 char symbol[sizeof LONGEST_SYMBOL];-
288 int value;-
289};-
290-
291/* Conversion symbols, for conv="...". */-
292static struct symbol_value const conversions[] =-
293{-
294 {"ascii", C_ASCII | C_UNBLOCK | C_TWOBUFS}, /* EBCDIC to ASCII. */-
295 {"ebcdic", C_EBCDIC | C_BLOCK | C_TWOBUFS}, /* ASCII to EBCDIC. */-
296 {"ibm", C_IBM | C_BLOCK | C_TWOBUFS}, /* Different ASCII to EBCDIC. */-
297 {"block", C_BLOCK | C_TWOBUFS}, /* Variable to fixed length records. */-
298 {"unblock", C_UNBLOCK | C_TWOBUFS}, /* Fixed to variable length records. */-
299 {"lcase", C_LCASE | C_TWOBUFS}, /* Translate upper to lower case. */-
300 {"ucase", C_UCASE | C_TWOBUFS}, /* Translate lower to upper case. */-
301 {"sparse", C_SPARSE}, /* Try to sparsely write output. */-
302 {"swab", C_SWAB | C_TWOBUFS}, /* Swap bytes of input. */-
303 {"noerror", C_NOERROR}, /* Ignore i/o errors. */-
304 {"nocreat", C_NOCREAT}, /* Do not create output file. */-
305 {"excl", C_EXCL}, /* Fail if the output file already exists. */-
306 {"notrunc", C_NOTRUNC}, /* Do not truncate output file. */-
307 {"sync", C_SYNC}, /* Pad input records to ibs with NULs. */-
308 {"fdatasync", C_FDATASYNC}, /* Synchronize output data before finishing. */-
309 {"fsync", C_FSYNC}, /* Also synchronize output metadata. */-
310 {"", 0}-
311};-
312-
313#define FFS_MASK(x) ((x) ^ ((x) & ((x) - 1)))-
314enum-
315 {-
316 /* Compute a value that's bitwise disjoint from the union-
317 of all O_ values. */-
318 v = ~(0-
319 | O_APPEND-
320 | O_BINARY-
321 | O_CIO-
322 | O_DIRECT-
323 | O_DIRECTORY-
324 | O_DSYNC-
325 | O_NOATIME-
326 | O_NOCTTY-
327 | O_NOFOLLOW-
328 | O_NOLINKS-
329 | O_NONBLOCK-
330 | O_SYNC-
331 | O_TEXT-
332 ),-
333-
334 /* Use its lowest bits for private flags. */-
335 O_FULLBLOCK = FFS_MASK (v),-
336 v2 = v ^ O_FULLBLOCK,-
337-
338 O_NOCACHE = FFS_MASK (v2),-
339 v3 = v2 ^ O_NOCACHE,-
340-
341 O_COUNT_BYTES = FFS_MASK (v3),-
342 v4 = v3 ^ O_COUNT_BYTES,-
343-
344 O_SKIP_BYTES = FFS_MASK (v4),-
345 v5 = v4 ^ O_SKIP_BYTES,-
346-
347 O_SEEK_BYTES = FFS_MASK (v5)-
348 };-
349-
350/* Ensure that we got something. */-
351verify (O_FULLBLOCK != 0);-
352verify (O_NOCACHE != 0);-
353verify (O_COUNT_BYTES != 0);-
354verify (O_SKIP_BYTES != 0);-
355verify (O_SEEK_BYTES != 0);-
356-
357#define MULTIPLE_BITS_SET(i) (((i) & ((i) - 1)) != 0)-
358-
359/* Ensure that this is a single-bit value. */-
360verify ( ! MULTIPLE_BITS_SET (O_FULLBLOCK));-
361verify ( ! MULTIPLE_BITS_SET (O_NOCACHE));-
362verify ( ! MULTIPLE_BITS_SET (O_COUNT_BYTES));-
363verify ( ! MULTIPLE_BITS_SET (O_SKIP_BYTES));-
364verify ( ! MULTIPLE_BITS_SET (O_SEEK_BYTES));-
365-
366/* Flags, for iflag="..." and oflag="...". */-
367static struct symbol_value const flags[] =-
368{-
369 {"append", O_APPEND},-
370 {"binary", O_BINARY},-
371 {"cio", O_CIO},-
372 {"direct", O_DIRECT},-
373 {"directory", O_DIRECTORY},-
374 {"dsync", O_DSYNC},-
375 {"noatime", O_NOATIME},-
376 {"nocache", O_NOCACHE}, /* Discard cache. */-
377 {"noctty", O_NOCTTY},-
378 {"nofollow", HAVE_WORKING_O_NOFOLLOW ? O_NOFOLLOW : 0},-
379 {"nolinks", O_NOLINKS},-
380 {"nonblock", O_NONBLOCK},-
381 {"sync", O_SYNC},-
382 {"text", O_TEXT},-
383 {"fullblock", O_FULLBLOCK}, /* Accumulate full blocks from input. */-
384 {"count_bytes", O_COUNT_BYTES},-
385 {"skip_bytes", O_SKIP_BYTES},-
386 {"seek_bytes", O_SEEK_BYTES},-
387 {"", 0}-
388};-
389-
390/* Status, for status="...". */-
391static struct symbol_value const statuses[] =-
392{-
393 {"none", STATUS_NONE},-
394 {"noxfer", STATUS_NOXFER},-
395 {"progress", STATUS_PROGRESS},-
396 {"", 0}-
397};-
398-
399/* Translation table formed by applying successive transformations. */-
400static unsigned char trans_table[256];-
401-
402/* Standard translation tables, taken from POSIX 1003.1-2013.-
403 Beware of imitations; there are lots of ASCII<->EBCDIC tables-
404 floating around the net, perhaps valid for some applications but-
405 not correct here. */-
406-
407static char const ascii_to_ebcdic[] =-
408{-
409 '\000', '\001', '\002', '\003', '\067', '\055', '\056', '\057',-
410 '\026', '\005', '\045', '\013', '\014', '\015', '\016', '\017',-
411 '\020', '\021', '\022', '\023', '\074', '\075', '\062', '\046',-
412 '\030', '\031', '\077', '\047', '\034', '\035', '\036', '\037',-
413 '\100', '\132', '\177', '\173', '\133', '\154', '\120', '\175',-
414 '\115', '\135', '\134', '\116', '\153', '\140', '\113', '\141',-
415 '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',-
416 '\370', '\371', '\172', '\136', '\114', '\176', '\156', '\157',-
417 '\174', '\301', '\302', '\303', '\304', '\305', '\306', '\307',-
418 '\310', '\311', '\321', '\322', '\323', '\324', '\325', '\326',-
419 '\327', '\330', '\331', '\342', '\343', '\344', '\345', '\346',-
420 '\347', '\350', '\351', '\255', '\340', '\275', '\232', '\155',-
421 '\171', '\201', '\202', '\203', '\204', '\205', '\206', '\207',-
422 '\210', '\211', '\221', '\222', '\223', '\224', '\225', '\226',-
423 '\227', '\230', '\231', '\242', '\243', '\244', '\245', '\246',-
424 '\247', '\250', '\251', '\300', '\117', '\320', '\137', '\007',-
425 '\040', '\041', '\042', '\043', '\044', '\025', '\006', '\027',-
426 '\050', '\051', '\052', '\053', '\054', '\011', '\012', '\033',-
427 '\060', '\061', '\032', '\063', '\064', '\065', '\066', '\010',-
428 '\070', '\071', '\072', '\073', '\004', '\024', '\076', '\341',-
429 '\101', '\102', '\103', '\104', '\105', '\106', '\107', '\110',-
430 '\111', '\121', '\122', '\123', '\124', '\125', '\126', '\127',-
431 '\130', '\131', '\142', '\143', '\144', '\145', '\146', '\147',-
432 '\150', '\151', '\160', '\161', '\162', '\163', '\164', '\165',-
433 '\166', '\167', '\170', '\200', '\212', '\213', '\214', '\215',-
434 '\216', '\217', '\220', '\152', '\233', '\234', '\235', '\236',-
435 '\237', '\240', '\252', '\253', '\254', '\112', '\256', '\257',-
436 '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',-
437 '\270', '\271', '\272', '\273', '\274', '\241', '\276', '\277',-
438 '\312', '\313', '\314', '\315', '\316', '\317', '\332', '\333',-
439 '\334', '\335', '\336', '\337', '\352', '\353', '\354', '\355',-
440 '\356', '\357', '\372', '\373', '\374', '\375', '\376', '\377'-
441};-
442-
443static char const ascii_to_ibm[] =-
444{-
445 '\000', '\001', '\002', '\003', '\067', '\055', '\056', '\057',-
446 '\026', '\005', '\045', '\013', '\014', '\015', '\016', '\017',-
447 '\020', '\021', '\022', '\023', '\074', '\075', '\062', '\046',-
448 '\030', '\031', '\077', '\047', '\034', '\035', '\036', '\037',-
449 '\100', '\132', '\177', '\173', '\133', '\154', '\120', '\175',-
450 '\115', '\135', '\134', '\116', '\153', '\140', '\113', '\141',-
451 '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',-
452 '\370', '\371', '\172', '\136', '\114', '\176', '\156', '\157',-
453 '\174', '\301', '\302', '\303', '\304', '\305', '\306', '\307',-
454 '\310', '\311', '\321', '\322', '\323', '\324', '\325', '\326',-
455 '\327', '\330', '\331', '\342', '\343', '\344', '\345', '\346',-
456 '\347', '\350', '\351', '\255', '\340', '\275', '\137', '\155',-
457 '\171', '\201', '\202', '\203', '\204', '\205', '\206', '\207',-
458 '\210', '\211', '\221', '\222', '\223', '\224', '\225', '\226',-
459 '\227', '\230', '\231', '\242', '\243', '\244', '\245', '\246',-
460 '\247', '\250', '\251', '\300', '\117', '\320', '\241', '\007',-
461 '\040', '\041', '\042', '\043', '\044', '\025', '\006', '\027',-
462 '\050', '\051', '\052', '\053', '\054', '\011', '\012', '\033',-
463 '\060', '\061', '\032', '\063', '\064', '\065', '\066', '\010',-
464 '\070', '\071', '\072', '\073', '\004', '\024', '\076', '\341',-
465 '\101', '\102', '\103', '\104', '\105', '\106', '\107', '\110',-
466 '\111', '\121', '\122', '\123', '\124', '\125', '\126', '\127',-
467 '\130', '\131', '\142', '\143', '\144', '\145', '\146', '\147',-
468 '\150', '\151', '\160', '\161', '\162', '\163', '\164', '\165',-
469 '\166', '\167', '\170', '\200', '\212', '\213', '\214', '\215',-
470 '\216', '\217', '\220', '\232', '\233', '\234', '\235', '\236',-
471 '\237', '\240', '\252', '\253', '\254', '\255', '\256', '\257',-
472 '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',-
473 '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',-
474 '\312', '\313', '\314', '\315', '\316', '\317', '\332', '\333',-
475 '\334', '\335', '\336', '\337', '\352', '\353', '\354', '\355',-
476 '\356', '\357', '\372', '\373', '\374', '\375', '\376', '\377'-
477};-
478-
479static char const ebcdic_to_ascii[] =-
480{-
481 '\000', '\001', '\002', '\003', '\234', '\011', '\206', '\177',-
482 '\227', '\215', '\216', '\013', '\014', '\015', '\016', '\017',-
483 '\020', '\021', '\022', '\023', '\235', '\205', '\010', '\207',-
484 '\030', '\031', '\222', '\217', '\034', '\035', '\036', '\037',-
485 '\200', '\201', '\202', '\203', '\204', '\012', '\027', '\033',-
486 '\210', '\211', '\212', '\213', '\214', '\005', '\006', '\007',-
487 '\220', '\221', '\026', '\223', '\224', '\225', '\226', '\004',-
488 '\230', '\231', '\232', '\233', '\024', '\025', '\236', '\032',-
489 '\040', '\240', '\241', '\242', '\243', '\244', '\245', '\246',-
490 '\247', '\250', '\325', '\056', '\074', '\050', '\053', '\174',-
491 '\046', '\251', '\252', '\253', '\254', '\255', '\256', '\257',-
492 '\260', '\261', '\041', '\044', '\052', '\051', '\073', '\176',-
493 '\055', '\057', '\262', '\263', '\264', '\265', '\266', '\267',-
494 '\270', '\271', '\313', '\054', '\045', '\137', '\076', '\077',-
495 '\272', '\273', '\274', '\275', '\276', '\277', '\300', '\301',-
496 '\302', '\140', '\072', '\043', '\100', '\047', '\075', '\042',-
497 '\303', '\141', '\142', '\143', '\144', '\145', '\146', '\147',-
498 '\150', '\151', '\304', '\305', '\306', '\307', '\310', '\311',-
499 '\312', '\152', '\153', '\154', '\155', '\156', '\157', '\160',-
500 '\161', '\162', '\136', '\314', '\315', '\316', '\317', '\320',-
501 '\321', '\345', '\163', '\164', '\165', '\166', '\167', '\170',-
502 '\171', '\172', '\322', '\323', '\324', '\133', '\326', '\327',-
503 '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',-
504 '\340', '\341', '\342', '\343', '\344', '\135', '\346', '\347',-
505 '\173', '\101', '\102', '\103', '\104', '\105', '\106', '\107',-
506 '\110', '\111', '\350', '\351', '\352', '\353', '\354', '\355',-
507 '\175', '\112', '\113', '\114', '\115', '\116', '\117', '\120',-
508 '\121', '\122', '\356', '\357', '\360', '\361', '\362', '\363',-
509 '\134', '\237', '\123', '\124', '\125', '\126', '\127', '\130',-
510 '\131', '\132', '\364', '\365', '\366', '\367', '\370', '\371',-
511 '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',-
512 '\070', '\071', '\372', '\373', '\374', '\375', '\376', '\377'-
513};-
514-
515/* True if we need to close the standard output *stream*. */-
516static bool close_stdout_required = true;-
517-
518/* The only reason to close the standard output *stream* is if-
519 parse_long_options fails (as it does for --help or --version).-
520 In any other case, dd uses only the STDOUT_FILENO file descriptor,-
521 and the "cleanup" function calls "close (STDOUT_FILENO)".-
522 Closing the file descriptor and then letting the usual atexit-run-
523 close_stdout function call "fclose (stdout)" would result in a-
524 harmless failure of the close syscall (with errno EBADF).-
525 This function serves solely to avoid the unnecessary close_stdout-
526 call, once parse_long_options has succeeded.-
527 Meanwhile, we guarantee that the standard error stream is flushed,-
528 by inlining the last half of close_stdout as needed. */-
529static void-
530maybe_close_stdout (void)-
531{-
532 if (close_stdout_required)
close_stdout_requiredDescription
TRUEevaluated 25 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 633 times by 1 test
Evaluated by:
  • dd
25-633
533 close_stdout ();
executed 25 times by 1 test: close_stdout ();
Executed by:
  • dd
25
534 else if (close_stream (stderr) != 0)
close_stream ( stderr ) != 0Description
TRUEnever evaluated
FALSEevaluated 633 times by 1 test
Evaluated by:
  • dd
0-633
535 _exit (EXIT_FAILURE);
never executed: _exit ( 1 );
0
536}
executed 658 times by 1 test: end of block
Executed by:
  • dd
658
537-
538/* Like error() but handle any pending newline. */-
539-
540static void _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4))-
541nl_error (int status, int errnum, const char *fmt, ...)-
542{-
543 if (0 < progress_len)
0 < progress_lenDescription
TRUEnever evaluated
FALSEevaluated 20 times by 1 test
Evaluated by:
  • dd
0-20
544 {-
545 fputc ('\n', stderr);-
546 progress_len = 0;-
547 }
never executed: end of block
0
548-
549 va_list ap;-
550 va_start (ap, fmt);-
551 verror (status, errnum, fmt, ap);-
552 va_end (ap);-
553}
executed 13 times by 1 test: end of block
Executed by:
  • dd
13
554-
555#define error nl_error-
556-
557void-
558usage (int status)-
559{-
560 if (status != EXIT_SUCCESS)
status != 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 4 times by 1 test
Evaluated by:
  • dd
4
561 emit_try_help ();
executed 4 times by 1 test: end of block
Executed by:
  • dd
4
562 else-
563 {-
564 printf (_("\-
565Usage: %s [OPERAND]...\n\-
566 or: %s OPTION\n\-
567"),-
568 program_name, program_name);-
569 fputs (_("\-
570Copy a file, converting and formatting according to the operands.\n\-
571\n\-
572 bs=BYTES read and write up to BYTES bytes at a time (default: 512);\n\-
573 overrides ibs and obs\n\-
574 cbs=BYTES convert BYTES bytes at a time\n\-
575 conv=CONVS convert the file as per the comma separated symbol list\n\-
576 count=N copy only N input blocks\n\-
577 ibs=BYTES read up to BYTES bytes at a time (default: 512)\n\-
578"), stdout);-
579 fputs (_("\-
580 if=FILE read from FILE instead of stdin\n\-
581 iflag=FLAGS read as per the comma separated symbol list\n\-
582 obs=BYTES write BYTES bytes at a time (default: 512)\n\-
583 of=FILE write to FILE instead of stdout\n\-
584 oflag=FLAGS write as per the comma separated symbol list\n\-
585 seek=N skip N obs-sized blocks at start of output\n\-
586 skip=N skip N ibs-sized blocks at start of input\n\-
587 status=LEVEL The LEVEL of information to print to stderr;\n\-
588 'none' suppresses everything but error messages,\n\-
589 'noxfer' suppresses the final transfer statistics,\n\-
590 'progress' shows periodic transfer statistics\n\-
591"), stdout);-
592 fputs (_("\-
593\n\-
594N and BYTES may be followed by the following multiplicative suffixes:\n\-
595c =1, w =2, b =512, kB =1000, K =1024, MB =1000*1000, M =1024*1024, xM =M,\n\-
596GB =1000*1000*1000, G =1024*1024*1024, and so on for T, P, E, Z, Y.\n\-
597\n\-
598Each CONV symbol may be:\n\-
599\n\-
600"), stdout);-
601 fputs (_("\-
602 ascii from EBCDIC to ASCII\n\-
603 ebcdic from ASCII to EBCDIC\n\-
604 ibm from ASCII to alternate EBCDIC\n\-
605 block pad newline-terminated records with spaces to cbs-size\n\-
606 unblock replace trailing spaces in cbs-size records with newline\n\-
607 lcase change upper case to lower case\n\-
608 ucase change lower case to upper case\n\-
609 sparse try to seek rather than write the output for NUL input blocks\n\-
610 swab swap every pair of input bytes\n\-
611 sync pad every input block with NULs to ibs-size; when used\n\-
612 with block or unblock, pad with spaces rather than NULs\n\-
613"), stdout);-
614 fputs (_("\-
615 excl fail if the output file already exists\n\-
616 nocreat do not create the output file\n\-
617 notrunc do not truncate the output file\n\-
618 noerror continue after read errors\n\-
619 fdatasync physically write output file data before finishing\n\-
620 fsync likewise, but also write metadata\n\-
621"), stdout);-
622 fputs (_("\-
623\n\-
624Each FLAG symbol may be:\n\-
625\n\-
626 append append mode (makes sense only for output; conv=notrunc suggested)\n\-
627"), stdout);-
628 if (O_CIO)
dead code: fputs_unlocked ( dcgettext (((void *)0), " cio use concurrent I/O for data\n" , 5) , stdout );
-
629 fputs (_(" cio use concurrent I/O for data\n"), stdout);
dead code: fputs_unlocked ( dcgettext (((void *)0), " cio use concurrent I/O for data\n" , 5) , stdout );
-
630 if (O_DIRECT)-
631 fputs (_(" direct use direct I/O for data\n"), stdout);
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " direct use direct I/O for data\n" , 5) , stdout );
Executed by:
  • dd
4
632 if (O_DIRECTORY)-
633 fputs (_(" directory fail unless a directory\n"), stdout);
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " directory fail unless a directory\n" , 5) , stdout );
Executed by:
  • dd
4
634 if (O_DSYNC)-
635 fputs (_(" dsync use synchronized I/O for data\n"), stdout);
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " dsync use synchronized I/O for data\n" , 5) , stdout );
Executed by:
  • dd
4
636 if (O_SYNC)-
637 fputs (_(" sync likewise, but also for metadata\n"), stdout);
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " sync likewise, but also for metadata\n" , 5) , stdout );
Executed by:
  • dd
4
638 fputs (_(" fullblock accumulate full blocks of input (iflag only)\n"),-
639 stdout);-
640 if (O_NONBLOCK)-
641 fputs (_(" nonblock use non-blocking I/O\n"), stdout);
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " nonblock use non-blocking I/O\n" , 5) , stdout );
Executed by:
  • dd
4
642 if (O_NOATIME)-
643 fputs (_(" noatime do not update access time\n"), stdout);
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " noatime do not update access time\n" , 5) , stdout );
Executed by:
  • dd
4
644#if HAVE_POSIX_FADVISE-
645 if (O_NOCACHE)
O_NOCACHEDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-4
646 fputs (_(" nocache Request to drop cache. See also oflag=sync\n"),
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " nocache Request to drop cache. See also oflag=sync\n" , 5) , stdout ) ;
Executed by:
  • dd
4
647 stdout);
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " nocache Request to drop cache. See also oflag=sync\n" , 5) , stdout ) ;
Executed by:
  • dd
4
648#endif-
649 if (O_NOCTTY)-
650 fputs (_(" noctty do not assign controlling terminal from file\n"),
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " noctty do not assign controlling terminal from file\n" , 5) , stdout ) ;
Executed by:
  • dd
4
651 stdout);
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " noctty do not assign controlling terminal from file\n" , 5) , stdout ) ;
Executed by:
  • dd
4
652 if (HAVE_WORKING_O_NOFOLLOW)-
653 fputs (_(" nofollow do not follow symlinks\n"), stdout);
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " nofollow do not follow symlinks\n" , 5) , stdout );
Executed by:
  • dd
4
654 if (O_NOLINKS)
dead code: fputs_unlocked ( dcgettext (((void *)0), " nolinks fail if multiply-linked\n" , 5) , stdout );
-
655 fputs (_(" nolinks fail if multiply-linked\n"), stdout);
dead code: fputs_unlocked ( dcgettext (((void *)0), " nolinks fail if multiply-linked\n" , 5) , stdout );
-
656 if (O_BINARY)
dead code: fputs_unlocked ( dcgettext (((void *)0), " binary use binary I/O for data\n" , 5) , stdout );
-
657 fputs (_(" binary use binary I/O for data\n"), stdout);
dead code: fputs_unlocked ( dcgettext (((void *)0), " binary use binary I/O for data\n" , 5) , stdout );
-
658 if (O_TEXT)
dead code: fputs_unlocked ( dcgettext (((void *)0), " text use text I/O for data\n" , 5) , stdout );
-
659 fputs (_(" text use text I/O for data\n"), stdout);
dead code: fputs_unlocked ( dcgettext (((void *)0), " text use text I/O for data\n" , 5) , stdout );
-
660 if (O_COUNT_BYTES)
O_COUNT_BYTESDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-4
661 fputs (_(" count_bytes treat 'count=N' as a byte count (iflag only)\n\
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " count_bytes treat 'count=N' as a byte count (iflag only)\n" , 5) , stdout ) ;
Executed by:
  • dd
4
662"
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " count_bytes treat 'count=N' as a byte count (iflag only)\n" , 5) , stdout ) ;
Executed by:
  • dd
), stdout);
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " count_bytes treat 'count=N' as a byte count (iflag only)\n" , 5) , stdout ) ;
Executed by:
  • dd
4
663 if (O_SKIP_BYTES)
O_SKIP_BYTESDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-4
664 fputs (_(" skip_bytes treat 'skip=N' as a byte count (iflag only)\n\
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " skip_bytes treat 'skip=N' as a byte count (iflag only)\n" , 5) , stdout ) ;
Executed by:
  • dd
4
665"
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " skip_bytes treat 'skip=N' as a byte count (iflag only)\n" , 5) , stdout ) ;
Executed by:
  • dd
), stdout);
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " skip_bytes treat 'skip=N' as a byte count (iflag only)\n" , 5) , stdout ) ;
Executed by:
  • dd
4
666 if (O_SEEK_BYTES)
O_SEEK_BYTESDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-4
667 fputs (_(" seek_bytes treat 'seek=N' as a byte count (oflag only)\n\
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " seek_bytes treat 'seek=N' as a byte count (oflag only)\n" , 5) , stdout ) ;
Executed by:
  • dd
4
668"
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " seek_bytes treat 'seek=N' as a byte count (oflag only)\n" , 5) , stdout ) ;
Executed by:
  • dd
), stdout);
executed 4 times by 1 test: fputs_unlocked ( dcgettext (((void *)0), " seek_bytes treat 'seek=N' as a byte count (oflag only)\n" , 5) , stdout ) ;
Executed by:
  • dd
4
669-
670 {-
671 printf (_("\-
672\n\-
673Sending a %s signal to a running 'dd' process makes it\n\-
674print I/O statistics to standard error and then resume copying.\n\-
675\n\-
676Options are:\n\-
677\n\-
678"), SIGINFO == SIGUSR1 ? "USR1" : "INFO");-
679 }-
680-
681 fputs (HELP_OPTION_DESCRIPTION, stdout);-
682 fputs (VERSION_OPTION_DESCRIPTION, stdout);-
683 emit_ancillary_info (PROGRAM_NAME);-
684 }
executed 4 times by 1 test: end of block
Executed by:
  • dd
4
685 exit (status);
executed 8 times by 1 test: exit (status);
Executed by:
  • dd
8
686}-
687-
688/* Common options to use when displaying sizes and rates. */-
689-
690enum { human_opts = (human_autoscale | human_round_to_nearest-
691 | human_space_before_unit | human_SI | human_B) };-
692-
693/* Ensure input buffer IBUF is allocated. */-
694-
695static void-
696alloc_ibuf (void)-
697{-
698 if (ibuf)
ibufDescription
TRUEevaluated 531 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 600 times by 1 test
Evaluated by:
  • dd
531-600
699 return;
executed 531 times by 1 test: return;
Executed by:
  • dd
531
700-
701 char *real_buf = malloc (input_blocksize + INPUT_BLOCK_SLOP);-
702 if (!real_buf)
!real_bufDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 597 times by 1 test
Evaluated by:
  • dd
3-597
703 {-
704 uintmax_t ibs = input_blocksize;-
705 char hbuf[LONGEST_HUMAN_READABLE + 1];-
706 die (EXIT_FAILURE, 0,-
707 _("memory exhausted by input buffer of size %"PRIuMAX" bytes (%s)"),-
708 ibs,-
709 human_readable (input_blocksize, hbuf,-
710 human_opts | human_base_1024, 1, 1));-
711 }
never executed: end of block
0
712-
713 real_buf += SWAB_ALIGN_OFFSET; /* allow space for swab */-
714-
715 ibuf = ptr_align (real_buf, page_size);-
716}
executed 597 times by 1 test: end of block
Executed by:
  • dd
597
717-
718/* Ensure output buffer OBUF is allocated/initialized. */-
719-
720static void-
721alloc_obuf (void)-
722{-
723 if (obuf)
obufDescription
TRUEnever evaluated
FALSEevaluated 597 times by 1 test
Evaluated by:
  • dd
0-597
724 return;
never executed: return;
0
725-
726 if (conversions_mask & C_TWOBUFS)
conversions_mask & C_TWOBUFSDescription
TRUEevaluated 67 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 530 times by 1 test
Evaluated by:
  • dd
67-530
727 {-
728 /* Page-align the output buffer, too. */-
729 char *real_obuf = malloc (output_blocksize + OUTPUT_BLOCK_SLOP);-
730 if (!real_obuf)
!real_obufDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 66 times by 1 test
Evaluated by:
  • dd
1-66
731 {-
732 uintmax_t obs = output_blocksize;-
733 char hbuf[LONGEST_HUMAN_READABLE + 1];-
734 die (EXIT_FAILURE, 0,-
735 _("memory exhausted by output buffer of size %"PRIuMAX-
736 " bytes (%s)"),-
737 obs,-
738 human_readable (output_blocksize, hbuf,-
739 human_opts | human_base_1024, 1, 1));-
740 }
never executed: end of block
0
741 obuf = ptr_align (real_obuf, page_size);-
742 }
executed 66 times by 1 test: end of block
Executed by:
  • dd
66
743 else-
744 {-
745 alloc_ibuf ();-
746 obuf = ibuf;-
747 }
executed 529 times by 1 test: end of block
Executed by:
  • dd
529
748}-
749-
750static void-
751translate_charset (char const *new_trans)-
752{-
753 for (int i = 0; i < 256; i++)
i < 256Description
TRUEevaluated 256 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1-256
754 trans_table[i] = new_trans[trans_table[i]];
executed 256 times by 1 test: trans_table[i] = new_trans[trans_table[i]];
Executed by:
  • dd
256
755 translation_needed = true;-
756}
executed 1 time by 1 test: end of block
Executed by:
  • dd
1
757-
758/* Return true if I has more than one bit set. I must be nonnegative. */-
759-
760static inline bool-
761multiple_bits_set (int i)-
762{-
763 return MULTIPLE_BITS_SET (i);
executed 3773 times by 1 test: return (((i) & ((i) - 1)) != 0);
Executed by:
  • dd
3773
764}-
765-
766static bool-
767abbreviation_lacks_prefix (char const *message)-
768{-
769 return message[strlen (message) - 2] == ' ';
executed 233 times by 1 test: return message[strlen (message) - 2] == ' ';
Executed by:
  • dd
233
770}-
771-
772/* Print transfer statistics. */-
773-
774static void-
775print_xfer_stats (xtime_t progress_time)-
776{-
777 xtime_t now = progress_time ? progress_time : gethrxtime ();
progress_timeDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 149 times by 1 test
Evaluated by:
  • dd
1-149
778 static char const slash_s[] = "/s";-
779 char hbuf[3][LONGEST_HUMAN_READABLE + sizeof slash_s];-
780 double delta_s;-
781 char const *bytes_per_second;-
782 char const *si = human_readable (w_bytes, hbuf[0], human_opts, 1, 1);-
783 char const *iec = human_readable (w_bytes, hbuf[1],-
784 human_opts | human_base_1024, 1, 1);-
785-
786 /* Use integer arithmetic to compute the transfer rate,-
787 since that makes it easy to use SI abbreviations. */-
788 char *bpsbuf = hbuf[2];-
789 int bpsbufsize = sizeof hbuf[2];-
790 if (start_time < now)
start_time < nowDescription
TRUEevaluated 150 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-150
791 {-
792 double XTIME_PRECISIONe0 = XTIME_PRECISION;-
793 uintmax_t delta_xtime = now;-
794 delta_xtime -= start_time;-
795 delta_s = delta_xtime / XTIME_PRECISIONe0;-
796 bytes_per_second = human_readable (w_bytes, bpsbuf, human_opts,-
797 XTIME_PRECISION, delta_xtime);-
798 strcat (bytes_per_second - bpsbuf + bpsbuf, slash_s);-
799 }
executed 150 times by 1 test: end of block
Executed by:
  • dd
150
800 else-
801 {-
802 delta_s = 0;-
803 snprintf (bpsbuf, bpsbufsize, "%s B/s", _("Infinity"));-
804 bytes_per_second = bpsbuf;-
805 }
never executed: end of block
0
806-
807 if (progress_time)
progress_timeDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 149 times by 1 test
Evaluated by:
  • dd
1-149
808 fputc ('\r', stderr);
executed 1 time by 1 test: fputc_unlocked ('\r', stderr );
Executed by:
  • dd
1
809-
810 /* Use full seconds when printing progress, since the progress-
811 report is output once per second and there is little point-
812 displaying any subsecond jitter. Use default precision with %g-
813 otherwise, as this provides more-useful output then. With long-
814 transfers %g can generate a number with an exponent; that is OK. */-
815 char delta_s_buf[24];-
816 snprintf (delta_s_buf, sizeof delta_s_buf,-
817 progress_time ? "%.0f s" : "%g s", delta_s);-
818-
819 int stats_len-
820 = (abbreviation_lacks_prefix (si)
abbreviation_lacks_prefix (si)Description
TRUEevaluated 67 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 83 times by 1 test
Evaluated by:
  • dd
67-83
821 ? fprintf (stderr,-
822 ngettext ("%"PRIuMAX" byte copied, %s, %s",-
823 "%"PRIuMAX" bytes copied, %s, %s",-
824 select_plural (w_bytes)),-
825 w_bytes, delta_s_buf, bytes_per_second)-
826 : abbreviation_lacks_prefix (iec)
abbreviation_l...s_prefix (iec)Description
TRUEnever evaluated
FALSEevaluated 83 times by 1 test
Evaluated by:
  • dd
0-83
827 ? fprintf (stderr,-
828 _("%"PRIuMAX" bytes (%s) copied, %s, %s"),-
829 w_bytes, si, delta_s_buf, bytes_per_second)-
830 : fprintf (stderr,-
831 _("%"PRIuMAX" bytes (%s, %s) copied, %s, %s"),-
832 w_bytes, si, iec, delta_s_buf, bytes_per_second));-
833-
834 if (progress_time)
progress_timeDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 149 times by 1 test
Evaluated by:
  • dd
1-149
835 {-
836 /* Erase any trailing junk on the output line by outputting-
837 spaces. In theory this could glitch the display because the-
838 formatted translation of a line describing a larger file-
839 could consume fewer screen columns than the strlen difference-
840 from the previously formatted translation. In practice this-
841 does not seem to be a problem. */-
842 if (0 <= stats_len && stats_len < progress_len)
0 <= stats_lenDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
stats_len < progress_lenDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
0-1
843 fprintf (stderr, "%*s", progress_len - stats_len, "");
never executed: fprintf ( stderr , "%*s", progress_len - stats_len, "");
0
844 progress_len = stats_len;-
845 }
executed 1 time by 1 test: end of block
Executed by:
  • dd
1
846 else-
847 fputc ('\n', stderr);
executed 149 times by 1 test: fputc_unlocked ('\n', stderr );
Executed by:
  • dd
149
848}-
849-
850static void-
851print_stats (void)-
852{-
853 if (status_level == STATUS_NONE)
status_level == STATUS_NONEDescription
TRUEevaluated 505 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 174 times by 1 test
Evaluated by:
  • dd
174-505
854 return;
executed 505 times by 1 test: return;
Executed by:
  • dd
505
855-
856 if (0 < progress_len)
0 < progress_lenDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 173 times by 1 test
Evaluated by:
  • dd
1-173
857 {-
858 fputc ('\n', stderr);-
859 progress_len = 0;-
860 }
executed 1 time by 1 test: end of block
Executed by:
  • dd
1
861-
862 fprintf (stderr,-
863 _("%"PRIuMAX"+%"PRIuMAX" records in\n"-
864 "%"PRIuMAX"+%"PRIuMAX" records out\n"),-
865 r_full, r_partial, w_full, w_partial);-
866-
867 if (r_truncate != 0)
r_truncate != 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 173 times by 1 test
Evaluated by:
  • dd
1-173
868 fprintf (stderr,
executed 1 time by 1 test: fprintf ( stderr , dcngettext (((void *)0), "%" "l" "u" " truncated record\n" , "%" "l" "u" " truncated records\n" , select_plural (r_truncate) , 5) , r_truncate);
Executed by:
  • dd
1
869 ngettext ("%"PRIuMAX" truncated record\n",
executed 1 time by 1 test: fprintf ( stderr , dcngettext (((void *)0), "%" "l" "u" " truncated record\n" , "%" "l" "u" " truncated records\n" , select_plural (r_truncate) , 5) , r_truncate);
Executed by:
  • dd
1
870 "%"PRIuMAX" truncated records\n",
executed 1 time by 1 test: fprintf ( stderr , dcngettext (((void *)0), "%" "l" "u" " truncated record\n" , "%" "l" "u" " truncated records\n" , select_plural (r_truncate) , 5) , r_truncate);
Executed by:
  • dd
1
871 select_plural (r_truncate)),
executed 1 time by 1 test: fprintf ( stderr , dcngettext (((void *)0), "%" "l" "u" " truncated record\n" , "%" "l" "u" " truncated records\n" , select_plural (r_truncate) , 5) , r_truncate);
Executed by:
  • dd
1
872 r_truncate);
executed 1 time by 1 test: fprintf ( stderr , dcngettext (((void *)0), "%" "l" "u" " truncated record\n" , "%" "l" "u" " truncated records\n" , select_plural (r_truncate) , 5) , r_truncate);
Executed by:
  • dd
1
873-
874 if (status_level == STATUS_NOXFER)
status_level == STATUS_NOXFERDescription
TRUEevaluated 25 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 149 times by 1 test
Evaluated by:
  • dd
25-149
875 return;
executed 25 times by 1 test: return;
Executed by:
  • dd
25
876-
877 print_xfer_stats (0);-
878}
executed 149 times by 1 test: end of block
Executed by:
  • dd
149
879-
880/* An ordinary signal was received; arrange for the program to exit. */-
881-
882static void-
883interrupt_handler (int sig)-
884{-
885 if (! SA_RESETHAND)
! 0x80000000Description
TRUEnever evaluated
FALSEnever evaluated
dead code: signal (sig, ((__sighandler_t) 0) );
-
886 signal (sig, SIG_DFL);
dead code: signal (sig, ((__sighandler_t) 0) );
-
887 interrupt_signal = sig;-
888}
never executed: end of block
0
889-
890/* An info signal was received; arrange for the program to print status. */-
891-
892static void-
893siginfo_handler (int sig)-
894{-
895 if (! SA_NOCLDSTOP)
! 1Description
TRUEnever evaluated
FALSEevaluated 59 times by 1 test
Evaluated by:
  • dd
dead code: signal (sig, siginfo_handler);
-
896 signal (sig, siginfo_handler);
dead code: signal (sig, siginfo_handler);
-
897 info_signal_count++;-
898}
executed 59 times by 1 test: end of block
Executed by:
  • dd
59
899-
900/* Install the signal handlers. */-
901-
902static void-
903install_signal_handlers (void)-
904{-
905 bool catch_siginfo = ! (SIGINFO == SIGUSR1 && getenv ("POSIXLY_CORRECT"));
10 == 10Description
TRUEevaluated 658 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
getenv ("POSIXLY_CORRECT")Description
TRUEnever evaluated
FALSEevaluated 658 times by 1 test
Evaluated by:
  • dd
0-658
906-
907#if SA_NOCLDSTOP-
908-
909 struct sigaction act;-
910 sigemptyset (&caught_signals);-
911 if (catch_siginfo)
catch_siginfoDescription
TRUEevaluated 658 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-658
912 sigaddset (&caught_signals, SIGINFO);
executed 658 times by 1 test: sigaddset (&caught_signals, 10 );
Executed by:
  • dd
658
913 sigaction (SIGINT, NULL, &act);-
914 if (act.sa_handler != SIG_IGN)
act. __sigacti...ghandler_t) 1)Description
TRUEevaluated 658 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-658
915 sigaddset (&caught_signals, SIGINT);
executed 658 times by 1 test: sigaddset (&caught_signals, 2 );
Executed by:
  • dd
658
916 act.sa_mask = caught_signals;-
917-
918 if (sigismember (&caught_signals, SIGINFO))
sigismember (&..._signals, 10 )Description
TRUEevaluated 658 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-658
919 {-
920 act.sa_handler = siginfo_handler;-
921 /* Note we don't use SA_RESTART here and instead-
922 handle EINTR explicitly in iftruncate() etc.-
923 to avoid blocking on noncommitted read()/write() calls. */-
924 act.sa_flags = 0;-
925 sigaction (SIGINFO, &act, NULL);-
926 }
executed 658 times by 1 test: end of block
Executed by:
  • dd
658
927-
928 if (sigismember (&caught_signals, SIGINT))
sigismember (&...t_signals, 2 )Description
TRUEevaluated 658 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-658
929 {-
930 act.sa_handler = interrupt_handler;-
931 act.sa_flags = SA_NODEFER | SA_RESETHAND;-
932 sigaction (SIGINT, &act, NULL);-
933 }
executed 658 times by 1 test: end of block
Executed by:
  • dd
658
934-
935#else-
936-
937 if (catch_siginfo)-
938 {-
939 signal (SIGINFO, siginfo_handler);-
940 siginterrupt (SIGINFO, 1);-
941 }-
942 if (signal (SIGINT, SIG_IGN) != SIG_IGN)-
943 {-
944 signal (SIGINT, interrupt_handler);-
945 siginterrupt (SIGINT, 1);-
946 }-
947#endif-
948}
executed 658 times by 1 test: end of block
Executed by:
  • dd
658
949-
950static void-
951cleanup (void)-
952{-
953 if (close (STDIN_FILENO) < 0)
close ( 0 ) < 0Description
TRUEnever evaluated
FALSEevaluated 622 times by 1 test
Evaluated by:
  • dd
0-622
954 die (EXIT_FAILURE, errno, _("closing input file %s"), quoteaf (input_file));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"closing input file %s\", 5), quotearg_style (shell_escape_always_quoting_style, input_file)), assume (false))" ")"); int _gl_d... ? (void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "closing input file %s" , 5) , quotearg_style (shell_escape_always_quoting_style, input_file)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
955-
956 /* Don't remove this call to close, even though close_stdout-
957 closes standard output. This close is necessary when cleanup-
958 is called as part of a signal handler. */-
959 if (close (STDOUT_FILENO) < 0)
close ( 1 ) < 0Description
TRUEnever evaluated
FALSEevaluated 622 times by 1 test
Evaluated by:
  • dd
0-622
960 die (EXIT_FAILURE, errno,
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"closing output file %s\", 5), quotearg_style (shell_escape_always_quoting_style, output_file)), assume (false))" ")"); int _gl...(void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "closing output file %s" , 5) , quotearg_style (shell_escape_always_quoting_style, output_file)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
961 _("closing output file %s"), quoteaf (output_file));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"closing output file %s\", 5), quotearg_style (shell_escape_always_quoting_style, output_file)), assume (false))" ")"); int _gl...(void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "closing output file %s" , 5) , quotearg_style (shell_escape_always_quoting_style, output_file)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
962}
executed 622 times by 1 test: end of block
Executed by:
  • dd
622
963-
964/* Process any pending signals. If signals are caught, this function-
965 should be called periodically. Ideally there should never be an-
966 unbounded amount of time when signals are not being processed. */-
967-
968static void-
969process_signals (void)-
970{-
971 while (interrupt_signal || info_signal_count)
interrupt_signalDescription
TRUEnever evaluated
FALSEevaluated 7843 times by 1 test
Evaluated by:
  • dd
info_signal_countDescription
TRUEevaluated 57 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 7786 times by 1 test
Evaluated by:
  • dd
0-7843
972 {-
973 int interrupt;-
974 int infos;-
975 sigset_t oldset;-
976-
977 sigprocmask (SIG_BLOCK, &caught_signals, &oldset);-
978-
979 /* Reload interrupt_signal and info_signal_count, in case a new-
980 signal was handled before sigprocmask took effect. */-
981 interrupt = interrupt_signal;-
982 infos = info_signal_count;-
983-
984 if (infos)
infosDescription
TRUEevaluated 57 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-57
985 info_signal_count = infos - 1;
executed 57 times by 1 test: info_signal_count = infos - 1;
Executed by:
  • dd
57
986-
987 sigprocmask (SIG_SETMASK, &oldset, NULL);-
988-
989 if (interrupt)
interruptDescription
TRUEnever evaluated
FALSEevaluated 57 times by 1 test
Evaluated by:
  • dd
0-57
990 cleanup ();
never executed: cleanup ();
0
991 print_stats ();-
992 if (interrupt)
interruptDescription
TRUEnever evaluated
FALSEevaluated 57 times by 1 test
Evaluated by:
  • dd
0-57
993 raise (interrupt);
never executed: raise (interrupt);
0
994 }
executed 57 times by 1 test: end of block
Executed by:
  • dd
57
995}
executed 7786 times by 1 test: end of block
Executed by:
  • dd
7786
996-
997static void-
998finish_up (void)-
999{-
1000 cleanup ();-
1001 print_stats ();-
1002 process_signals ();-
1003}
executed 622 times by 1 test: end of block
Executed by:
  • dd
622
1004-
1005static void ATTRIBUTE_NORETURN-
1006quit (int code)-
1007{-
1008 finish_up ();-
1009 exit (code);
executed 2 times by 1 test: exit (code);
Executed by:
  • dd
2
1010}-
1011-
1012/* Return LEN rounded down to a multiple of IO_BUFSIZE-
1013 (to minimize calls to the expensive posix_fadvise(,POSIX_FADV_DONTNEED),-
1014 while storing the remainder internally per FD.-
1015 Pass LEN == 0 to get the current remainder. */-
1016-
1017static off_t-
1018cache_round (int fd, off_t len)-
1019{-
1020 static off_t i_pending, o_pending;-
1021 off_t *pending = (fd == STDIN_FILENO ? &i_pending : &o_pending);
fd == 0Description
TRUEevaluated 432 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 123 times by 1 test
Evaluated by:
  • dd
123-432
1022-
1023 if (len)
lenDescription
TRUEevaluated 519 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 36 times by 1 test
Evaluated by:
  • dd
36-519
1024 {-
1025 uintmax_t c_pending = *pending + len;-
1026 *pending = c_pending % IO_BUFSIZE;-
1027 if (c_pending > *pending)
c_pending > *pendingDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 509 times by 1 test
Evaluated by:
  • dd
10-509
1028 len = c_pending - *pending;
executed 10 times by 1 test: len = c_pending - *pending;
Executed by:
  • dd
10
1029 else-
1030 len = 0;
executed 509 times by 1 test: len = 0;
Executed by:
  • dd
509
1031 }-
1032 else-
1033 len = *pending;
executed 36 times by 1 test: len = *pending;
Executed by:
  • dd
36
1034-
1035 return len;
executed 555 times by 1 test: return len;
Executed by:
  • dd
555
1036}-
1037-
1038/* Discard the cache from the current offset of either-
1039 STDIN_FILENO or STDOUT_FILENO.-
1040 Return true on success. */-
1041-
1042static bool-
1043invalidate_cache (int fd, off_t len)-
1044{-
1045 int adv_ret = -1;-
1046 off_t offset;-
1047 bool nocache_eof = (fd == STDIN_FILENO ? i_nocache_eof : o_nocache_eof);
fd == 0Description
TRUEevaluated 426 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 119 times by 1 test
Evaluated by:
  • dd
119-426
1048-
1049 /* Minimize syscalls. */-
1050 off_t clen = cache_round (fd, len);-
1051 if (len && !clen)
lenDescription
TRUEevaluated 519 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 26 times by 1 test
Evaluated by:
  • dd
!clenDescription
TRUEevaluated 509 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 10 times by 1 test
Evaluated by:
  • dd
10-519
1052 return true; /* Don't advise this time. */
executed 509 times by 1 test: return 1 ;
Executed by:
  • dd
509
1053 else if (! len && ! clen && ! nocache_eof)
! lenDescription
TRUEevaluated 26 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 10 times by 1 test
Evaluated by:
  • dd
! clenDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 8 times by 1 test
Evaluated by:
  • dd
! nocache_eofDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 17 times by 1 test
Evaluated by:
  • dd
1-26
1054 return true;
executed 1 time by 1 test: return 1 ;
Executed by:
  • dd
1
1055 off_t pending = len ? cache_round (fd, 0) : 0;
lenDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 25 times by 1 test
Evaluated by:
  • dd
10-25
1056-
1057 if (fd == STDIN_FILENO)
fd == 0Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 19 times by 1 test
Evaluated by:
  • dd
16-19
1058 {-
1059 if (input_seekable)
input_seekableDescription
TRUEevaluated 15 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1-15
1060 offset = input_offset;
executed 15 times by 1 test: offset = input_offset;
Executed by:
  • dd
15
1061 else-
1062 {-
1063 offset = -1;-
1064 errno = ESPIPE;-
1065 }
executed 1 time by 1 test: end of block
Executed by:
  • dd
1
1066 }-
1067 else-
1068 {-
1069 static off_t output_offset = -2;-
1070-
1071 if (output_offset != -1)
output_offset != -1Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-19
1072 {-
1073 if (output_offset < 0)
output_offset < 0Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 9 times by 1 test
Evaluated by:
  • dd
9-10
1074 output_offset = lseek (fd, 0, SEEK_CUR);
executed 10 times by 1 test: output_offset = lseek (fd, 0, 1 );
Executed by:
  • dd
10
1075 else if (len)
lenDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 7 times by 1 test
Evaluated by:
  • dd
2-7
1076 output_offset += clen + pending;
executed 2 times by 1 test: output_offset += clen + pending;
Executed by:
  • dd
2
1077 }
executed 19 times by 1 test: end of block
Executed by:
  • dd
19
1078-
1079 offset = output_offset;-
1080 }
executed 19 times by 1 test: end of block
Executed by:
  • dd
19
1081-
1082 if (0 <= offset)
0 <= offsetDescription
TRUEevaluated 34 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1-34
1083 {-
1084 if (! len && clen && nocache_eof)
! lenDescription
TRUEevaluated 24 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 10 times by 1 test
Evaluated by:
  • dd
clenDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 16 times by 1 test
Evaluated by:
  • dd
nocache_eofDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 2 times by 1 test
Evaluated by:
  • dd
2-24
1085 {-
1086 pending = clen;-
1087 clen = 0;-
1088 }
executed 6 times by 1 test: end of block
Executed by:
  • dd
6
1089-
1090 /* Note we're being careful here to only invalidate what-
1091 we've read, so as not to dump any read ahead cache.-
1092 Note also the kernel is conservative and only invalidates-
1093 full pages in the specified range. */-
1094#if HAVE_POSIX_FADVISE-
1095 offset = offset - clen - pending;-
1096 /* ensure full page specified when invalidating to eof. */-
1097 if (clen == 0)
clen == 0Description
TRUEevaluated 22 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 12 times by 1 test
Evaluated by:
  • dd
12-22
1098 offset -= offset % page_size;
executed 22 times by 1 test: offset -= offset % page_size;
Executed by:
  • dd
22
1099 adv_ret = posix_fadvise (fd, offset, clen, POSIX_FADV_DONTNEED);-
1100#else-
1101 errno = ENOTSUP;-
1102#endif-
1103 }
executed 34 times by 1 test: end of block
Executed by:
  • dd
34
1104-
1105 return adv_ret != -1 ? true : false;
executed 35 times by 1 test: return adv_ret != -1 ? 1 : 0 ;
Executed by:
  • dd
35
1106}-
1107-
1108/* Read from FD into the buffer BUF of size SIZE, processing any-
1109 signals that arrive before bytes are read. Return the number of-
1110 bytes read if successful, -1 (setting errno) on failure. */-
1111-
1112static ssize_t-
1113iread (int fd, char *buf, size_t size)-
1114{-
1115 ssize_t nread;-
1116 static ssize_t prev_nread;-
1117-
1118 do-
1119 {-
1120 process_signals ();-
1121 nread = read (fd, buf, size);-
1122 /* Ignore final read error with iflag=direct as that-
1123 returns EINVAL due to the non aligned file offset. */-
1124 if (nread == -1 && errno == EINVAL
nread == -1Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 3004 times by 1 test
Evaluated by:
  • dd
(*__errno_location ()) == 22Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-3004
1125 && 0 < prev_nread && prev_nread < size
0 < prev_nreadDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
prev_nread < sizeDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-3
1126 && (input_flags & O_DIRECT))
(input_flags & 040000 )Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-3
1127 {-
1128 errno = 0;-
1129 nread = 0;-
1130 }
executed 3 times by 1 test: end of block
Executed by:
  • dd
3
1131 }
executed 3007 times by 1 test: end of block
Executed by:
  • dd
3007
1132 while (nread < 0 && errno == EINTR);
nread < 0Description
TRUEnever evaluated
FALSEevaluated 3007 times by 1 test
Evaluated by:
  • dd
(*__errno_location ()) == 4Description
TRUEnever evaluated
FALSEnever evaluated
0-3007
1133-
1134 /* Short read may be due to received signal. */-
1135 if (0 < nread && nread < size)
0 < nreadDescription
TRUEevaluated 2934 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 73 times by 1 test
Evaluated by:
  • dd
nread < sizeDescription
TRUEevaluated 56 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 2878 times by 1 test
Evaluated by:
  • dd
56-2934
1136 process_signals ();
executed 56 times by 1 test: process_signals ();
Executed by:
  • dd
56
1137-
1138 if (0 < nread && warn_partial_read)
0 < nreadDescription
TRUEevaluated 2934 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 73 times by 1 test
Evaluated by:
  • dd
warn_partial_readDescription
TRUEevaluated 425 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 2509 times by 1 test
Evaluated by:
  • dd
73-2934
1139 {-
1140 if (0 < prev_nread && prev_nread < size)
0 < prev_nreadDescription
TRUEevaluated 407 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 18 times by 1 test
Evaluated by:
  • dd
prev_nread < sizeDescription
TRUEnever evaluated
FALSEevaluated 407 times by 1 test
Evaluated by:
  • dd
0-407
1141 {-
1142 uintmax_t prev = prev_nread;-
1143 if (status_level != STATUS_NONE)
status_level != STATUS_NONEDescription
TRUEnever evaluated
FALSEnever evaluated
0
1144 error (0, 0, ngettext (("warning: partial read (%"PRIuMAX" byte); "
never executed: nl_error (0, 0, dcngettext (((void *)0), ("warning: partial read (%" "l" "u" " byte); " "suggest iflag=fullblock") , ("warning: partial read (%" "l" "u" " bytes); " "suggest iflag=fullblock") , select_plural (prev) , 5) , prev);
0
1145 "suggest iflag=fullblock"),
never executed: nl_error (0, 0, dcngettext (((void *)0), ("warning: partial read (%" "l" "u" " byte); " "suggest iflag=fullblock") , ("warning: partial read (%" "l" "u" " bytes); " "suggest iflag=fullblock") , select_plural (prev) , 5) , prev);
0
1146 ("warning: partial read (%"PRIuMAX" bytes); "
never executed: nl_error (0, 0, dcngettext (((void *)0), ("warning: partial read (%" "l" "u" " byte); " "suggest iflag=fullblock") , ("warning: partial read (%" "l" "u" " bytes); " "suggest iflag=fullblock") , select_plural (prev) , 5) , prev);
0
1147 "suggest iflag=fullblock"),
never executed: nl_error (0, 0, dcngettext (((void *)0), ("warning: partial read (%" "l" "u" " byte); " "suggest iflag=fullblock") , ("warning: partial read (%" "l" "u" " bytes); " "suggest iflag=fullblock") , select_plural (prev) , 5) , prev);
0
1148 select_plural (prev)),
never executed: nl_error (0, 0, dcngettext (((void *)0), ("warning: partial read (%" "l" "u" " byte); " "suggest iflag=fullblock") , ("warning: partial read (%" "l" "u" " bytes); " "suggest iflag=fullblock") , select_plural (prev) , 5) , prev);
0
1149 prev);
never executed: nl_error (0, 0, dcngettext (((void *)0), ("warning: partial read (%" "l" "u" " byte); " "suggest iflag=fullblock") , ("warning: partial read (%" "l" "u" " bytes); " "suggest iflag=fullblock") , select_plural (prev) , 5) , prev);
0
1150 warn_partial_read = false;-
1151 }
never executed: end of block
0
1152 }
executed 425 times by 1 test: end of block
Executed by:
  • dd
425
1153-
1154 prev_nread = nread;-
1155 return nread;
executed 3007 times by 1 test: return nread;
Executed by:
  • dd
3007
1156}-
1157-
1158/* Wrapper around iread function to accumulate full blocks. */-
1159static ssize_t-
1160iread_fullblock (int fd, char *buf, size_t size)-
1161{-
1162 ssize_t nread = 0;-
1163-
1164 while (0 < size)
0 < sizeDescription
TRUEevaluated 1724 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1716 times by 1 test
Evaluated by:
  • dd
1716-1724
1165 {-
1166 ssize_t ncurr = iread (fd, buf, size);-
1167 if (ncurr < 0)
ncurr < 0Description
TRUEnever evaluated
FALSEevaluated 1724 times by 1 test
Evaluated by:
  • dd
0-1724
1168 return ncurr;
never executed: return ncurr;
0
1169 if (ncurr == 0)
ncurr == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 1723 times by 1 test
Evaluated by:
  • dd
1-1723
1170 break;
executed 1 time by 1 test: break;
Executed by:
  • dd
1
1171 nread += ncurr;-
1172 buf += ncurr;-
1173 size -= ncurr;-
1174 }
executed 1723 times by 1 test: end of block
Executed by:
  • dd
1723
1175-
1176 return nread;
executed 1717 times by 1 test: return nread;
Executed by:
  • dd
1717
1177}-
1178-
1179/* Write to FD the buffer BUF of size SIZE, processing any signals-
1180 that arrive. Return the number of bytes written, setting errno if-
1181 this is less than SIZE. Keep trying if there are partial-
1182 writes. */-
1183-
1184static size_t-
1185iwrite (int fd, char const *buf, size_t size)-
1186{-
1187 size_t total_written = 0;-
1188-
1189 if ((output_flags & O_DIRECT) && size < output_blocksize)
(output_flags & 040000 )Description
TRUEevaluated 54 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 2854 times by 1 test
Evaluated by:
  • dd
size < output_blocksizeDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 49 times by 1 test
Evaluated by:
  • dd
5-2854
1190 {-
1191 int old_flags = fcntl (STDOUT_FILENO, F_GETFL);-
1192 if (fcntl (STDOUT_FILENO, F_SETFL, old_flags & ~O_DIRECT) != 0
rpl_fcntl ( 1 ... 040000 ) != 0Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • dd
0-5
1193 && status_level != STATUS_NONE)
status_level != STATUS_NONEDescription
TRUEnever evaluated
FALSEnever evaluated
0
1194 error (0, errno, _("failed to turn off O_DIRECT: %s"),
never executed: nl_error (0, (*__errno_location ()) , dcgettext (((void *)0), "failed to turn off O_DIRECT: %s" , 5) , quotearg_n_style_colon (0, shell_escape_quoting_style, output_file));
0
1195 quotef (output_file));
never executed: nl_error (0, (*__errno_location ()) , dcgettext (((void *)0), "failed to turn off O_DIRECT: %s" , 5) , quotearg_n_style_colon (0, shell_escape_quoting_style, output_file));
0
1196-
1197 /* Since we have just turned off O_DIRECT for the final write,-
1198 we try to preserve some of its semantics. */-
1199-
1200 /* Call invalidate_cache() to setup the appropriate offsets-
1201 for subsequent calls. */-
1202 o_nocache_eof = true;-
1203 invalidate_cache (STDOUT_FILENO, 0);-
1204-
1205 /* Attempt to ensure that that final block is committed-
1206 to disk as quickly as possible. */-
1207 conversions_mask |= C_FSYNC;-
1208-
1209 /* After the subsequent fsync() we'll call invalidate_cache()-
1210 to attempt to clear all data from the page cache. */-
1211 }
executed 5 times by 1 test: end of block
Executed by:
  • dd
5
1212-
1213 while (total_written < size)
total_written < sizeDescription
TRUEevaluated 2958 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 2908 times by 1 test
Evaluated by:
  • dd
2908-2958
1214 {-
1215 ssize_t nwritten = 0;-
1216 process_signals ();-
1217-
1218 /* Perform a seek for a NUL block if sparse output is enabled. */-
1219 final_op_was_seek = false;-
1220 if ((conversions_mask & C_SPARSE) && is_nul (buf, size))
(conversions_mask & C_SPARSE)Description
TRUEevaluated 47 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 2911 times by 1 test
Evaluated by:
  • dd
is_nul (buf, size)Description
TRUEevaluated 38 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 9 times by 1 test
Evaluated by:
  • dd
9-2911
1221 {-
1222 if (lseek (fd, size, SEEK_CUR) < 0)
lseek (fd, size, 1 ) < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 37 times by 1 test
Evaluated by:
  • dd
1-37
1223 {-
1224 conversions_mask &= ~C_SPARSE;-
1225 /* Don't warn about the advisory sparse request. */-
1226 }
executed 1 time by 1 test: end of block
Executed by:
  • dd
1
1227 else-
1228 {-
1229 final_op_was_seek = true;-
1230 nwritten = size;-
1231 }
executed 37 times by 1 test: end of block
Executed by:
  • dd
37
1232 }-
1233-
1234 if (!nwritten)
!nwrittenDescription
TRUEevaluated 2921 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 37 times by 1 test
Evaluated by:
  • dd
37-2921
1235 nwritten = write (fd, buf + total_written, size - total_written);
executed 2921 times by 1 test: nwritten = write (fd, buf + total_written, size - total_written);
Executed by:
  • dd
2921
1236-
1237 if (nwritten < 0)
nwritten < 0Description
TRUEnever evaluated
FALSEevaluated 2958 times by 1 test
Evaluated by:
  • dd
0-2958
1238 {-
1239 if (errno != EINTR)
(*__errno_location ()) != 4Description
TRUEnever evaluated
FALSEnever evaluated
0
1240 break;
never executed: break;
0
1241 }
never executed: end of block
0
1242 else if (nwritten == 0)
nwritten == 0Description
TRUEnever evaluated
FALSEevaluated 2958 times by 1 test
Evaluated by:
  • dd
0-2958
1243 {-
1244 /* Some buggy drivers return 0 when one tries to write beyond-
1245 a device's end. (Example: Linux kernel 1.2.13 on /dev/fd0.)-
1246 Set errno to ENOSPC so they get a sensible diagnostic. */-
1247 errno = ENOSPC;-
1248 break;
never executed: break;
0
1249 }-
1250 else-
1251 total_written += nwritten;
executed 2958 times by 1 test: total_written += nwritten;
Executed by:
  • dd
2958
1252 }-
1253-
1254 if (o_nocache && total_written)
o_nocacheDescription
TRUEevaluated 104 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 2804 times by 1 test
Evaluated by:
  • dd
total_writtenDescription
TRUEevaluated 104 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-2804
1255 invalidate_cache (fd, total_written);
executed 104 times by 1 test: invalidate_cache (fd, total_written);
Executed by:
  • dd
104
1256-
1257 return total_written;
executed 2908 times by 1 test: return total_written;
Executed by:
  • dd
2908
1258}-
1259-
1260/* Write, then empty, the output buffer 'obuf'. */-
1261-
1262static void-
1263write_output (void)-
1264{-
1265 size_t nwritten = iwrite (STDOUT_FILENO, obuf, output_blocksize);-
1266 w_bytes += nwritten;-
1267 if (nwritten != output_blocksize)
nwritten != output_blocksizeDescription
TRUEnever evaluated
FALSEevaluated 760 times by 1 test
Evaluated by:
  • dd
0-760
1268 {-
1269 error (0, errno, _("writing to %s"), quoteaf (output_file));-
1270 if (nwritten != 0)
nwritten != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1271 w_partial++;
never executed: w_partial++;
0
1272 quit (EXIT_FAILURE);-
1273 }
never executed: end of block
0
1274 else-
1275 w_full++;
executed 760 times by 1 test: w_full++;
Executed by:
  • dd
760
1276 oc = 0;-
1277}
executed 760 times by 1 test: end of block
Executed by:
  • dd
760
1278-
1279/* Restart on EINTR from fd_reopen(). */-
1280-
1281static int-
1282ifd_reopen (int desired_fd, char const *file, int flag, mode_t mode)-
1283{-
1284 int ret;-
1285-
1286 do-
1287 {-
1288 process_signals ();-
1289 ret = fd_reopen (desired_fd, file, flag, mode);-
1290 }
executed 1125 times by 1 test: end of block
Executed by:
  • dd
1125
1291 while (ret < 0 && errno == EINTR);
ret < 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1123 times by 1 test
Evaluated by:
  • dd
(*__errno_location ()) == 4Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1-1123
1292-
1293 return ret;
executed 1124 times by 1 test: return ret;
Executed by:
  • dd
1124
1294}-
1295-
1296/* Restart on EINTR from ftruncate(). */-
1297-
1298static int-
1299iftruncate (int fd, off_t length)-
1300{-
1301 int ret;-
1302-
1303 do-
1304 {-
1305 process_signals ();-
1306 ret = ftruncate (fd, length);-
1307 }
executed 18 times by 1 test: end of block
Executed by:
  • dd
18
1308 while (ret < 0 && errno == EINTR);
ret < 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 15 times by 1 test
Evaluated by:
  • dd
(*__errno_location ()) == 4Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • dd
0-15
1309-
1310 return ret;
executed 18 times by 1 test: return ret;
Executed by:
  • dd
18
1311}-
1312-
1313/* Return true if STR is of the form "PATTERN" or "PATTERNDELIM...". */-
1314-
1315static bool _GL_ATTRIBUTE_PURE-
1316operand_matches (char const *str, char const *pattern, char delim)-
1317{-
1318 while (*pattern)
*patternDescription
TRUEevaluated 67860 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 7441 times by 1 test
Evaluated by:
  • dd
7441-67860
1319 if (*str++ != *pattern++)
*str++ != *pattern++Description
TRUEevaluated 31850 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 36010 times by 1 test
Evaluated by:
  • dd
31850-36010
1320 return false;
executed 31850 times by 1 test: return 0 ;
Executed by:
  • dd
31850
1321 return !*str || *str == delim;
executed 7441 times by 1 test: return !*str || *str == delim;
Executed by:
  • dd
7441
1322}-
1323-
1324/* Interpret one "conv=..." or similar operand STR according to the-
1325 symbols in TABLE, returning the flags specified. If the operand-
1326 cannot be parsed, use ERROR_MSGID to generate a diagnostic. */-
1327-
1328static int-
1329parse_symbols (char const *str, struct symbol_value const *table,-
1330 bool exclusive, char const *error_msgid)-
1331{-
1332 int value = 0;-
1333-
1334 while (true)-
1335 {-
1336 char const *strcomma = strchr (str, ',');
__builtin_constant_p ( ',' )Description
TRUEevaluated 2063 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
!__builtin_constant_p ( str )Description
TRUEevaluated 2063 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
( ',' ) == '\0'Description
TRUEnever evaluated
FALSEevaluated 2063 times by 1 test
Evaluated by:
  • dd
0-2063
1337 struct symbol_value const *entry;-
1338-
1339 for (entry = table;-
1340 ! (operand_matches (str, entry->symbol, ',') && entry->value);
operand_matche...->symbol, ',')Description
TRUEevaluated 2063 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 13296 times by 1 test
Evaluated by:
  • dd
entry->valueDescription
TRUEevaluated 2062 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1-13296
1341 entry++)-
1342 {-
1343 if (! entry->symbol[0])
! entry->symbol[0]Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 13296 times by 1 test
Evaluated by:
  • dd
1-13296
1344 {-
1345 size_t slen = strcomma ? strcomma - str : strlen (str);
strcommaDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
0-1
1346 error (0, 0, "%s: %s", _(error_msgid),-
1347 quotearg_n_style_mem (0, locale_quoting_style, str, slen));-
1348 usage (EXIT_FAILURE);-
1349 }
never executed: end of block
0
1350 }
executed 13296 times by 1 test: end of block
Executed by:
  • dd
13296
1351-
1352 if (exclusive)
exclusiveDescription
TRUEevaluated 533 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1529 times by 1 test
Evaluated by:
  • dd
533-1529
1353 value = entry->value;
executed 533 times by 1 test: value = entry->value;
Executed by:
  • dd
533
1354 else-
1355 value |= entry->value;
executed 1529 times by 1 test: value |= entry->value;
Executed by:
  • dd
1529
1356 if (!strcomma)
!strcommaDescription
TRUEevaluated 2054 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 8 times by 1 test
Evaluated by:
  • dd
8-2054
1357 break;
executed 2054 times by 1 test: break;
Executed by:
  • dd
2054
1358 str = strcomma + 1;-
1359 }
executed 8 times by 1 test: end of block
Executed by:
  • dd
8
1360-
1361 return value;
executed 2054 times by 1 test: return value;
Executed by:
  • dd
2054
1362}-
1363-
1364/* Return the value of STR, interpreted as a non-negative decimal integer,-
1365 optionally multiplied by various values.-
1366 Set *INVALID to a nonzero error value if STR does not represent a-
1367 number in this format. */-
1368-
1369static uintmax_t-
1370parse_integer (const char *str, strtol_error *invalid)-
1371{-
1372 uintmax_t n;-
1373 char *suffix;-
1374 strtol_error e = xstrtoumax (str, &suffix, 10, &n, "bcEGkKMPTwYZ0");-
1375-
1376 if (e == LONGINT_INVALID_SUFFIX_CHAR && *suffix == 'x')
e == LONGINT_I...ID_SUFFIX_CHARDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1180 times by 1 test
Evaluated by:
  • dd
*suffix == 'x'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-1180
1377 {-
1378 uintmax_t multiplier = parse_integer (suffix + 1, invalid);-
1379-
1380 if (multiplier != 0 && n * multiplier / multiplier != n)
multiplier != 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
n * multiplier...ultiplier != nDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • dd
0-3
1381 {-
1382 *invalid = LONGINT_OVERFLOW;-
1383 return 0;
never executed: return 0;
0
1384 }-
1385-
1386 if (n == 0 && STRPREFIX (str, "0x"))
never executed: __result = (((const unsigned char *) (const char *) ( str ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "0x" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
n == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
( (__extension...0x") ))) == 0)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
__builtin_cons...trlen ("0x") )Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
__builtin_constant_p ( str )Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • dd
strlen ( str )...rlen ("0x") ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( "0x" )Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
strlen ( "0x" ...rlen ("0x") ))Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • dd
__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
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__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-3
1387 error (0, 0,
executed 3 times by 1 test: nl_error (0, 0, dcgettext (((void *)0), "warning: %s is a zero multiplier; " "use %s if that is intended" , 5) , quote_n (0, "0x"), quote_n (1, "00x"));
Executed by:
  • dd
3
1388 _("warning: %s is a zero multiplier; "
executed 3 times by 1 test: nl_error (0, 0, dcgettext (((void *)0), "warning: %s is a zero multiplier; " "use %s if that is intended" , 5) , quote_n (0, "0x"), quote_n (1, "00x"));
Executed by:
  • dd
3
1389 "use %s if that is intended"),
executed 3 times by 1 test: nl_error (0, 0, dcgettext (((void *)0), "warning: %s is a zero multiplier; " "use %s if that is intended" , 5) , quote_n (0, "0x"), quote_n (1, "00x"));
Executed by:
  • dd
3
1390 quote_n (0, "0x"), quote_n (1, "00x"));
executed 3 times by 1 test: nl_error (0, 0, dcgettext (((void *)0), "warning: %s is a zero multiplier; " "use %s if that is intended" , 5) , quote_n (0, "0x"), quote_n (1, "00x"));
Executed by:
  • dd
3
1391-
1392 n *= multiplier;-
1393 }
executed 3 times by 1 test: end of block
Executed by:
  • dd
3
1394 else if (e != LONGINT_OK)
e != LONGINT_OKDescription
TRUEnever evaluated
FALSEevaluated 1180 times by 1 test
Evaluated by:
  • dd
0-1180
1395 {-
1396 *invalid = e;-
1397 return 0;
never executed: return 0;
0
1398 }-
1399-
1400 return n;
executed 1183 times by 1 test: return n;
Executed by:
  • dd
1183
1401}-
1402-
1403/* OPERAND is of the form "X=...". Return true if X is NAME. */-
1404-
1405static bool _GL_ATTRIBUTE_PURE-
1406operand_is (char const *operand, char const *name)-
1407{-
1408 return operand_matches (operand, name, '=');
executed 23932 times by 1 test: return operand_matches (operand, name, '=');
Executed by:
  • dd
23932
1409}-
1410-
1411static void-
1412scanargs (int argc, char *const *argv)-
1413{-
1414 size_t blocksize = 0;-
1415 uintmax_t count = (uintmax_t) -1;-
1416 uintmax_t skip = 0;-
1417 uintmax_t seek = 0;-
1418-
1419 for (int i = optind; i < argc; i++)
i < argcDescription
TRUEevaluated 4360 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 629 times by 1 test
Evaluated by:
  • dd
629-4360
1420 {-
1421 char const *name = argv[i];-
1422 char const *val = strchr (name, '=');
__builtin_constant_p ( '=' )Description
TRUEevaluated 4360 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
!__builtin_constant_p ( name )Description
TRUEevaluated 4360 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
( '=' ) == '\0'Description
TRUEnever evaluated
FALSEevaluated 4360 times by 1 test
Evaluated by:
  • dd
0-4360
1423-
1424 if (val == NULL)
val == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4360 times by 1 test
Evaluated by:
  • dd
0-4360
1425 {-
1426 error (0, 0, _("unrecognized operand %s"),-
1427 quote (name));-
1428 usage (EXIT_FAILURE);-
1429 }
never executed: end of block
0
1430 val++;-
1431-
1432 if (operand_is (name, "if"))
operand_is (name, "if")Description
TRUEevaluated 562 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 3798 times by 1 test
Evaluated by:
  • dd
562-3798
1433 input_file = val;
executed 562 times by 1 test: input_file = val;
Executed by:
  • dd
562
1434 else if (operand_is (name, "of"))
operand_is (name, "of")Description
TRUEevaluated 563 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 3235 times by 1 test
Evaluated by:
  • dd
563-3235
1435 output_file = val;
executed 563 times by 1 test: output_file = val;
Executed by:
  • dd
563
1436 else if (operand_is (name, "conv"))
operand_is (name, "conv")Description
TRUEevaluated 508 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 2727 times by 1 test
Evaluated by:
  • dd
508-2727
1437 conversions_mask |= parse_symbols (val, conversions, false,
executed 508 times by 1 test: conversions_mask |= parse_symbols (val, conversions, 0 , "invalid conversion");
Executed by:
  • dd
508
1438 N_("invalid conversion"));
executed 508 times by 1 test: conversions_mask |= parse_symbols (val, conversions, 0 , "invalid conversion");
Executed by:
  • dd
508
1439 else if (operand_is (name, "iflag"))
operand_is (name, "iflag")Description
TRUEevaluated 517 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 2210 times by 1 test
Evaluated by:
  • dd
517-2210
1440 input_flags |= parse_symbols (val, flags, false,
executed 517 times by 1 test: input_flags |= parse_symbols (val, flags, 0 , "invalid input flag");
Executed by:
  • dd
517
1441 N_("invalid input flag"));
executed 517 times by 1 test: input_flags |= parse_symbols (val, flags, 0 , "invalid input flag");
Executed by:
  • dd
517
1442 else if (operand_is (name, "oflag"))
operand_is (name, "oflag")Description
TRUEevaluated 497 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1713 times by 1 test
Evaluated by:
  • dd
497-1713
1443 output_flags |= parse_symbols (val, flags, false,
executed 497 times by 1 test: output_flags |= parse_symbols (val, flags, 0 , "invalid output flag");
Executed by:
  • dd
497
1444 N_("invalid output flag"));
executed 497 times by 1 test: output_flags |= parse_symbols (val, flags, 0 , "invalid output flag");
Executed by:
  • dd
497
1445 else if (operand_is (name, "status"))
operand_is (name, "status")Description
TRUEevaluated 533 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1180 times by 1 test
Evaluated by:
  • dd
533-1180
1446 status_level = parse_symbols (val, statuses, true,
executed 533 times by 1 test: status_level = parse_symbols (val, statuses, 1 , "invalid status level");
Executed by:
  • dd
533
1447 N_("invalid status level"));
executed 533 times by 1 test: status_level = parse_symbols (val, statuses, 1 , "invalid status level");
Executed by:
  • dd
533
1448 else-
1449 {-
1450 strtol_error invalid = LONGINT_OK;-
1451 uintmax_t n = parse_integer (val, &invalid);-
1452 uintmax_t n_min = 0;-
1453 uintmax_t n_max = UINTMAX_MAX;-
1454-
1455 if (operand_is (name, "ibs"))
operand_is (name, "ibs")Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1172 times by 1 test
Evaluated by:
  • dd
8-1172
1456 {-
1457 n_min = 1;-
1458 n_max = MAX_BLOCKSIZE (INPUT_BLOCK_SLOP);
(((18446744073... 2 + 1))) ))))Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • dd
((0x7fffffffff... * 2 + 1))) ))Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • dd
0-8
1459 input_blocksize = n;-
1460 }
executed 8 times by 1 test: end of block
Executed by:
  • dd
8
1461 else if (operand_is (name, "obs"))
operand_is (name, "obs")Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1166 times by 1 test
Evaluated by:
  • dd
6-1166
1462 {-
1463 n_min = 1;-
1464 n_max = MAX_BLOCKSIZE (OUTPUT_BLOCK_SLOP);
(((18446744073... 2 + 1))) ))))Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • dd
((0x7fffffffff... * 2 + 1))) ))Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • dd
0-6
1465 output_blocksize = n;-
1466 }
executed 6 times by 1 test: end of block
Executed by:
  • dd
6
1467 else if (operand_is (name, "bs"))
operand_is (name, "bs")Description
TRUEevaluated 545 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 621 times by 1 test
Evaluated by:
  • dd
545-621
1468 {-
1469 n_min = 1;-
1470 n_max = MAX_BLOCKSIZE (INPUT_BLOCK_SLOP);
(((18446744073... 2 + 1))) ))))Description
TRUEnever evaluated
FALSEevaluated 545 times by 1 test
Evaluated by:
  • dd
((0x7fffffffff... * 2 + 1))) ))Description
TRUEnever evaluated
FALSEevaluated 545 times by 1 test
Evaluated by:
  • dd
0-545
1471 blocksize = n;-
1472 }
executed 545 times by 1 test: end of block
Executed by:
  • dd
545
1473 else if (operand_is (name, "cbs"))
operand_is (name, "cbs")Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 610 times by 1 test
Evaluated by:
  • dd
11-610
1474 {-
1475 n_min = 1;-
1476 n_max = SIZE_MAX;-
1477 conversion_blocksize = n;-
1478 }
executed 11 times by 1 test: end of block
Executed by:
  • dd
11
1479 else if (operand_is (name, "skip"))
operand_is (name, "skip")Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 582 times by 1 test
Evaluated by:
  • dd
28-582
1480 skip = n;
executed 28 times by 1 test: skip = n;
Executed by:
  • dd
28
1481 else if (operand_is (name, "seek"))
operand_is (name, "seek")Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 558 times by 1 test
Evaluated by:
  • dd
24-558
1482 seek = n;
executed 24 times by 1 test: seek = n;
Executed by:
  • dd
24
1483 else if (operand_is (name, "count"))
operand_is (name, "count")Description
TRUEevaluated 558 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-558
1484 count = n;
executed 558 times by 1 test: count = n;
Executed by:
  • dd
558
1485 else-
1486 {-
1487 error (0, 0, _("unrecognized operand %s"),-
1488 quote (name));-
1489 usage (EXIT_FAILURE);-
1490 }
never executed: end of block
0
1491-
1492 if (n < n_min)
n < n_minDescription
TRUEnever evaluated
FALSEevaluated 1180 times by 1 test
Evaluated by:
  • dd
0-1180
1493 invalid = LONGINT_INVALID;
never executed: invalid = LONGINT_INVALID;
0
1494 else if (n_max < n)
n_max < nDescription
TRUEnever evaluated
FALSEevaluated 1180 times by 1 test
Evaluated by:
  • dd
0-1180
1495 invalid = LONGINT_OVERFLOW;
never executed: invalid = LONGINT_OVERFLOW;
0
1496-
1497 if (invalid != LONGINT_OK)
invalid != LONGINT_OKDescription
TRUEnever evaluated
FALSEevaluated 1180 times by 1 test
Evaluated by:
  • dd
0-1180
1498 die (EXIT_FAILURE, invalid == LONGINT_OVERFLOW ? EOVERFLOW : 0,
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, invalid == LONGINT_OVERFLOW ? 75 : 0, \"%s: %s\", dcgettext (((void *)0), \"invalid number\", 5), quote (val)), assume (false))" ")"); int _gl_dummy; })) ? ((nl_error ( 1 , inv...umber" , 5) , quote (val)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , invalid == LONGINT_OVERFLOW ? 75 : 0, "%s: %s", dcgettext (((void *)0), "invalid number" , 5) , quote (val)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
1499 "%s: %s", _("invalid number"), quote (val));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, invalid == LONGINT_OVERFLOW ? 75 : 0, \"%s: %s\", dcgettext (((void *)0), \"invalid number\", 5), quote (val)), assume (false))" ")"); int _gl_dummy; })) ? ((nl_error ( 1 , inv...umber" , 5) , quote (val)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , invalid == LONGINT_OVERFLOW ? 75 : 0, "%s: %s", dcgettext (((void *)0), "invalid number" , 5) , quote (val)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
1500 }
executed 1180 times by 1 test: end of block
Executed by:
  • dd
1180
1501 }-
1502-
1503 if (blocksize)
blocksizeDescription
TRUEevaluated 545 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 84 times by 1 test
Evaluated by:
  • dd
84-545
1504 input_blocksize = output_blocksize = blocksize;
executed 545 times by 1 test: input_blocksize = output_blocksize = blocksize;
Executed by:
  • dd
545
1505 else-
1506 {-
1507 /* POSIX says dd aggregates partial reads into-
1508 output_blocksize if bs= is not specified. */-
1509 conversions_mask |= C_TWOBUFS;-
1510 }
executed 84 times by 1 test: end of block
Executed by:
  • dd
84
1511-
1512 if (input_blocksize == 0)
input_blocksize == 0Description
TRUEevaluated 78 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 551 times by 1 test
Evaluated by:
  • dd
78-551
1513 input_blocksize = DEFAULT_BLOCKSIZE;
executed 78 times by 1 test: input_blocksize = 512;
Executed by:
  • dd
78
1514 if (output_blocksize == 0)
output_blocksize == 0Description
TRUEevaluated 80 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 549 times by 1 test
Evaluated by:
  • dd
80-549
1515 output_blocksize = DEFAULT_BLOCKSIZE;
executed 80 times by 1 test: output_blocksize = 512;
Executed by:
  • dd
80
1516 if (conversion_blocksize == 0)
conversion_blocksize == 0Description
TRUEevaluated 618 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 11 times by 1 test
Evaluated by:
  • dd
11-618
1517 conversions_mask &= ~(C_BLOCK | C_UNBLOCK);
executed 618 times by 1 test: conversions_mask &= ~(C_BLOCK | C_UNBLOCK);
Executed by:
  • dd
618
1518-
1519 if (input_flags & (O_DSYNC | O_SYNC))
input_flags & ...0 | 04010000 )Description
TRUEnever evaluated
FALSEevaluated 629 times by 1 test
Evaluated by:
  • dd
0-629
1520 input_flags |= O_RSYNC;
never executed: input_flags |= 04010000 ;
0
1521-
1522 if (output_flags & O_FULLBLOCK)
output_flags & O_FULLBLOCKDescription
TRUEnever evaluated
FALSEevaluated 629 times by 1 test
Evaluated by:
  • dd
0-629
1523 {-
1524 error (0, 0, "%s: %s", _("invalid output flag"), quote ("fullblock"));-
1525 usage (EXIT_FAILURE);-
1526 }
never executed: end of block
0
1527-
1528 if (input_flags & O_SEEK_BYTES)
input_flags & O_SEEK_BYTESDescription
TRUEnever evaluated
FALSEevaluated 629 times by 1 test
Evaluated by:
  • dd
0-629
1529 {-
1530 error (0, 0, "%s: %s", _("invalid input flag"), quote ("seek_bytes"));-
1531 usage (EXIT_FAILURE);-
1532 }
never executed: end of block
0
1533-
1534 if (output_flags & (O_COUNT_BYTES | O_SKIP_BYTES))
output_flags &... O_SKIP_BYTES)Description
TRUEnever evaluated
FALSEevaluated 629 times by 1 test
Evaluated by:
  • dd
0-629
1535 {-
1536 error (0, 0, "%s: %s", _("invalid output flag"),-
1537 quote (output_flags & O_COUNT_BYTES-
1538 ? "count_bytes" : "skip_bytes"));-
1539 usage (EXIT_FAILURE);-
1540 }
never executed: end of block
0
1541-
1542 if (input_flags & O_SKIP_BYTES && skip != 0)
input_flags & O_SKIP_BYTESDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 627 times by 1 test
Evaluated by:
  • dd
skip != 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-627
1543 {-
1544 skip_records = skip / input_blocksize;-
1545 skip_bytes = skip % input_blocksize;-
1546 }
executed 2 times by 1 test: end of block
Executed by:
  • dd
2
1547 else if (skip != 0)
skip != 0Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 602 times by 1 test
Evaluated by:
  • dd
25-602
1548 skip_records = skip;
executed 25 times by 1 test: skip_records = skip;
Executed by:
  • dd
25
1549-
1550 if (input_flags & O_COUNT_BYTES && count != (uintmax_t) -1)
input_flags & O_COUNT_BYTESDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 628 times by 1 test
Evaluated by:
  • dd
count != (uintmax_t) -1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-628
1551 {-
1552 max_records = count / input_blocksize;-
1553 max_bytes = count % input_blocksize;-
1554 }
executed 1 time by 1 test: end of block
Executed by:
  • dd
1
1555 else if (count != (uintmax_t) -1)
count != (uintmax_t) -1Description
TRUEevaluated 557 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 71 times by 1 test
Evaluated by:
  • dd
71-557
1556 max_records = count;
executed 557 times by 1 test: max_records = count;
Executed by:
  • dd
557
1557-
1558 if (output_flags & O_SEEK_BYTES && seek != 0)
output_flags & O_SEEK_BYTESDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 626 times by 1 test
Evaluated by:
  • dd
seek != 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-626
1559 {-
1560 seek_records = seek / output_blocksize;-
1561 seek_bytes = seek % output_blocksize;-
1562 }
executed 3 times by 1 test: end of block
Executed by:
  • dd
3
1563 else if (seek != 0)
seek != 0Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 606 times by 1 test
Evaluated by:
  • dd
20-606
1564 seek_records = seek;
executed 20 times by 1 test: seek_records = seek;
Executed by:
  • dd
20
1565-
1566 /* Warn about partial reads if bs=SIZE is given and iflag=fullblock-
1567 is not, and if counting or skipping bytes or using direct I/O.-
1568 This helps to avoid confusion with miscounts, and to avoid issues-
1569 with direct I/O on GNU/Linux. */-
1570 warn_partial_read =-
1571 (! (conversions_mask & C_TWOBUFS) && ! (input_flags & O_FULLBLOCK)
! (conversions...k & C_TWOBUFS)Description
TRUEevaluated 545 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 84 times by 1 test
Evaluated by:
  • dd
! (input_flags & O_FULLBLOCK)Description
TRUEevaluated 61 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 484 times by 1 test
Evaluated by:
  • dd
61-545
1572 && (skip_records
skip_recordsDescription
TRUEevaluated 21 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 40 times by 1 test
Evaluated by:
  • dd
21-40
1573 || (0 < max_records && max_records < (uintmax_t) -1)
0 < max_recordsDescription
TRUEevaluated 36 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 4 times by 1 test
Evaluated by:
  • dd
max_records < (uintmax_t) -1Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 29 times by 1 test
Evaluated by:
  • dd
4-36
1574 || (input_flags | output_flags) & O_DIRECT));
(input_flags |...lags) & 040000Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 31 times by 1 test
Evaluated by:
  • dd
2-31
1575-
1576 iread_fnc = ((input_flags & O_FULLBLOCK)
(input_flags & O_FULLBLOCK)Description
TRUEevaluated 493 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 136 times by 1 test
Evaluated by:
  • dd
136-493
1577 ? iread_fullblock-
1578 : iread);-
1579 input_flags &= ~O_FULLBLOCK;-
1580-
1581 if (multiple_bits_set (conversions_mask & (C_ASCII | C_EBCDIC | C_IBM)))
multiple_bits_...CDIC | C_IBM))Description
TRUEnever evaluated
FALSEevaluated 629 times by 1 test
Evaluated by:
  • dd
0-629
1582 die (EXIT_FAILURE, 0, _("cannot combine any two of {ascii,ebcdic,ibm}"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"cannot combine any two of {ascii,ebcdic,ibm}\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((nl_error ( 1 , 0, dcgettext (((void *)0), "cannot combine any two of {ascii,ebcdic,ibm}" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , 0, dcgettext (((void *)0), "cannot combine any two of {ascii,ebcdic,ibm}" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
1583 if (multiple_bits_set (conversions_mask & (C_BLOCK | C_UNBLOCK)))
multiple_bits_... | C_UNBLOCK))Description
TRUEnever evaluated
FALSEevaluated 629 times by 1 test
Evaluated by:
  • dd
0-629
1584 die (EXIT_FAILURE, 0, _("cannot combine block and unblock"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"cannot combine block and unblock\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((nl_error ( 1 , 0, dcgettext (((void *)0), "cannot combine block and unblock" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , 0, dcgettext (((void *)0), "cannot combine block and unblock" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
1585 if (multiple_bits_set (conversions_mask & (C_LCASE | C_UCASE)))
multiple_bits_...SE | C_UCASE))Description
TRUEnever evaluated
FALSEevaluated 629 times by 1 test
Evaluated by:
  • dd
0-629
1586 die (EXIT_FAILURE, 0, _("cannot combine lcase and ucase"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"cannot combine lcase and ucase\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((nl_error ( 1 , 0, dcgettext (((void *)0), "cannot combine lcase and ucase" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , 0, dcgettext (((void *)0), "cannot combine lcase and ucase" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
1587 if (multiple_bits_set (conversions_mask & (C_EXCL | C_NOCREAT)))
multiple_bits_... | C_NOCREAT))Description
TRUEnever evaluated
FALSEevaluated 629 times by 1 test
Evaluated by:
  • dd
0-629
1588 die (EXIT_FAILURE, 0, _("cannot combine excl and nocreat"));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"cannot combine excl and nocreat\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((nl_error ( 1 , 0, dcgettext (((void *)0), "cannot combine excl and nocreat" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , 0, dcgettext (((void *)0), "cannot combine excl and nocreat" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
1589 if (multiple_bits_set (input_flags & (O_DIRECT | O_NOCACHE))
multiple_bits_... | O_NOCACHE))Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 628 times by 1 test
Evaluated by:
  • dd
1-628
1590 || multiple_bits_set (output_flags & (O_DIRECT | O_NOCACHE)))
multiple_bits_... | O_NOCACHE))Description
TRUEnever evaluated
FALSEevaluated 628 times by 1 test
Evaluated by:
  • dd
0-628
1591 die (EXIT_FAILURE, 0, _("cannot combine direct and nocache"));
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"cannot combine direct and nocache\", 5)), assume (false))" ")"); int _gl_dummy; })) ? ((nl_error ( 1 , 0, dcgettext (((void *)0), "cannot combine direct and nocache" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , 0, dcgettext (((void *)0), "cannot combine direct and nocache" , 5) ), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
Executed by:
  • dd
1
1592-
1593 if (input_flags & O_NOCACHE)
input_flags & O_NOCACHEDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 617 times by 1 test
Evaluated by:
  • dd
11-617
1594 {-
1595 i_nocache = true;-
1596 i_nocache_eof = (max_records == 0 && max_bytes == 0);
max_records == 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 7 times by 1 test
Evaluated by:
  • dd
max_bytes == 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-7
1597 input_flags &= ~O_NOCACHE;-
1598 }
executed 11 times by 1 test: end of block
Executed by:
  • dd
11
1599 if (output_flags & O_NOCACHE)
output_flags & O_NOCACHEDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 623 times by 1 test
Evaluated by:
  • dd
5-623
1600 {-
1601 o_nocache = true;-
1602 o_nocache_eof = (max_records == 0 && max_bytes == 0);
max_records == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 4 times by 1 test
Evaluated by:
  • dd
max_bytes == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-4
1603 output_flags &= ~O_NOCACHE;-
1604 }
executed 5 times by 1 test: end of block
Executed by:
  • dd
5
1605}
executed 628 times by 1 test: end of block
Executed by:
  • dd
628
1606-
1607/* Fix up translation table. */-
1608-
1609static void-
1610apply_translations (void)-
1611{-
1612 int i;-
1613-
1614 if (conversions_mask & C_ASCII)
conversions_mask & C_ASCIIDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 627 times by 1 test
Evaluated by:
  • dd
1-627
1615 translate_charset (ebcdic_to_ascii);
executed 1 time by 1 test: translate_charset (ebcdic_to_ascii);
Executed by:
  • dd
1
1616-
1617 if (conversions_mask & C_UCASE)
conversions_mask & C_UCASEDescription
TRUEnever evaluated
FALSEevaluated 628 times by 1 test
Evaluated by:
  • dd
0-628
1618 {-
1619 for (i = 0; i < 256; i++)
i < 256Description
TRUEnever evaluated
FALSEnever evaluated
0
1620 trans_table[i] = toupper (trans_table[i]);
never executed: trans_table[i] = (__extension__ ({ int __res; if (sizeof ( trans_table[i] ) > 1) { if (__builtin_constant_p ( trans_table[i] )) { int __c = ( trans_table[i] ); __res = __c < -128 || __c > 255 ? __c : (*__ctype_toupper_loc ())[__c]; } else __res = toupper ( trans_table[i] ); } else __res = (*__ctype_toupper_loc ())[(int) ( trans_table[i] )]; __res; })) ;
never executed: end of block
never executed: __res = toupper ( trans_table[i] );
never executed: __res = (*__ctype_toupper_loc ())[(int) ( trans_table[i] )];
sizeof ( trans_table[i] ) > 1Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...ans_table[i] )Description
TRUEnever evaluated
FALSEnever evaluated
__c < -128Description
TRUEnever evaluated
FALSEnever evaluated
__c > 255Description
TRUEnever evaluated
FALSEnever evaluated
0
1621 translation_needed = true;-
1622 }
never executed: end of block
0
1623 else if (conversions_mask & C_LCASE)
conversions_mask & C_LCASEDescription
TRUEnever evaluated
FALSEevaluated 628 times by 1 test
Evaluated by:
  • dd
0-628
1624 {-
1625 for (i = 0; i < 256; i++)
i < 256Description
TRUEnever evaluated
FALSEnever evaluated
0
1626 trans_table[i] = tolower (trans_table[i]);
never executed: trans_table[i] = (__extension__ ({ int __res; if (sizeof ( trans_table[i] ) > 1) { if (__builtin_constant_p ( trans_table[i] )) { int __c = ( trans_table[i] ); __res = __c < -128 || __c > 255 ? __c : (*__ctype_tolower_loc ())[__c]; } else __res = tolower ( trans_table[i] ); } else __res = (*__ctype_tolower_loc ())[(int) ( trans_table[i] )]; __res; })) ;
never executed: end of block
never executed: __res = tolower ( trans_table[i] );
never executed: __res = (*__ctype_tolower_loc ())[(int) ( trans_table[i] )];
sizeof ( trans_table[i] ) > 1Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...ans_table[i] )Description
TRUEnever evaluated
FALSEnever evaluated
__c < -128Description
TRUEnever evaluated
FALSEnever evaluated
__c > 255Description
TRUEnever evaluated
FALSEnever evaluated
0
1627 translation_needed = true;-
1628 }
never executed: end of block
0
1629-
1630 if (conversions_mask & C_EBCDIC)
conversions_mask & C_EBCDICDescription
TRUEnever evaluated
FALSEevaluated 628 times by 1 test
Evaluated by:
  • dd
0-628
1631 {-
1632 translate_charset (ascii_to_ebcdic);-
1633 newline_character = ascii_to_ebcdic['\n'];-
1634 space_character = ascii_to_ebcdic[' '];-
1635 }
never executed: end of block
0
1636 else if (conversions_mask & C_IBM)
conversions_mask & C_IBMDescription
TRUEnever evaluated
FALSEevaluated 628 times by 1 test
Evaluated by:
  • dd
0-628
1637 {-
1638 translate_charset (ascii_to_ibm);-
1639 newline_character = ascii_to_ibm['\n'];-
1640 space_character = ascii_to_ibm[' '];-
1641 }
never executed: end of block
0
1642}
executed 628 times by 1 test: end of block
Executed by:
  • dd
628
1643-
1644/* Apply the character-set translations specified by the user-
1645 to the NREAD bytes in BUF. */-
1646-
1647static void-
1648translate_buffer (char *buf, size_t nread)-
1649{-
1650 size_t i;-
1651 char *cp;-
1652 for (i = nread, cp = buf; i; i--, cp++)
iDescription
TRUEevaluated 264 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1-264
1653 *cp = trans_table[to_uchar (*cp)];
executed 264 times by 1 test: *cp = trans_table[to_uchar (*cp)];
Executed by:
  • dd
264
1654}
executed 1 time by 1 test: end of block
Executed by:
  • dd
1
1655-
1656/* If true, the last char from the previous call to 'swab_buffer'-
1657 is saved in 'saved_char'. */-
1658static bool char_is_saved = false;-
1659-
1660/* Odd char from previous call. */-
1661static char saved_char;-
1662-
1663/* Swap NREAD bytes in BUF, plus possibly an initial char from the-
1664 previous call. If NREAD is odd, save the last char for the-
1665 next call. Return the new start of the BUF buffer. */-
1666-
1667static char *-
1668swab_buffer (char *buf, size_t *nread)-
1669{-
1670 char *bufstart = buf;-
1671-
1672 /* Is a char left from last time? */-
1673 if (char_is_saved)
char_is_savedDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
0-1
1674 {-
1675 *--bufstart = saved_char;-
1676 (*nread)++;-
1677 char_is_saved = false;-
1678 }
never executed: end of block
0
1679-
1680 if (*nread & 1)
*nread & 1Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
0-1
1681 {-
1682 /* An odd number of chars are in the buffer. */-
1683 saved_char = bufstart[--*nread];-
1684 char_is_saved = true;-
1685 }
never executed: end of block
0
1686-
1687 /* Do the byte-swapping by moving every second character two-
1688 positions toward the end, working from the end of the buffer-
1689 toward the beginning. This way we only move half of the data. */-
1690-
1691 char *cp = bufstart + *nread; /* Start one char past the last. */-
1692 for (size_t i = *nread / 2; i; i--, cp -= 2)
iDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1-7
1693 *cp = *(cp - 2);
executed 7 times by 1 test: *cp = *(cp - 2);
Executed by:
  • dd
7
1694-
1695 return ++bufstart;
executed 1 time by 1 test: return ++bufstart;
Executed by:
  • dd
1
1696}-
1697-
1698/* Add OFFSET to the input offset, setting the overflow flag if-
1699 necessary. */-
1700-
1701static void-
1702advance_input_offset (uintmax_t offset)-
1703{-
1704 input_offset += offset;-
1705 if (input_offset < offset)
input_offset < offsetDescription
TRUEnever evaluated
FALSEevaluated 2944 times by 1 test
Evaluated by:
  • dd
0-2944
1706 input_offset_overflow = true;
never executed: input_offset_overflow = 1 ;
0
1707}
executed 2944 times by 1 test: end of block
Executed by:
  • dd
2944
1708-
1709/* This is a wrapper for lseek. It detects and warns about a kernel-
1710 bug that makes lseek a no-op for tape devices, even though the kernel-
1711 lseek return value suggests that the function succeeded.-
1712-
1713 The parameters are the same as those of the lseek function, but-
1714 with the addition of FILENAME, the name of the file associated with-
1715 descriptor FDESC. The file name is used solely in the warning that's-
1716 printed when the bug is detected. Return the same value that lseek-
1717 would have returned, but when the lseek bug is detected, return -1-
1718 to indicate that lseek failed.-
1719-
1720 The offending behavior has been confirmed with an Exabyte SCSI tape-
1721 drive accessed via /dev/nst0 on both Linux 2.2.17 and 2.4.16 kernels. */-
1722-
1723#if defined __linux__ && HAVE_SYS_MTIO_H-
1724-
1725# include <sys/mtio.h>-
1726-
1727# define MT_SAME_POSITION(P, Q) \-
1728 ((P).mt_resid == (Q).mt_resid \-
1729 && (P).mt_fileno == (Q).mt_fileno \-
1730 && (P).mt_blkno == (Q).mt_blkno)-
1731-
1732static off_t-
1733skip_via_lseek (char const *filename, int fdesc, off_t offset, int whence)-
1734{-
1735 struct mtget s1;-
1736 struct mtget s2;-
1737 bool got_original_tape_position = (ioctl (fdesc, MTIOCGET, &s1) == 0);-
1738 /* known bad device type */-
1739 /* && s.mt_type == MT_ISSCSI2 */-
1740-
1741 off_t new_position = lseek (fdesc, offset, whence);-
1742 if (0 <= new_position
0 <= new_positionDescription
TRUEevaluated 40 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 21 times by 1 test
Evaluated by:
  • dd
21-40
1743 && got_original_tape_position
got_original_tape_positionDescription
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • dd
0-40
1744 && ioctl (fdesc, MTIOCGET, &s2) == 0
ioctl (fdesc, ...)) , &s2) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1745 && MT_SAME_POSITION (s1, s2))
(s1).mt_resid == (s2).mt_residDescription
TRUEnever evaluated
FALSEnever evaluated
(s1).mt_fileno...(s2).mt_filenoDescription
TRUEnever evaluated
FALSEnever evaluated
(s1).mt_blkno == (s2).mt_blknoDescription
TRUEnever evaluated
FALSEnever evaluated
0
1746 {-
1747 if (status_level != STATUS_NONE)
status_level != STATUS_NONEDescription
TRUEnever evaluated
FALSEnever evaluated
0
1748 error (0, 0, _("warning: working around lseek kernel bug for file "
never executed: nl_error (0, 0, dcgettext (((void *)0), "warning: working around lseek kernel bug for file " "(%s)\n of mt_type=0x%0lx -- " "see <sys/mtio.h> for the list of types" , 5) , filename, s2.mt_type + 0Lu);
0
1749 "(%s)\n of mt_type=0x%0lx -- "
never executed: nl_error (0, 0, dcgettext (((void *)0), "warning: working around lseek kernel bug for file " "(%s)\n of mt_type=0x%0lx -- " "see <sys/mtio.h> for the list of types" , 5) , filename, s2.mt_type + 0Lu);
0
1750 "see <sys/mtio.h> for the list of types"),
never executed: nl_error (0, 0, dcgettext (((void *)0), "warning: working around lseek kernel bug for file " "(%s)\n of mt_type=0x%0lx -- " "see <sys/mtio.h> for the list of types" , 5) , filename, s2.mt_type + 0Lu);
0
1751 filename, s2.mt_type + 0Lu);
never executed: nl_error (0, 0, dcgettext (((void *)0), "warning: working around lseek kernel bug for file " "(%s)\n of mt_type=0x%0lx -- " "see <sys/mtio.h> for the list of types" , 5) , filename, s2.mt_type + 0Lu);
0
1752 errno = 0;-
1753 new_position = -1;-
1754 }
never executed: end of block
0
1755-
1756 return new_position;
executed 61 times by 1 test: return new_position;
Executed by:
  • dd
61
1757}-
1758#else-
1759# define skip_via_lseek(Filename, Fd, Offset, Whence) lseek (Fd, Offset, Whence)-
1760#endif-
1761-
1762/* Throw away RECORDS blocks of BLOCKSIZE bytes plus BYTES bytes on-
1763 file descriptor FDESC, which is open with read permission for FILE.-
1764 Store up to BLOCKSIZE bytes of the data at a time in IBUF or OBUF, if-
1765 necessary. RECORDS or BYTES must be nonzero. If FDESC is-
1766 STDIN_FILENO, advance the input offset. Return the number of-
1767 records remaining, i.e., that were not skipped because EOF was-
1768 reached. If FDESC is STDOUT_FILENO, on return, BYTES is the-
1769 remaining bytes in addition to the remaining records. */-
1770-
1771static uintmax_t-
1772skip (int fdesc, char const *file, uintmax_t records, size_t blocksize,-
1773 size_t *bytes)-
1774{-
1775 uintmax_t offset = records * blocksize + *bytes;-
1776-
1777 /* Try lseek and if an error indicates it was an inappropriate operation ---
1778 or if the file offset is not representable as an off_t ---
1779 fall back on using read. */-
1780-
1781 errno = 0;-
1782 if (records <= OFF_T_MAX / blocksize
records <= ((o...)) / blocksizeDescription
TRUEevaluated 49 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1-49
1783 && 0 <= skip_via_lseek (file, fdesc, offset, SEEK_CUR))
0 <= skip_via_...c, offset, 1 )Description
TRUEevaluated 38 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 11 times by 1 test
Evaluated by:
  • dd
11-38
1784 {-
1785 if (fdesc == STDIN_FILENO)
fdesc == 0Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 20 times by 1 test
Evaluated by:
  • dd
18-20
1786 {-
1787 struct stat st;-
1788 if (fstat (STDIN_FILENO, &st) != 0)
fstat ( 0 , &st) != 0Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • dd
0-18
1789 die (EXIT_FAILURE, errno, _("cannot fstat %s"), quoteaf (file));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"cannot fstat %s\", 5), quotearg_style (shell_escape_always_quoting_style, file)), assume (false))" ")"); int _gl_dummy; })) ? ...le)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "cannot fstat %s" , 5) , quotearg_style (shell_escape_always_quoting_style, file)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
0
1790 if (usable_st_size (&st) && st.st_size < input_offset + offset)
usable_st_size (&st)Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
st.st_size < i...ffset + offsetDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 13 times by 1 test
Evaluated by:
  • dd
0-18
1791 {-
1792 /* When skipping past EOF, return the number of _full_ blocks-
1793 * that are not skipped, and set offset to EOF, so the caller-
1794 * can determine the requested skip was not satisfied. */-
1795 records = ( offset - st.st_size ) / blocksize;-
1796 offset = st.st_size - input_offset;-
1797 }
executed 5 times by 1 test: end of block
Executed by:
  • dd
5
1798 else-
1799 records = 0;
executed 13 times by 1 test: records = 0;
Executed by:
  • dd
13
1800 advance_input_offset (offset);-
1801 }
executed 18 times by 1 test: end of block
Executed by:
  • dd
18
1802 else-
1803 {-
1804 records = 0;-
1805 *bytes = 0;-
1806 }
executed 20 times by 1 test: end of block
Executed by:
  • dd
20
1807 return records;
executed 38 times by 1 test: return records;
Executed by:
  • dd
38
1808 }-
1809 else-
1810 {-
1811 int lseek_errno = errno;-
1812-
1813 /* The seek request may have failed above if it was too big-
1814 (> device size, > max file size, etc.)-
1815 Or it may not have been done at all (> OFF_T_MAX).-
1816 Therefore try to seek to the end of the file,-
1817 to avoid redundant reading. */-
1818 if ((skip_via_lseek (file, fdesc, 0, SEEK_END)) >= 0)
(skip_via_lsee..., 0, 2 )) >= 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 10 times by 1 test
Evaluated by:
  • dd
2-10
1819 {-
1820 /* File is seekable, and we're at the end of it, and-
1821 size <= OFF_T_MAX. So there's no point using read to advance. */-
1822-
1823 if (!lseek_errno)
!lseek_errnoDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1
1824 {-
1825 /* The original seek was not attempted as offset > OFF_T_MAX.-
1826 We should error for write as can't get to the desired-
1827 location, even if OFF_T_MAX < max file size.-
1828 For read we're not going to read any data anyway,-
1829 so we should error for consistency.-
1830 It would be nice to not error for /dev/{zero,null}-
1831 for any offset, but that's not a significant issue. */-
1832 lseek_errno = EOVERFLOW;-
1833 }
executed 1 time by 1 test: end of block
Executed by:
  • dd
1
1834-
1835 if (fdesc == STDIN_FILENO)
fdesc == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-2
1836 error (0, lseek_errno, _("%s: cannot skip"), quotef (file));
executed 2 times by 1 test: nl_error (0, lseek_errno, dcgettext (((void *)0), "%s: cannot skip" , 5) , quotearg_n_style_colon (0, shell_escape_quoting_style, file));
Executed by:
  • dd
2
1837 else-
1838 error (0, lseek_errno, _("%s: cannot seek"), quotef (file));
never executed: nl_error (0, lseek_errno, dcgettext (((void *)0), "%s: cannot seek" , 5) , quotearg_n_style_colon (0, shell_escape_quoting_style, file));
0
1839 /* If the file has a specific size and we've asked-
1840 to skip/seek beyond the max allowable, then quit. */-
1841 quit (EXIT_FAILURE);-
1842 }
never executed: end of block
0
1843 /* else file_size && offset > OFF_T_MAX or file ! seekable */-
1844-
1845 char *buf;-
1846 if (fdesc == STDIN_FILENO)
fdesc == 0Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 3 times by 1 test
Evaluated by:
  • dd
3-7
1847 {-
1848 alloc_ibuf ();-
1849 buf = ibuf;-
1850 }
executed 5 times by 1 test: end of block
Executed by:
  • dd
5
1851 else-
1852 {-
1853 alloc_obuf ();-
1854 buf = obuf;-
1855 }
executed 1 time by 1 test: end of block
Executed by:
  • dd
1
1856-
1857 do-
1858 {-
1859 ssize_t nread = iread_fnc (fdesc, buf, records ? blocksize : *bytes);-
1860 if (nread < 0)
nread < 0Description
TRUEnever evaluated
FALSEevaluated 15 times by 1 test
Evaluated by:
  • dd
0-15
1861 {-
1862 if (fdesc == STDIN_FILENO)
fdesc == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1863 {-
1864 error (0, errno, _("error reading %s"), quoteaf (file));-
1865 if (conversions_mask & C_NOERROR)
conversions_mask & C_NOERRORDescription
TRUEnever evaluated
FALSEnever evaluated
0
1866 print_stats ();
never executed: print_stats ();
0
1867 }
never executed: end of block
0
1868 else-
1869 error (0, lseek_errno, _("%s: cannot seek"), quotef (file));
never executed: nl_error (0, lseek_errno, dcgettext (((void *)0), "%s: cannot seek" , 5) , quotearg_n_style_colon (0, shell_escape_quoting_style, file));
0
1870 quit (EXIT_FAILURE);-
1871 }
never executed: end of block
0
1872 else if (nread == 0)
nread == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 14 times by 1 test
Evaluated by:
  • dd
1-14
1873 break;
executed 1 time by 1 test: break;
Executed by:
  • dd
1
1874 else if (fdesc == STDIN_FILENO)
fdesc == 0Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1-13
1875 advance_input_offset (nread);
executed 13 times by 1 test: advance_input_offset (nread);
Executed by:
  • dd
13
1876-
1877 if (records != 0)
records != 0Description
TRUEevaluated 14 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-14
1878 records--;
executed 14 times by 1 test: records--;
Executed by:
  • dd
14
1879 else-
1880 *bytes = 0;
never executed: *bytes = 0;
0
1881 }-
1882 while (records || *bytes);
recordsDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 5 times by 1 test
Evaluated by:
  • dd
*bytesDescription
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • dd
0-9
1883-
1884 return records;
executed 6 times by 1 test: return records;
Executed by:
  • dd
6
1885 }-
1886}-
1887-
1888/* Advance the input by NBYTES if possible, after a read error.-
1889 The input file offset may or may not have advanced after the failed-
1890 read; adjust it to point just after the bad record regardless.-
1891 Return true if successful, or if the input is already known to not-
1892 be seekable. */-
1893-
1894static bool-
1895advance_input_after_read_error (size_t nbytes)-
1896{-
1897 if (! input_seekable)
! input_seekableDescription
TRUEnever evaluated
FALSEnever evaluated
0
1898 {-
1899 if (input_seek_errno == ESPIPE)
input_seek_errno == 29Description
TRUEnever evaluated
FALSEnever evaluated
0
1900 return true;
never executed: return 1 ;
0
1901 errno = input_seek_errno;-
1902 }
never executed: end of block
0
1903 else-
1904 {-
1905 off_t offset;-
1906 advance_input_offset (nbytes);-
1907 input_offset_overflow |= (OFF_T_MAX < input_offset);-
1908 if (input_offset_overflow)
input_offset_overflowDescription
TRUEnever evaluated
FALSEnever evaluated
0
1909 {-
1910 error (0, 0, _("offset overflow while reading file %s"),-
1911 quoteaf (input_file));-
1912 return false;
never executed: return 0 ;
0
1913 }-
1914 offset = lseek (STDIN_FILENO, 0, SEEK_CUR);-
1915 if (0 <= offset)
0 <= offsetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1916 {-
1917 off_t diff;-
1918 if (offset == input_offset)
offset == input_offsetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1919 return true;
never executed: return 1 ;
0
1920 diff = input_offset - offset;-
1921 if (! (0 <= diff && diff <= nbytes) && status_level != STATUS_NONE)
0 <= diffDescription
TRUEnever evaluated
FALSEnever evaluated
diff <= nbytesDescription
TRUEnever evaluated
FALSEnever evaluated
status_level != STATUS_NONEDescription
TRUEnever evaluated
FALSEnever evaluated
0
1922 error (0, 0, _("warning: invalid file offset after failed read"));
never executed: nl_error (0, 0, dcgettext (((void *)0), "warning: invalid file offset after failed read" , 5) );
0
1923 if (0 <= skip_via_lseek (input_file, STDIN_FILENO, diff, SEEK_CUR))
0 <= skip_via_... 0 , diff, 1 )Description
TRUEnever evaluated
FALSEnever evaluated
0
1924 return true;
never executed: return 1 ;
0
1925 if (errno == 0)
(*__errno_location ()) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1926 error (0, 0, _("cannot work around kernel bug after all"));
never executed: nl_error (0, 0, dcgettext (((void *)0), "cannot work around kernel bug after all" , 5) );
0
1927 }
never executed: end of block
0
1928 }
never executed: end of block
0
1929-
1930 error (0, errno, _("%s: cannot seek"), quotef (input_file));-
1931 return false;
never executed: return 0 ;
0
1932}-
1933-
1934/* Copy NREAD bytes of BUF, with no conversions. */-
1935-
1936static void-
1937copy_simple (char const *buf, size_t nread)-
1938{-
1939 const char *start = buf; /* First uncopied char in BUF. */-
1940-
1941 do-
1942 {-
1943 size_t nfree = MIN (nread, output_blocksize - oc);
(( nread )<( o...cksize - oc ))Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 760 times by 1 test
Evaluated by:
  • dd
25-760
1944-
1945 memcpy (obuf + oc, start, nfree);-
1946-
1947 nread -= nfree; /* Update the number of bytes left to copy. */-
1948 start += nfree;-
1949 oc += nfree;-
1950 if (oc >= output_blocksize)
oc >= output_blocksizeDescription
TRUEevaluated 760 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 25 times by 1 test
Evaluated by:
  • dd
25-760
1951 write_output ();
executed 760 times by 1 test: write_output ();
Executed by:
  • dd
760
1952 }
executed 785 times by 1 test: end of block
Executed by:
  • dd
785
1953 while (nread != 0);
nread != 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 784 times by 1 test
Evaluated by:
  • dd
1-784
1954}
executed 784 times by 1 test: end of block
Executed by:
  • dd
784
1955-
1956/* Copy NREAD bytes of BUF, doing conv=block-
1957 (pad newline-terminated records to 'conversion_blocksize',-
1958 replacing the newline with trailing spaces). */-
1959-
1960static void-
1961copy_with_block (char const *buf, size_t nread)-
1962{-
1963 for (size_t i = nread; i; i--, buf++)
iDescription
TRUEevaluated 30 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 3 times by 1 test
Evaluated by:
  • dd
3-30
1964 {-
1965 if (*buf == newline_character)
*buf == newline_characterDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 28 times by 1 test
Evaluated by:
  • dd
2-28
1966 {-
1967 if (col < conversion_blocksize)
col < conversion_blocksizeDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1
1968 {-
1969 size_t j;-
1970 for (j = col; j < conversion_blocksize; j++)
j < conversion_blocksizeDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1-2
1971 output_char (space_character);
never executed: write_output ();
executed 2 times by 1 test: end of block
Executed by:
  • dd
oc >= output_blocksizeDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • dd
0-2
1972 }
executed 1 time by 1 test: end of block
Executed by:
  • dd
1
1973 col = 0;-
1974 }
executed 2 times by 1 test: end of block
Executed by:
  • dd
2
1975 else-
1976 {-
1977 if (col == conversion_blocksize)
col == conversion_blocksizeDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 27 times by 1 test
Evaluated by:
  • dd
1-27
1978 r_truncate++;
executed 1 time by 1 test: r_truncate++;
Executed by:
  • dd
1
1979 else if (col < conversion_blocksize)
col < conversion_blocksizeDescription
TRUEevaluated 26 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1-26
1980 output_char (*buf);
never executed: write_output ();
executed 26 times by 1 test: end of block
Executed by:
  • dd
oc >= output_blocksizeDescription
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • dd
0-26
1981 col++;-
1982 }
executed 28 times by 1 test: end of block
Executed by:
  • dd
28
1983 }-
1984}
executed 3 times by 1 test: end of block
Executed by:
  • dd
3
1985-
1986/* Copy NREAD bytes of BUF, doing conv=unblock-
1987 (replace trailing spaces in 'conversion_blocksize'-sized records-
1988 with a newline). */-
1989-
1990static void-
1991copy_with_unblock (char const *buf, size_t nread)-
1992{-
1993 static size_t pending_spaces = 0;-
1994-
1995 for (size_t i = 0; i < nread; i++)
i < nreadDescription
TRUEevaluated 377 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 12 times by 1 test
Evaluated by:
  • dd
12-377
1996 {-
1997 char c = buf[i];-
1998-
1999 if (col++ >= conversion_blocksize)
col++ >= conversion_blocksizeDescription
TRUEevaluated 72 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 305 times by 1 test
Evaluated by:
  • dd
72-305
2000 {-
2001 col = pending_spaces = 0; /* Wipe out any pending spaces. */-
2002 i--; /* Push the char back; get it later. */-
2003 output_char (newline_character);
never executed: write_output ();
oc >= output_blocksizeDescription
TRUEnever evaluated
FALSEevaluated 72 times by 1 test
Evaluated by:
  • dd
0-72
2004 }
executed 72 times by 1 test: end of block
Executed by:
  • dd
72
2005 else if (c == space_character)
c == space_characterDescription
TRUEevaluated 21 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 284 times by 1 test
Evaluated by:
  • dd
21-284
2006 pending_spaces++;
executed 21 times by 1 test: pending_spaces++;
Executed by:
  • dd
21
2007 else-
2008 {-
2009 /* 'c' is the character after a run of spaces that were not-
2010 at the end of the conversion buffer. Output them. */-
2011 while (pending_spaces)
pending_spacesDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 284 times by 1 test
Evaluated by:
  • dd
6-284
2012 {-
2013 output_char (space_character);
never executed: write_output ();
oc >= output_blocksizeDescription
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • dd
0-6
2014 --pending_spaces;-
2015 }
executed 6 times by 1 test: end of block
Executed by:
  • dd
6
2016 output_char (c);
never executed: write_output ();
oc >= output_blocksizeDescription
TRUEnever evaluated
FALSEevaluated 284 times by 1 test
Evaluated by:
  • dd
0-284
2017 }
executed 284 times by 1 test: end of block
Executed by:
  • dd
284
2018 }-
2019}
executed 12 times by 1 test: end of block
Executed by:
  • dd
12
2020-
2021/* Set the file descriptor flags for FD that correspond to the nonzero bits-
2022 in ADD_FLAGS. The file's name is NAME. */-
2023-
2024static void-
2025set_fd_flags (int fd, int add_flags, char const *name)-
2026{-
2027 /* Ignore file creation flags that are no-ops on file descriptors. */-
2028 add_flags &= ~ (O_NOCTTY | O_NOFOLLOW);-
2029-
2030 if (add_flags)
add_flagsDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 123 times by 1 test
Evaluated by:
  • dd
7-123
2031 {-
2032 int old_flags = fcntl (fd, F_GETFL);-
2033 int new_flags = old_flags | add_flags;-
2034 bool ok = true;-
2035 if (old_flags < 0)
old_flags < 0Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • dd
0-7
2036 ok = false;
never executed: ok = 0 ;
0
2037 else if (old_flags != new_flags)
old_flags != new_flagsDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-7
2038 {-
2039 if (new_flags & (O_DIRECTORY | O_NOLINKS))
new_flags & ( 0200000 | 0 )Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 5 times by 1 test
Evaluated by:
  • dd
2-5
2040 {-
2041 /* NEW_FLAGS contains at least one file creation flag that-
2042 requires some checking of the open file descriptor. */-
2043 struct stat st;-
2044 if (fstat (fd, &st) != 0)
fstat (fd, &st) != 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • dd
0-2
2045 ok = false;
never executed: ok = 0 ;
0
2046 else if ((new_flags & O_DIRECTORY) && ! S_ISDIR (st.st_mode))
(new_flags & 0200000 )Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
! (((( st.st_m... == (0040000))Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
0-2
2047 {-
2048 errno = ENOTDIR;-
2049 ok = false;-
2050 }
executed 1 time by 1 test: end of block
Executed by:
  • dd
1
2051 else if ((new_flags & O_NOLINKS) && 1 < st.st_nlink)
(new_flags & 0 )Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1 < st.st_nlinkDescription
TRUEnever evaluated
FALSEnever evaluated
0-1
2052 {-
2053 errno = EMLINK;-
2054 ok = false;-
2055 }
never executed: end of block
0
2056 new_flags &= ~ (O_DIRECTORY | O_NOLINKS);-
2057 }
executed 2 times by 1 test: end of block
Executed by:
  • dd
2
2058-
2059 if (ok && old_flags != new_flags
okDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
old_flags != new_flagsDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1-6
2060 && fcntl (fd, F_SETFL, new_flags) == -1)
rpl_fcntl (fd,...w_flags) == -1Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • dd
0-5
2061 ok = false;
never executed: ok = 0 ;
0
2062 }
executed 7 times by 1 test: end of block
Executed by:
  • dd
7
2063-
2064 if (!ok)
!okDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 6 times by 1 test
Evaluated by:
  • dd
1-6
2065 die (EXIT_FAILURE, errno, _("setting flags for %s"), quoteaf (name));
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"setting flags for %s\", 5), quotearg_style (shell_escape_always_quoting_style, name)), assume (false))" ")"); int _gl_dummy; }... (( 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "setting flags for %s" , 5) , quotearg_style (shell_escape_always_quoting_style, name)), (( 0 ) ? (void) 0 : __builtin_unreachable ()))));
Executed by:
  • dd
1
2066 }
executed 6 times by 1 test: end of block
Executed by:
  • dd
6
2067}
executed 129 times by 1 test: end of block
Executed by:
  • dd
129
2068-
2069/* The main loop. */-
2070-
2071static int-
2072dd_copy (void)-
2073{-
2074 char *bufstart; /* Input buffer. */-
2075 ssize_t nread; /* Bytes read in the current block. */-
2076-
2077 /* If nonzero, then the previously read block was partial and-
2078 PARTREAD was its size. */-
2079 size_t partread = 0;-
2080-
2081 int exit_status = EXIT_SUCCESS;-
2082 size_t n_bytes_read;-
2083-
2084 /* Leave at least one extra byte at the beginning and end of 'ibuf'-
2085 for conv=swab, but keep the buffer address even. But some peculiar-
2086 device drivers work only with word-aligned buffers, so leave an-
2087 extra two bytes. */-
2088-
2089 /* Some devices require alignment on a sector or page boundary-
2090 (e.g. character disk devices). Align the input buffer to a-
2091 page boundary to cover all bases. Note that due to the swab-
2092 algorithm, we must have at least one byte in the page before-
2093 the input buffer; thus we allocate 2 pages of slop in the-
2094 real buffer. 8k above the blocksize shouldn't bother anyone.-
2095-
2096 The page alignment is necessary on any Linux kernel that supports-
2097 either the SGI raw I/O patch or Steven Tweedies raw I/O patch.-
2098 It is necessary when accessing raw (i.e., character special) disk-
2099 devices on Unixware or other SVR4-derived system. */-
2100-
2101 if (skip_records != 0 || skip_bytes != 0)
skip_records != 0Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 600 times by 1 test
Evaluated by:
  • dd
skip_bytes != 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 599 times by 1 test
Evaluated by:
  • dd
1-600
2102 {-
2103 uintmax_t us_bytes = input_offset + (skip_records * input_blocksize)-
2104 + skip_bytes;-
2105 uintmax_t us_blocks = skip (STDIN_FILENO, input_file,-
2106 skip_records, input_blocksize, &skip_bytes);-
2107 us_bytes -= input_offset;-
2108-
2109 /* POSIX doesn't say what to do when dd detects it has been-
2110 asked to skip past EOF, so I assume it's non-fatal.-
2111 There are 3 reasons why there might be unskipped blocks/bytes:-
2112 1. file is too small-
2113 2. pipe has not enough data-
2114 3. partial reads */-
2115 if ((us_blocks || (!input_offset_overflow && us_bytes))
us_blocksDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 20 times by 1 test
Evaluated by:
  • dd
!input_offset_overflowDescription
TRUEevaluated 20 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
us_bytesDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 16 times by 1 test
Evaluated by:
  • dd
0-20
2116 && status_level != STATUS_NONE)
status_level != STATUS_NONEDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1-6
2117 {-
2118 error (0, 0,-
2119 _("%s: cannot skip to specified offset"), quotef (input_file));-
2120 }
executed 6 times by 1 test: end of block
Executed by:
  • dd
6
2121 }
executed 23 times by 1 test: end of block
Executed by:
  • dd
23
2122-
2123 if (seek_records != 0 || seek_bytes != 0)
seek_records != 0Description
TRUEevaluated 22 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 600 times by 1 test
Evaluated by:
  • dd
seek_bytes != 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 599 times by 1 test
Evaluated by:
  • dd
1-600
2124 {-
2125 size_t bytes = seek_bytes;-
2126 uintmax_t write_records = skip (STDOUT_FILENO, output_file,-
2127 seek_records, output_blocksize, &bytes);-
2128-
2129 if (write_records != 0 || bytes != 0)
write_records != 0Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • dd
bytes != 0Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • dd
0-21
2130 {-
2131 memset (obuf, 0, write_records ? output_blocksize : bytes);-
2132-
2133 do-
2134 {-
2135 size_t size = write_records ? output_blocksize : bytes;
write_recordsDescription
TRUEnever evaluated
FALSEnever evaluated
0
2136 if (iwrite (STDOUT_FILENO, obuf, size) != size)
iwrite ( 1 , o... size) != sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
2137 {-
2138 error (0, errno, _("writing to %s"), quoteaf (output_file));-
2139 quit (EXIT_FAILURE);-
2140 }
never executed: end of block
0
2141-
2142 if (write_records != 0)
write_records != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2143 write_records--;
never executed: write_records--;
0
2144 else-
2145 bytes = 0;
never executed: bytes = 0;
0
2146 }-
2147 while (write_records || bytes);
write_recordsDescription
TRUEnever evaluated
FALSEnever evaluated
bytesDescription
TRUEnever evaluated
FALSEnever evaluated
0
2148 }
never executed: end of block
0
2149 }
executed 21 times by 1 test: end of block
Executed by:
  • dd
21
2150-
2151 if (max_records == 0 && max_bytes == 0)
max_records == 0Description
TRUEevaluated 27 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 593 times by 1 test
Evaluated by:
  • dd
max_bytes == 0Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1-593
2152 return exit_status;
executed 26 times by 1 test: return exit_status;
Executed by:
  • dd
26
2153-
2154 alloc_ibuf ();-
2155 alloc_obuf ();-
2156-
2157 while (1)-
2158 {-
2159 if (status_level == STATUS_PROGRESS)
status_level =...TATUS_PROGRESSDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 3504 times by 1 test
Evaluated by:
  • dd
3-3504
2160 {-
2161 xtime_t progress_time = gethrxtime ();-
2162 if (next_time <= progress_time)
next_time <= progress_timeDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 2 times by 1 test
Evaluated by:
  • dd
1-2
2163 {-
2164 print_xfer_stats (progress_time);-
2165 next_time += XTIME_PRECISION;-
2166 }
executed 1 time by 1 test: end of block
Executed by:
  • dd
1
2167 }
executed 3 times by 1 test: end of block
Executed by:
  • dd
3
2168-
2169 if (r_partial + r_full >= max_records + !!max_bytes)
r_partial + r_... + !!max_bytesDescription
TRUEevaluated 522 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 2985 times by 1 test
Evaluated by:
  • dd
522-2985
2170 break;
executed 522 times by 1 test: break;
Executed by:
  • dd
522
2171-
2172 /* Zero the buffer before reading, so that if we get a read error,-
2173 whatever data we are able to read is followed by zeros.-
2174 This minimizes data loss. */-
2175 if ((conversions_mask & C_SYNC) && (conversions_mask & C_NOERROR))
(conversions_mask & C_SYNC)Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 2968 times by 1 test
Evaluated by:
  • dd
(conversions_mask & C_NOERROR)Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • dd
0-2968
2176 memset (ibuf,
never executed: memset (ibuf, (conversions_mask & (C_BLOCK | C_UNBLOCK)) ? ' ' : '\0', input_blocksize);
0
2177 (conversions_mask & (C_BLOCK | C_UNBLOCK)) ? ' ' : '\0',
never executed: memset (ibuf, (conversions_mask & (C_BLOCK | C_UNBLOCK)) ? ' ' : '\0', input_blocksize);
0
2178 input_blocksize);
never executed: memset (ibuf, (conversions_mask & (C_BLOCK | C_UNBLOCK)) ? ' ' : '\0', input_blocksize);
0
2179-
2180 if (r_partial + r_full >= max_records)
r_partial + r_...>= max_recordsDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 2984 times by 1 test
Evaluated by:
  • dd
1-2984
2181 nread = iread_fnc (STDIN_FILENO, ibuf, max_bytes);
executed 1 time by 1 test: nread = iread_fnc ( 0 , ibuf, max_bytes);
Executed by:
  • dd
1
2182 else-
2183 nread = iread_fnc (STDIN_FILENO, ibuf, input_blocksize);
executed 2984 times by 1 test: nread = iread_fnc ( 0 , ibuf, input_blocksize);
Executed by:
  • dd
2984
2184-
2185 if (nread > 0)
nread > 0Description
TRUEevaluated 2913 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 72 times by 1 test
Evaluated by:
  • dd
72-2913
2186 {-
2187 advance_input_offset (nread);-
2188 if (i_nocache)
i_nocacheDescription
TRUEevaluated 415 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 2498 times by 1 test
Evaluated by:
  • dd
415-2498
2189 invalidate_cache (STDIN_FILENO, nread);
executed 415 times by 1 test: invalidate_cache ( 0 , nread);
Executed by:
  • dd
415
2190 }
executed 2913 times by 1 test: end of block
Executed by:
  • dd
2913
2191 else if (nread == 0)
nread == 0Description
TRUEevaluated 72 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-72
2192 {-
2193 i_nocache_eof |= i_nocache;-
2194 o_nocache_eof |= o_nocache && ! (conversions_mask & C_NOTRUNC);
o_nocacheDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 68 times by 1 test
Evaluated by:
  • dd
! (conversions...k & C_NOTRUNC)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-68
2195 break; /* EOF. */
executed 72 times by 1 test: break;
Executed by:
  • dd
72
2196 }-
2197 else-
2198 {-
2199 if (!(conversions_mask & C_NOERROR) || status_level != STATUS_NONE)
!(conversions_...k & C_NOERROR)Description
TRUEnever evaluated
FALSEnever evaluated
status_level != STATUS_NONEDescription
TRUEnever evaluated
FALSEnever evaluated
0
2200 error (0, errno, _("error reading %s"), quoteaf (input_file));
never executed: nl_error (0, (*__errno_location ()) , dcgettext (((void *)0), "error reading %s" , 5) , quotearg_style (shell_escape_always_quoting_style, input_file));
0
2201-
2202 if (conversions_mask & C_NOERROR)
conversions_mask & C_NOERRORDescription
TRUEnever evaluated
FALSEnever evaluated
0
2203 {-
2204 print_stats ();-
2205 size_t bad_portion = input_blocksize - partread;-
2206-
2207 /* We already know this data is not cached,-
2208 but call this so that correct offsets are maintained. */-
2209 invalidate_cache (STDIN_FILENO, bad_portion);-
2210-
2211 /* Seek past the bad block if possible. */-
2212 if (!advance_input_after_read_error (bad_portion))
!advance_input... (bad_portion)Description
TRUEnever evaluated
FALSEnever evaluated
0
2213 {-
2214 exit_status = EXIT_FAILURE;-
2215-
2216 /* Suppress duplicate diagnostics. */-
2217 input_seekable = false;-
2218 input_seek_errno = ESPIPE;-
2219 }
never executed: end of block
0
2220 if ((conversions_mask & C_SYNC) && !partread)
(conversions_mask & C_SYNC)Description
TRUEnever evaluated
FALSEnever evaluated
!partreadDescription
TRUEnever evaluated
FALSEnever evaluated
0
2221 /* Replace the missing input with null bytes and-
2222 proceed normally. */-
2223 nread = 0;
never executed: nread = 0;
0
2224 else-
2225 continue;
never executed: continue;
0
2226 }-
2227 else-
2228 {-
2229 /* Write any partial block. */-
2230 exit_status = EXIT_FAILURE;-
2231 break;
never executed: break;
0
2232 }-
2233 }-
2234-
2235 n_bytes_read = nread;-
2236-
2237 if (n_bytes_read < input_blocksize)
n_bytes_read < input_blocksizeDescription
TRUEevaluated 49 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 2864 times by 1 test
Evaluated by:
  • dd
49-2864
2238 {-
2239 r_partial++;-
2240 partread = n_bytes_read;-
2241 if (conversions_mask & C_SYNC)
conversions_mask & C_SYNCDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 43 times by 1 test
Evaluated by:
  • dd
6-43
2242 {-
2243 if (!(conversions_mask & C_NOERROR))
!(conversions_...k & C_NOERROR)Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-6
2244 /* If C_NOERROR, we zeroed the block before reading. */-
2245 memset (ibuf + n_bytes_read,
executed 6 times by 1 test: memset (ibuf + n_bytes_read, (conversions_mask & (C_BLOCK | C_UNBLOCK)) ? ' ' : '\0', input_blocksize - n_bytes_read);
Executed by:
  • dd
6
2246 (conversions_mask & (C_BLOCK | C_UNBLOCK)) ? ' ' : '\0',
executed 6 times by 1 test: memset (ibuf + n_bytes_read, (conversions_mask & (C_BLOCK | C_UNBLOCK)) ? ' ' : '\0', input_blocksize - n_bytes_read);
Executed by:
  • dd
6
2247 input_blocksize - n_bytes_read);
executed 6 times by 1 test: memset (ibuf + n_bytes_read, (conversions_mask & (C_BLOCK | C_UNBLOCK)) ? ' ' : '\0', input_blocksize - n_bytes_read);
Executed by:
  • dd
6
2248 n_bytes_read = input_blocksize;-
2249 }
executed 6 times by 1 test: end of block
Executed by:
  • dd
6
2250 }
executed 49 times by 1 test: end of block
Executed by:
  • dd
49
2251 else-
2252 {-
2253 r_full++;-
2254 partread = 0;-
2255 }
executed 2864 times by 1 test: end of block
Executed by:
  • dd
2864
2256-
2257 if (ibuf == obuf) /* If not C_TWOBUFS. */
ibuf == obufDescription
TRUEevaluated 2114 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 799 times by 1 test
Evaluated by:
  • dd
799-2114
2258 {-
2259 size_t nwritten = iwrite (STDOUT_FILENO, obuf, n_bytes_read);-
2260 w_bytes += nwritten;-
2261 if (nwritten != n_bytes_read)
nwritten != n_bytes_readDescription
TRUEnever evaluated
FALSEevaluated 2114 times by 1 test
Evaluated by:
  • dd
0-2114
2262 {-
2263 error (0, errno, _("error writing %s"), quoteaf (output_file));-
2264 return EXIT_FAILURE;
never executed: return 1 ;
0
2265 }-
2266 else if (n_bytes_read == input_blocksize)
n_bytes_read =...nput_blocksizeDescription
TRUEevaluated 2104 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 10 times by 1 test
Evaluated by:
  • dd
10-2104
2267 w_full++;
executed 2104 times by 1 test: w_full++;
Executed by:
  • dd
2104
2268 else-
2269 w_partial++;
executed 10 times by 1 test: w_partial++;
Executed by:
  • dd
10
2270 continue;
executed 2114 times by 1 test: continue;
Executed by:
  • dd
2114
2271 }-
2272-
2273 /* Do any translations on the whole buffer at once. */-
2274-
2275 if (translation_needed)
translation_neededDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 798 times by 1 test
Evaluated by:
  • dd
1-798
2276 translate_buffer (ibuf, n_bytes_read);
executed 1 time by 1 test: translate_buffer (ibuf, n_bytes_read);
Executed by:
  • dd
1
2277-
2278 if (conversions_mask & C_SWAB)
conversions_mask & C_SWABDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 798 times by 1 test
Evaluated by:
  • dd
1-798
2279 bufstart = swab_buffer (ibuf, &n_bytes_read);
executed 1 time by 1 test: bufstart = swab_buffer (ibuf, &n_bytes_read);
Executed by:
  • dd
1
2280 else-
2281 bufstart = ibuf;
executed 798 times by 1 test: bufstart = ibuf;
Executed by:
  • dd
798
2282-
2283 if (conversions_mask & C_BLOCK)
conversions_mask & C_BLOCKDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 796 times by 1 test
Evaluated by:
  • dd
3-796
2284 copy_with_block (bufstart, n_bytes_read);
executed 3 times by 1 test: copy_with_block (bufstart, n_bytes_read);
Executed by:
  • dd
3
2285 else if (conversions_mask & C_UNBLOCK)
conversions_mask & C_UNBLOCKDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 784 times by 1 test
Evaluated by:
  • dd
12-784
2286 copy_with_unblock (bufstart, n_bytes_read);
executed 12 times by 1 test: copy_with_unblock (bufstart, n_bytes_read);
Executed by:
  • dd
12
2287 else-
2288 copy_simple (bufstart, n_bytes_read);
executed 784 times by 1 test: copy_simple (bufstart, n_bytes_read);
Executed by:
  • dd
784
2289 }-
2290-
2291 /* If we have a char left as a result of conv=swab, output it. */-
2292 if (char_is_saved)
char_is_savedDescription
TRUEnever evaluated
FALSEevaluated 594 times by 1 test
Evaluated by:
  • dd
0-594
2293 {-
2294 if (conversions_mask & C_BLOCK)
conversions_mask & C_BLOCKDescription
TRUEnever evaluated
FALSEnever evaluated
0
2295 copy_with_block (&saved_char, 1);
never executed: copy_with_block (&saved_char, 1);
0
2296 else if (conversions_mask & C_UNBLOCK)
conversions_mask & C_UNBLOCKDescription
TRUEnever evaluated
FALSEnever evaluated
0
2297 copy_with_unblock (&saved_char, 1);
never executed: copy_with_unblock (&saved_char, 1);
0
2298 else-
2299 output_char (saved_char);
never executed: write_output ();
never executed: end of block
oc >= output_blocksizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
2300 }-
2301-
2302 if ((conversions_mask & C_BLOCK) && col > 0)
(conversions_mask & C_BLOCK)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 593 times by 1 test
Evaluated by:
  • dd
col > 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-593
2303 {-
2304 /* If the final input line didn't end with a '\n', pad-
2305 the output block to 'conversion_blocksize' chars. */-
2306 for (size_t i = col; i < conversion_blocksize; i++)
i < conversion_blocksizeDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1-2
2307 output_char (space_character);
never executed: write_output ();
executed 2 times by 1 test: end of block
Executed by:
  • dd
oc >= output_blocksizeDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • dd
0-2
2308 }
executed 1 time by 1 test: end of block
Executed by:
  • dd
1
2309-
2310 if (col && (conversions_mask & C_UNBLOCK))
colDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 584 times by 1 test
Evaluated by:
  • dd
(conversions_mask & C_UNBLOCK)Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1-584
2311 {-
2312 /* If there was any output, add a final '\n'. */-
2313 output_char (newline_character);
never executed: write_output ();
oc >= output_blocksizeDescription
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • dd
0-9
2314 }
executed 9 times by 1 test: end of block
Executed by:
  • dd
9
2315-
2316 /* Write out the last block. */-
2317 if (oc != 0)
oc != 0Description
TRUEevaluated 34 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 560 times by 1 test
Evaluated by:
  • dd
34-560
2318 {-
2319 size_t nwritten = iwrite (STDOUT_FILENO, obuf, oc);-
2320 w_bytes += nwritten;-
2321 if (nwritten != 0)
nwritten != 0Description
TRUEevaluated 34 times by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-34
2322 w_partial++;
executed 34 times by 1 test: w_partial++;
Executed by:
  • dd
34
2323 if (nwritten != oc)
nwritten != ocDescription
TRUEnever evaluated
FALSEevaluated 34 times by 1 test
Evaluated by:
  • dd
0-34
2324 {-
2325 error (0, errno, _("error writing %s"), quoteaf (output_file));-
2326 return EXIT_FAILURE;
never executed: return 1 ;
0
2327 }-
2328 }
executed 34 times by 1 test: end of block
Executed by:
  • dd
34
2329-
2330 /* If the last write was converted to a seek, then for a regular file-
2331 or shared memory object, ftruncate to extend the size. */-
2332 if (final_op_was_seek)
final_op_was_seekDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 593 times by 1 test
Evaluated by:
  • dd
1-593
2333 {-
2334 struct stat stdout_stat;-
2335 if (fstat (STDOUT_FILENO, &stdout_stat) != 0)
fstat ( 1 , &stdout_stat) != 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
0-1
2336 {-
2337 error (0, errno, _("cannot fstat %s"), quoteaf (output_file));-
2338 return EXIT_FAILURE;
never executed: return 1 ;
0
2339 }-
2340 if (S_ISREG (stdout_stat.st_mode) || S_TYPEISSHM (&stdout_stat))
(((( stdout_st... == (0100000))Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
(( &stdout_sta...at )->st_mode)Description
TRUEnever evaluated
FALSEnever evaluated
0-1
2341 {-
2342 off_t output_offset = lseek (STDOUT_FILENO, 0, SEEK_CUR);-
2343 if (0 <= output_offset && stdout_stat.st_size < output_offset)
0 <= output_offsetDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
stdout_stat.st... output_offsetDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEnever evaluated
0-1
2344 {-
2345 if (iftruncate (STDOUT_FILENO, output_offset) != 0)
iftruncate ( 1...t_offset) != 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
0-1
2346 {-
2347 error (0, errno,-
2348 _("failed to truncate to %" PRIdMAX " bytes"-
2349 " in output file %s"),-
2350 (intmax_t) output_offset, quoteaf (output_file));-
2351 return EXIT_FAILURE;
never executed: return 1 ;
0
2352 }-
2353 }
executed 1 time by 1 test: end of block
Executed by:
  • dd
1
2354 }
executed 1 time by 1 test: end of block
Executed by:
  • dd
1
2355 }
executed 1 time by 1 test: end of block
Executed by:
  • dd
1
2356-
2357 if ((conversions_mask & C_FDATASYNC) && fdatasync (STDOUT_FILENO) != 0)
(conversions_m...& C_FDATASYNC)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 592 times by 1 test
Evaluated by:
  • dd
fdatasync ( 1 ) != 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • dd
0-592
2358 {-
2359 if (errno != ENOSYS && errno != EINVAL)
(*__errno_location ()) != 38Description
TRUEnever evaluated
FALSEnever evaluated
(*__errno_location ()) != 22Description
TRUEnever evaluated
FALSEnever evaluated
0
2360 {-
2361 error (0, errno, _("fdatasync failed for %s"), quoteaf (output_file));-
2362 exit_status = EXIT_FAILURE;-
2363 }
never executed: end of block
0
2364 conversions_mask |= C_FSYNC;-
2365 }
never executed: end of block
0
2366-
2367 if (conversions_mask & C_FSYNC)
conversions_mask & C_FSYNCDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 589 times by 1 test
Evaluated by:
  • dd
5-589
2368 while (fsync (STDOUT_FILENO) != 0)
fsync ( 1 ) != 0Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • dd
0-5
2369 if (errno != EINTR)
(*__errno_location ()) != 4Description
TRUEnever evaluated
FALSEnever evaluated
0
2370 {-
2371 error (0, errno, _("fsync failed for %s"), quoteaf (output_file));-
2372 return EXIT_FAILURE;
never executed: return 1 ;
0
2373 }-
2374-
2375 return exit_status;
executed 594 times by 1 test: return exit_status;
Executed by:
  • dd
594
2376}-
2377-
2378int-
2379main (int argc, char **argv)-
2380{-
2381 int i;-
2382 int exit_status;-
2383 off_t offset;-
2384-
2385 install_signal_handlers ();-
2386-
2387 initialize_main (&argc, &argv);-
2388 set_program_name (argv[0]);-
2389 setlocale (LC_ALL, "");-
2390 bindtextdomain (PACKAGE, LOCALEDIR);-
2391 textdomain (PACKAGE);-
2392-
2393 /* Arrange to close stdout if parse_long_options exits. */-
2394 atexit (maybe_close_stdout);-
2395-
2396 page_size = getpagesize ();-
2397-
2398 parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE, Version,-
2399 usage, AUTHORS, (char const *) NULL);-
2400 close_stdout_required = false;-
2401-
2402 if (getopt_long (argc, argv, "", long_options, NULL) != -1)
getopt_long (a...d *)0) ) != -1Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 630 times by 1 test
Evaluated by:
  • dd
3-630
2403 usage (EXIT_FAILURE);
executed 3 times by 1 test: usage ( 1 );
Executed by:
  • dd
3
2404-
2405 /* Initialize translation table to identity translation. */-
2406 for (i = 0; i < 256; i++)
i < 256Description
TRUEevaluated 161280 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 630 times by 1 test
Evaluated by:
  • dd
630-161280
2407 trans_table[i] = i;
executed 161280 times by 1 test: trans_table[i] = i;
Executed by:
  • dd
161280
2408-
2409 /* Decode arguments. */-
2410 scanargs (argc, argv);-
2411-
2412 apply_translations ();-
2413-
2414 if (input_file == NULL)
input_file == ((void *)0)Description
TRUEevaluated 67 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 561 times by 1 test
Evaluated by:
  • dd
67-561
2415 {-
2416 input_file = _("standard input");-
2417 set_fd_flags (STDIN_FILENO, input_flags, input_file);-
2418 }
executed 66 times by 1 test: end of block
Executed by:
  • dd
66
2419 else-
2420 {-
2421 if (ifd_reopen (STDIN_FILENO, input_file, O_RDONLY | input_flags, 0) < 0)
ifd_reopen ( 0..._flags, 0) < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 560 times by 1 test
Evaluated by:
  • dd
1-560
2422 die (EXIT_FAILURE, errno, _("failed to open %s"),
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"failed to open %s\", 5), quotearg_style (shell_escape_always_quoting_style, input_file)), assume (false))" ")"); int _gl_dummy...0 ) ? (void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "failed to open %s" , 5) , quotearg_style (shell_escape_always_quoting_style, input_file)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • dd
1
2423 quoteaf (input_file));
executed 1 time by 1 test: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"failed to open %s\", 5), quotearg_style (shell_escape_always_quoting_style, input_file)), assume (false))" ")"); int _gl_dummy...0 ) ? (void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "failed to open %s" , 5) , quotearg_style (shell_escape_always_quoting_style, input_file)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
Executed by:
  • dd
1
2424 }
executed 560 times by 1 test: end of block
Executed by:
  • dd
560
2425-
2426 offset = lseek (STDIN_FILENO, 0, SEEK_CUR);-
2427 input_seekable = (0 <= offset);-
2428 input_offset = MAX (0, offset);
(( 0 )>( offset ))Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 598 times by 1 test
Evaluated by:
  • dd
28-598
2429 input_seek_errno = errno;-
2430-
2431 if (output_file == NULL)
output_file == ((void *)0)Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 563 times by 1 test
Evaluated by:
  • dd
63-563
2432 {-
2433 output_file = _("standard output");-
2434 set_fd_flags (STDOUT_FILENO, output_flags, output_file);-
2435 }
executed 63 times by 1 test: end of block
Executed by:
  • dd
63
2436 else-
2437 {-
2438 mode_t perms = MODE_RW_UGO;-
2439 int opts-
2440 = (output_flags-
2441 | (conversions_mask & C_NOCREAT ? 0 : O_CREAT)-
2442 | (conversions_mask & C_EXCL ? O_EXCL : 0)-
2443 | (seek_records || (conversions_mask & C_NOTRUNC) ? 0 : O_TRUNC));-
2444-
2445 /* Open the output file with *read* access only if we might-
2446 need to read to satisfy a 'seek=' request. If we can't read-
2447 the file, go ahead with write-only access; it might work. */-
2448 if ((! seek_records
! seek_recordsDescription
TRUEevaluated 543 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 20 times by 1 test
Evaluated by:
  • dd
20-543
2449 || ifd_reopen (STDOUT_FILENO, output_file, O_RDWR | opts, perms) < 0)
ifd_reopen ( 1...ts, perms) < 0Description
TRUEnever evaluated
FALSEevaluated 20 times by 1 test
Evaluated by:
  • dd
0-20
2450 && (ifd_reopen (STDOUT_FILENO, output_file, O_WRONLY | opts, perms)
(ifd_reopen ( ...s, perms) < 0)Description
TRUEnever evaluated
FALSEevaluated 543 times by 1 test
Evaluated by:
  • dd
0-543
2451 < 0))
(ifd_reopen ( ...s, perms) < 0)Description
TRUEnever evaluated
FALSEevaluated 543 times by 1 test
Evaluated by:
  • dd
0-543
2452 die (EXIT_FAILURE, errno, _("failed to open %s"),
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"failed to open %s\", 5), quotearg_style (shell_escape_always_quoting_style, output_file)), assume (false))" ")"); int _gl_dumm... ) ? (void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "failed to open %s" , 5) , quotearg_style (shell_escape_always_quoting_style, output_file)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
2453 quoteaf (output_file));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"failed to open %s\", 5), quotearg_style (shell_escape_always_quoting_style, output_file)), assume (false))" ")"); int _gl_dumm... ) ? (void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "failed to open %s" , 5) , quotearg_style (shell_escape_always_quoting_style, output_file)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
2454-
2455 if (seek_records != 0 && !(conversions_mask & C_NOTRUNC))
seek_records != 0Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 543 times by 1 test
Evaluated by:
  • dd
!(conversions_...k & C_NOTRUNC)Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 3 times by 1 test
Evaluated by:
  • dd
3-543
2456 {-
2457 uintmax_t size = seek_records * output_blocksize + seek_bytes;-
2458 unsigned long int obs = output_blocksize;-
2459-
2460 if (OFF_T_MAX / output_blocksize < seek_records)
((off_t) (! (!...< seek_recordsDescription
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • dd
0-17
2461 die (EXIT_FAILURE, 0,
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"offset too large: \" \"cannot truncate to a length of seek=%\"\"l\" \"u\"\"\" \" (%lu-byte) blocks\", 5), seek_records, obs), assume (false))" ")")...(void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , 0, dcgettext (((void *)0), "offset too large: " "cannot truncate to a length of seek=%" "l" "u" "" " (%lu-byte) blocks" , 5) , seek_records, obs), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
2462 _("offset too large: "
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"offset too large: \" \"cannot truncate to a length of seek=%\"\"l\" \"u\"\"\" \" (%lu-byte) blocks\", 5), seek_records, obs), assume (false))" ")")...(void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , 0, dcgettext (((void *)0), "offset too large: " "cannot truncate to a length of seek=%" "l" "u" "" " (%lu-byte) blocks" , 5) , seek_records, obs), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
2463 "cannot truncate to a length of seek=%"PRIuMAX""
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"offset too large: \" \"cannot truncate to a length of seek=%\"\"l\" \"u\"\"\" \" (%lu-byte) blocks\", 5), seek_records, obs), assume (false))" ")")...(void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , 0, dcgettext (((void *)0), "offset too large: " "cannot truncate to a length of seek=%" "l" "u" "" " (%lu-byte) blocks" , 5) , seek_records, obs), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
2464 " (%lu-byte) blocks"),
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"offset too large: \" \"cannot truncate to a length of seek=%\"\"l\" \"u\"\"\" \" (%lu-byte) blocks\", 5), seek_records, obs), assume (false))" ")")...(void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , 0, dcgettext (((void *)0), "offset too large: " "cannot truncate to a length of seek=%" "l" "u" "" " (%lu-byte) blocks" , 5) , seek_records, obs), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
2465 seek_records, obs);
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, 0, dcgettext (((void *)0), \"offset too large: \" \"cannot truncate to a length of seek=%\"\"l\" \"u\"\"\" \" (%lu-byte) blocks\", 5), seek_records, obs), assume (false))" ")")...(void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , 0, dcgettext (((void *)0), "offset too large: " "cannot truncate to a length of seek=%" "l" "u" "" " (%lu-byte) blocks" , 5) , seek_records, obs), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
2466-
2467 if (iftruncate (STDOUT_FILENO, size) != 0)
iftruncate ( 1 , size) != 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 14 times by 1 test
Evaluated by:
  • dd
3-14
2468 {-
2469 /* Complain only when ftruncate fails on a regular file, a-
2470 directory, or a shared memory object, as POSIX 1003.1-2004-
2471 specifies ftruncate's behavior only for these file types.-
2472 For example, do not complain when Linux kernel 2.4 ftruncate-
2473 fails on /dev/fd0. */-
2474 int ftruncate_errno = errno;-
2475 struct stat stdout_stat;-
2476 if (fstat (STDOUT_FILENO, &stdout_stat) != 0)
fstat ( 1 , &stdout_stat) != 0Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • dd
0-3
2477 die (EXIT_FAILURE, errno, _("cannot fstat %s"),
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"cannot fstat %s\", 5), quotearg_style (shell_escape_always_quoting_style, output_file)), assume (false))" ")"); int _gl_dummy;... 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "cannot fstat %s" , 5) , quotearg_style (shell_escape_always_quoting_style, output_file)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
2478 quoteaf (output_file));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, (*__errno_location ()), dcgettext (((void *)0), \"cannot fstat %s\", 5), quotearg_style (shell_escape_always_quoting_style, output_file)), assume (false))" ")"); int _gl_dummy;... 0 ) ? (void) 0 : __builtin_unreachable ()))) : ((nl_error ( 1 , (*__errno_location ()) , dcgettext (((void *)0), "cannot fstat %s" , 5) , quotearg_style (shell_escape_always_quoting_style, output_file)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
2479 if (S_ISREG (stdout_stat.st_mode)
(((( stdout_st... == (0100000))Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • dd
0-3
2480 || S_ISDIR (stdout_stat.st_mode)
(((( stdout_st... == (0040000))Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • dd
0-3
2481 || S_TYPEISSHM (&stdout_stat))
(( &stdout_sta...at )->st_mode)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • dd
0-3
2482 die (EXIT_FAILURE, ftruncate_errno,
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, ftruncate_errno, dcgettext (((void *)0), \"failed to truncate to %\"\"l\" \"u\"\" bytes\" \" in output file %s\", 5), size, quotearg_style (shell_escape_always_quoting_style, o...) : ((nl_error ( 1 , ftruncate_errno, dcgettext (((void *)0), "failed to truncate to %" "l" "u" " bytes" " in output file %s" , 5) , size, quotearg_style (shell_escape_always_quoting_style, output_file)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
2483 _("failed to truncate to %"PRIuMAX" bytes"
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, ftruncate_errno, dcgettext (((void *)0), \"failed to truncate to %\"\"l\" \"u\"\" bytes\" \" in output file %s\", 5), size, quotearg_style (shell_escape_always_quoting_style, o...) : ((nl_error ( 1 , ftruncate_errno, dcgettext (((void *)0), "failed to truncate to %" "l" "u" " bytes" " in output file %s" , 5) , size, quotearg_style (shell_escape_always_quoting_style, output_file)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
2484 " in output file %s"),
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, ftruncate_errno, dcgettext (((void *)0), \"failed to truncate to %\"\"l\" \"u\"\" bytes\" \" in output file %s\", 5), size, quotearg_style (shell_escape_always_quoting_style, o...) : ((nl_error ( 1 , ftruncate_errno, dcgettext (((void *)0), "failed to truncate to %" "l" "u" " bytes" " in output file %s" , 5) , size, quotearg_style (shell_escape_always_quoting_style, output_file)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
2485 size, quoteaf (output_file));
never executed: ((!!sizeof (struct { _Static_assert ( 1 , "verify_expr (" "1" ", " "(error (1, ftruncate_errno, dcgettext (((void *)0), \"failed to truncate to %\"\"l\" \"u\"\" bytes\" \" in output file %s\", 5), size, quotearg_style (shell_escape_always_quoting_style, o...) : ((nl_error ( 1 , ftruncate_errno, dcgettext (((void *)0), "failed to truncate to %" "l" "u" " bytes" " in output file %s" , 5) , size, quotearg_style (shell_escape_always_quoting_style, output_file)), (( 0 ) ? (void) 0 : __builtin_unreachable ())))) ;
0
2486 }
executed 3 times by 1 test: end of block
Executed by:
  • dd
3
2487 }
executed 17 times by 1 test: end of block
Executed by:
  • dd
17
2488 }
executed 563 times by 1 test: end of block
Executed by:
  • dd
563
2489-
2490 start_time = gethrxtime ();-
2491 next_time = start_time + XTIME_PRECISION;-
2492-
2493 exit_status = dd_copy ();-
2494-
2495 if (max_records == 0 && max_bytes == 0)
max_records == 0Description
TRUEevaluated 27 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 593 times by 1 test
Evaluated by:
  • dd
max_bytes == 0Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
1-593
2496 {-
2497 /* Special case to invalidate cache to end of file. */-
2498 if (i_nocache && !invalidate_cache (STDIN_FILENO, 0))
i_nocacheDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 22 times by 1 test
Evaluated by:
  • dd
!invalidate_cache ( 0 , 0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 3 times by 1 test
Evaluated by:
  • dd
1-22
2499 {-
2500 error (0, errno, _("failed to discard cache for: %s"),-
2501 quotef (input_file));-
2502 exit_status = EXIT_FAILURE;-
2503 }
executed 1 time by 1 test: end of block
Executed by:
  • dd
1
2504 if (o_nocache && !invalidate_cache (STDOUT_FILENO, 0))
o_nocacheDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • dd
FALSEevaluated 25 times by 1 test
Evaluated by:
  • dd
!invalidate_cache ( 1 , 0)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • dd
0-25
2505 {-
2506 error (0, errno, _("failed to discard cache for: %s"),-
2507 quotef (output_file));-
2508 exit_status = EXIT_FAILURE;-
2509 }
never executed: end of block
0
2510 }
executed 26 times by 1 test: end of block
Executed by:
  • dd
26
2511 else-
2512 {-
2513 /* Invalidate any pending region or to EOF if appropriate. */-
2514 if (i_nocache || i_nocache_eof)
i_nocacheDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 587 times by 1 test
Evaluated by:
  • dd
i_nocache_eofDescription
TRUEnever evaluated
FALSEevaluated 587 times by 1 test
Evaluated by:
  • dd
0-587
2515 invalidate_cache (STDIN_FILENO, 0);
executed 7 times by 1 test: invalidate_cache ( 0 , 0);
Executed by:
  • dd
7
2516 if (o_nocache || o_nocache_eof)
o_nocacheDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 590 times by 1 test
Evaluated by:
  • dd
o_nocache_eofDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • dd
FALSEevaluated 585 times by 1 test
Evaluated by:
  • dd
4-590
2517 invalidate_cache (STDOUT_FILENO, 0);
executed 9 times by 1 test: invalidate_cache ( 1 , 0);
Executed by:
  • dd
9
2518 }
executed 594 times by 1 test: end of block
Executed by:
  • dd
594
2519-
2520 finish_up ();-
2521 return exit_status;
executed 620 times by 1 test: return exit_status;
Executed by:
  • dd
620
2522}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2