diff options
Diffstat (limited to 'src/dd.c')
-rw-r--r-- | src/dd.c | 37 |
1 files changed, 23 insertions, 14 deletions
@@ -1,5 +1,5 @@ /* dd -- convert a file while copying it. - Copyright (C) 1985-2012 Free Software Foundation, Inc. + Copyright (C) 1985-2013 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -135,7 +135,10 @@ enum /* Status bit masks. */ enum { - STATUS_NOXFER = 01 + STATUS_NOXFER = 01, + STATUS_NOCOUNTS = 02, + STATUS_LAST = STATUS_NOCOUNTS, + STATUS_NONE = STATUS_LAST | (STATUS_LAST - 1) }; /* The name of the input file, or NULL for the standard input. */ @@ -370,6 +373,7 @@ static struct symbol_value const flags[] = static struct symbol_value const statuses[] = { {"noxfer", STATUS_NOXFER}, + {"none", STATUS_NONE}, {"", 0} }; @@ -536,11 +540,12 @@ Copy a file, converting and formatting according to the operands.\n\ oflag=FLAGS write as per the comma separated symbol list\n\ seek=N skip N obs-sized blocks at start of output\n\ skip=N skip N ibs-sized blocks at start of input\n\ - status=noxfer suppress transfer statistics\n\ + status=WHICH WHICH info to suppress outputting to stderr;\n\ + 'noxfer' suppresses transfer stats, 'none' suppresses all\n\ "), stdout); fputs (_("\ \n\ -BLOCKS and BYTES may be followed by the following multiplicative suffixes:\n\ +N and BYTES may be followed by the following multiplicative suffixes:\n\ c =1, w =2, b =512, kB =1000, K =1024, MB =1000*1000, M =1024*1024, xM =M\n\ GB =1000*1000*1000, G =1024*1024*1024, and so on for T, P, E, Z, Y.\n\ \n\ @@ -664,7 +669,6 @@ multiple_bits_set (int i) static void print_stats (void) { - xtime_t now = gethrxtime (); char hbuf[LONGEST_HUMAN_READABLE + 1]; int human_opts = (human_autoscale | human_round_to_nearest @@ -672,6 +676,9 @@ print_stats (void) double delta_s; char const *bytes_per_second; + if ((status_flags & STATUS_NONE) == STATUS_NONE) + return; + fprintf (stderr, _("%"PRIuMAX"+%"PRIuMAX" records in\n" "%"PRIuMAX"+%"PRIuMAX" records out\n"), @@ -697,6 +704,7 @@ print_stats (void) w_bytes, human_readable (w_bytes, hbuf, human_opts, 1, 1)); + xtime_t now = gethrxtime (); if (start_time < now) { double XTIME_PRECISIONe0 = XTIME_PRECISION; @@ -1606,7 +1614,7 @@ skip (int fdesc, char const *file, uintmax_t records, size_t blocksize, { if (fdesc == STDIN_FILENO) { - error (0, errno, _("reading %s"), quote (file)); + error (0, errno, _("error reading %s"), quote (file)); if (conversions_mask & C_NOERROR) print_stats (); } @@ -1973,7 +1981,7 @@ dd_copy (void) if (nread < 0) { - error (0, errno, _("reading %s"), quote (input_file)); + error (0, errno, _("error reading %s"), quote (input_file)); if (conversions_mask & C_NOERROR) { print_stats (); @@ -2036,7 +2044,7 @@ dd_copy (void) w_bytes += nwritten; if (nwritten != n_bytes_read) { - error (0, errno, _("writing %s"), quote (output_file)); + error (0, errno, _("error writing %s"), quote (output_file)); return EXIT_FAILURE; } else if (n_bytes_read == input_blocksize) @@ -2099,7 +2107,7 @@ dd_copy (void) w_partial++; if (nwritten != oc) { - error (0, errno, _("writing %s"), quote (output_file)); + error (0, errno, _("error writing %s"), quote (output_file)); return EXIT_FAILURE; } } @@ -2122,9 +2130,9 @@ dd_copy (void) if (ftruncate (STDOUT_FILENO, output_offset) != 0) { error (0, errno, - _("failed to truncate to %"PRIuMAX" bytes" + _("failed to truncate to %" PRIdMAX " bytes" " in output file %s"), - output_offset, quote (output_file)); + (intmax_t) output_offset, quote (output_file)); return EXIT_FAILURE; } } @@ -2196,7 +2204,7 @@ main (int argc, char **argv) else { if (fd_reopen (STDIN_FILENO, input_file, O_RDONLY | input_flags, 0) < 0) - error (EXIT_FAILURE, errno, _("opening %s"), quote (input_file)); + error (EXIT_FAILURE, errno, _("failed to open %s"), quote (input_file)); } offset = lseek (STDIN_FILENO, 0, SEEK_CUR); @@ -2211,7 +2219,7 @@ main (int argc, char **argv) } else { - mode_t perms = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; + mode_t perms = MODE_RW_UGO; int opts = (output_flags | (conversions_mask & C_NOCREAT ? 0 : O_CREAT) @@ -2225,7 +2233,8 @@ main (int argc, char **argv) || fd_reopen (STDOUT_FILENO, output_file, O_RDWR | opts, perms) < 0) && (fd_reopen (STDOUT_FILENO, output_file, O_WRONLY | opts, perms) < 0)) - error (EXIT_FAILURE, errno, _("opening %s"), quote (output_file)); + error (EXIT_FAILURE, errno, _("failed to open %s"), + quote (output_file)); if (seek_records != 0 && !(conversions_mask & C_NOTRUNC)) { |