typo fix in a comment in a testcase. oh well...
[oweals/busybox.git] / coreutils / dd.c
index 4d1ef0b76434fe46ea5e71e0d11226574bd1d47e..c5c9476afc483e6dce789a264a271b977a98e45f 100644 (file)
@@ -8,7 +8,6 @@
  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  */
 
-#include <signal.h>  /* For FEATURE_DD_SIGNAL_HANDLING */
 #include "libbb.h"
 
 /* This is a NOEXEC applet. Be very careful! */
@@ -30,18 +29,20 @@ static const struct suffix_mult dd_suffixes[] = {
        { "M", 1048576 },
        { "GD", 1000000000 },
        { "G", 1073741824 },
-       { }
+       { "", 0 }
 };
 
 struct globals {
        off_t out_full, out_part, in_full, in_part;
 };
 #define G (*(struct globals*)&bb_common_bufsiz1)
-/* We have to zero it out because of NOEXEC */
-#define INIT_G() memset(&G, 0, sizeof(G))
+#define INIT_G() do { \
+       /* we have to zero it out because of NOEXEC */ \
+       memset(&G, 0, sizeof(G)); \
+} while (0)
 
 
-static void dd_output_status(int ATTRIBUTE_UNUSED cur_signal)
+static void dd_output_status(int UNUSED_PARAM cur_signal)
 {
        /* Deliberately using %u, not %d */
        fprintf(stderr, "%"OFF_FMT"u+%"OFF_FMT"u records in\n"
@@ -65,7 +66,7 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
        ssize_t n = full_write_or_warn(buf, len, filename);
        if (n < 0)
                return 1;
-       if (n == obs)
+       if ((size_t)n == obs)
                G.out_full++;
        else if (n) /* > 0 */
                G.out_part++;
@@ -79,7 +80,7 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
 #endif
 
 int dd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int dd_main(int argc ATTRIBUTE_UNUSED, char **argv)
+int dd_main(int argc UNUSED_PARAM, char **argv)
 {
        enum {
                /* Must be in the same order as OP_conv_XXX! */
@@ -287,23 +288,26 @@ int dd_main(int argc ATTRIBUTE_UNUSED, char **argv)
        }
 
        while (!(flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
-               if (flags & FLAG_NOERROR) /* Pre-zero the buffer if conv=noerror */
-                       memset(ibuf, 0, ibs);
                n = safe_read(ifd, ibuf, ibs);
                if (n == 0)
                        break;
                if (n < 0) {
+                       /* "Bad block" */
                        if (!(flags & FLAG_NOERROR))
                                goto die_infile;
-                       n = ibs;
                        bb_simple_perror_msg(infile);
+                       /* GNU dd with conv=noerror skips over bad blocks */
+                       xlseek(ifd, ibs, SEEK_CUR);
+                       /* conv=noerror,sync writes NULs,
+                        * conv=noerror just ignores input bad blocks */
+                       n = 0;
                }
                if ((size_t)n == ibs)
                        G.in_full++;
                else {
                        G.in_part++;
                        if (flags & FLAG_SYNC) {
-                               memset(ibuf + n, '\0', ibs - n);
+                               memset(ibuf + n, 0, ibs - n);
                                n = ibs;
                        }
                }
@@ -312,7 +316,7 @@ int dd_main(int argc ATTRIBUTE_UNUSED, char **argv)
                        while (n) {
                                size_t d = obs - oc;
 
-                               if (d > n)
+                               if (d > (size_t)n)
                                        d = n;
                                memcpy(obuf + oc, tmp, d);
                                n -= d;