bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

"dd --" POSIX-conformance fix; diagnostics made more precise


From: Paul Eggert
Subject: "dd --" POSIX-conformance fix; diagnostics made more precise
Date: Sat, 18 Sep 2004 18:49:10 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

POSIX requires "dd --" to behave like plain "dd", but GNU dd doesn't
support this.  Also, in the documentation and diagnostics, GNU "dd"
refers to operands as options in several places.  I installed this fix:

2004-09-18  Paul Eggert  <address@hidden>

        * doc/coreutils.texi (dd invocation): Distinguish between options
        (e.g., --help) and operands (e.g., if=file).  Move miscellaneous
        stuff after the operand descriptions, for clarity.
        * src/dd.c (usage): Distinguish between options and operands.
        (scanargs): Don't mess with argc, argv; getopt_long handles this now.
        Say "operands" for operands, not "options".
        (main): Use getopt_long, so that "dd --" works as POSIX requires.
        * tests/dd/misc: Check for "dd --".

Index: doc/coreutils.texi
===================================================================
RCS file: /home/eggert/coreutils/cu/doc/coreutils.texi,v
retrieving revision 1.211
diff -p -u -r1.211 coreutils.texi
--- doc/coreutils.texi  9 Sep 2004 23:21:38 -0000       1.211
+++ doc/coreutils.texi  19 Sep 2004 01:41:33 -0000
@@ -6554,53 +6554,15 @@ However, mount point directories @emph{a
 
 @command{dd} copies a file (from standard input to standard output, by
 default) with a changeable I/O block size, while optionally performing
-conversions on it.  Synopsis:
+conversions on it.  Synopses:
 
 @example
-dd address@hidden@dots{}
address@hidden example
-
-The program accepts the following options.  Also see @ref{Common options}.
-
address@hidden multipliers after numbers
-The numeric-valued options below (@var{bytes} and @var{blocks}) can be
-followed by a multiplier: @samp{b}=512, @samp{c}=1,
address@hidden, @address@hidden@var{m}, or any of the
-standard block size suffixes like @samp{k}=1024 (@pxref{Block size}).
-
-Use different @command{dd} invocations to use different block sizes for
-skipping and I/address@hidden  For example, the following shell commands copy 
data
-in 512 KiB blocks between a disk and a tape, but do not save or restore a
-4 KiB label at the start of the disk:
-
address@hidden
-disk=/dev/rdsk/c0t1d0s2
-tape=/dev/rmt/0
-
-# Copy all but the label from disk to tape.
-(dd bs=4k skip=1 count=0 && dd bs=512k) <$disk >$tape
-
-# Copy from tape back to disk, but leave the disk label alone.
-(dd bs=4k seek=1 count=0 && dd bs=512k) <$tape >$disk
address@hidden example
-
-Note that sending a @samp{SIGUSR1} signal to a running @command{dd}
-process makes it print to standard error the number of records read
-and written so far, then to resume copying.  In the example below,
address@hidden is run in the background to copy 10 million blocks.
-The @command{kill} command makes it output the first pair of
-intermediate record counts,
-and when @command{dd} completes, it outputs the final pair.
-
address@hidden
-$ dd if=/dev/zero of=/dev/null count=10M & pid=$!
-$ kill -s USR1 $pid; sleep 99
-5403604+0 records in
-5403604+0 records out
-10485760+0 records in
-10485760+0 records out
+dd address@hidden@dots{}
+dd @var{option}
 @end example
 
+The only options are @option{--help} and @option{--version}.
address@hidden options}.  @command{dd} accepts the following operands.
 
 @table @samp
 
@@ -6813,6 +6775,45 @@ should not be specified, and the other f
 affected file descriptors, even after @command{dd} exits.
 
 @end table
+
address@hidden multipliers after numbers
+The numeric-valued strings above (@var{bytes} and @var{blocks}) can be
+followed by a multiplier: @samp{b}=512, @samp{c}=1,
address@hidden, @address@hidden@var{m}, or any of the
+standard block size suffixes like @samp{k}=1024 (@pxref{Block size}).
+
+Use different @command{dd} invocations to use different block sizes for
+skipping and I/address@hidden  For example, the following shell commands copy 
data
+in 512 KiB blocks between a disk and a tape, but do not save or restore a
+4 KiB label at the start of the disk:
+
address@hidden
+disk=/dev/rdsk/c0t1d0s2
+tape=/dev/rmt/0
+
+# Copy all but the label from disk to tape.
+(dd bs=4k skip=1 count=0 && dd bs=512k) <$disk >$tape
+
+# Copy from tape back to disk, but leave the disk label alone.
+(dd bs=4k seek=1 count=0 && dd bs=512k) <$tape >$disk
address@hidden example
+
+Note that sending a @samp{SIGUSR1} signal to a running @command{dd}
+process makes it print to standard error the number of records read
+and written so far, then to resume copying.  In the example below,
address@hidden is run in the background to copy 10 million blocks.
+The @command{kill} command makes it output the first pair of
+intermediate record counts,
+and when @command{dd} completes, it outputs the final pair.
+
address@hidden
+$ dd if=/dev/zero of=/dev/null count=10M & pid=$!
+$ kill -s USR1 $pid; sleep 99
+5403604+0 records in
+5403604+0 records out
+10485760+0 records in
+10485760+0 records out
address@hidden example
 
 @exitstatus
 
Index: src/dd.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/dd.c,v
retrieving revision 1.165
diff -p -u -r1.165 dd.c
--- src/dd.c    3 Sep 2004 08:11:34 -0000       1.165
+++ src/dd.c    19 Sep 2004 01:35:38 -0000
@@ -332,9 +332,13 @@ usage (int status)
             program_name);
   else
     {
-      printf (_("Usage: %s [OPTION]...\n"), program_name);
+      printf (_("\
+Usage: %s [OPERAND]...\n\
+  or:  %s OPTION\n\
+"),
+             program_name, program_name);
       fputs (_("\
-Copy a file, converting and formatting according to the options.\n\
+Copy a file, converting and formatting according to the operands.\n\
 \n\
   bs=BYTES        force ibs=BYTES and obs=BYTES\n\
   cbs=BYTES       convert BYTES bytes at a time\n\
@@ -351,8 +355,6 @@ Copy a file, converting and formatting a
   seek=BLOCKS     skip BLOCKS obs-sized blocks at start of output\n\
   skip=BLOCKS     skip BLOCKS ibs-sized blocks at start of input\n\
 "), stdout);
-      fputs (HELP_OPTION_DESCRIPTION, stdout);
-      fputs (VERSION_OPTION_DESCRIPTION, stdout);
       fputs (_("\
 \n\
 BLOCKS and BYTES may be followed by the following multiplicative suffixes:\n\
@@ -408,7 +410,12 @@ then to resume copying.\n\
   $ kill -USR1 $pid; sleep 1; kill $pid\n\
   10899206+0 records in\n\
   10899206+0 records out\n\
+\n\
+Options are:\n\
+\n\
 "), stdout);
+      fputs (HELP_OPTION_DESCRIPTION, stdout);
+      fputs (VERSION_OPTION_DESCRIPTION, stdout);
       printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
     }
   exit (status);
@@ -557,8 +564,8 @@ write_output (void)
 static char const iflag_error_msgid[] = N_("invalid input flag: %s");
 static char const oflag_error_msgid[] = N_("invalid output flag: %s");
 
-/* Interpret one "conv=..." or similar option STR according to the
-   symbols in TABLE, returning the flags specified.  If the option
+/* Interpret one "conv=..." or similar operand STR according to the
+   symbols in TABLE, returning the flags specified.  If the operand
    cannot be parsed, use ERROR_MSGID to generate a diagnostic.
    As a by product, this function replaces each `,' in STR with a NUL byte.  */
 
@@ -633,9 +640,6 @@ scanargs (int argc, char **argv)
 {
   int i;
 
-  --argc;
-  ++argv;
-
   for (i = optind; i < argc; i++)
     {
       char *name, *val;
@@ -644,7 +648,7 @@ scanargs (int argc, char **argv)
       val = strchr (name, '=');
       if (val == NULL)
        {
-         error (0, 0, _("unrecognized option %s"), quote (name));
+         error (0, 0, _("unrecognized operand %s"), quote (name));
          usage (EXIT_FAILURE);
        }
       *val++ = '\0';
@@ -696,7 +700,7 @@ scanargs (int argc, char **argv)
            max_records = n;
          else
            {
-             error (0, 0, _("unrecognized option %s=%s"),
+             error (0, 0, _("unrecognized operand %s=%s"),
                     quote_n (0, name), quote_n (1, val));
              usage (EXIT_FAILURE);
            }
@@ -1356,6 +1360,8 @@ main (int argc, char **argv)
 
   parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE, VERSION,
                      usage, AUTHORS, (char const *) NULL);
+  if (getopt_long (argc, argv, "", NULL, NULL) != -1)
+    usage (EXIT_FAILURE);
 
   /* Don't close stdout on exit from here on.  */
   closeout_func = NULL;
@@ -1422,7 +1428,7 @@ main (int argc, char **argv)
 
          /* Complain only when ftruncate fails on a regular file, a
             directory, or a shared memory object, as
-            POSIX 1003.1-2003 specifies ftruncate's behavior only for these
+            POSIX 1003.1-2004 specifies ftruncate's behavior only for these
             file types.  For example, do not complain when Linux 2.4
             ftruncate fails on /dev/fd0.  */
          if (ftruncate (STDOUT_FILENO, o) != 0
Index: tests/dd/misc
===================================================================
RCS file: /home/eggert/coreutils/cu/tests/dd/misc,v
retrieving revision 1.1
diff -p -u -r1.1 misc
--- tests/dd/misc       11 Apr 1999 02:17:48 -0000      1.1
+++ tests/dd/misc       19 Sep 2004 01:34:25 -0000
@@ -18,6 +18,10 @@ fi
 dd if=$tmp_in of=$tmp_out > /dev/null 2>&1 || fail=1
 cmp $tmp_in $tmp_out || fail=1
 
+rm $tmp_out
+dd -- if=$tmp_in of=$tmp_out > /dev/null 2>&1 || fail=1
+cmp $tmp_in $tmp_out || fail=1
+
 rm -f $tmp_in $tmp_out
 
 exit $fail




reply via email to

[Prev in Thread] Current Thread [Next in Thread]