]> www.infradead.org Git - mtd-utils.git/commitdiff
nandwrite: Use Boolean Mnemonics from stdbool.h
authorGrant Erickson <gerickson@nuovations.com>
Sun, 7 Sep 2008 18:29:03 +0000 (18:29 +0000)
committerJosh Boyer <jwboyer@gmail.com>
Mon, 8 Sep 2008 14:27:27 +0000 (10:27 -0400)
Added include directive for stdbool.h and leveraged where appropriate
to improve code readability by making variable intent and usage more
explicit.

Signed-off-by: Grant Erickson <gerickson@nuovations.com>
Acked-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: Josh Boyer <jwboyer@gmail.com>
nandwrite.c

index e5de140e5e583f5637f4df50d974f5ba45c01773..5fbed4143793fe3f2fa5dad044da071c3477d1a9 100644 (file)
@@ -23,6 +23,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -108,15 +109,15 @@ static void display_version (void)
 
 static const char      *mtd_device, *img;
 static int             mtdoffset = 0;
-static int             quiet = 0;
-static int             writeoob = 0;
-static int             markbad = 0;
-static int             autoplace = 0;
-static int             forcejffs2 = 0;
-static int             forceyaffs = 0;
-static int             forcelegacy = 0;
-static int             noecc = 0;
-static int             pad = 0;
+static bool            quiet = false;
+static bool            writeoob = false;
+static bool            autoplace = false;
+static bool            markbad = false;
+static bool            forcejffs2 = false;
+static bool            forceyaffs = false;
+static bool            forcelegacy = false;
+static bool            noecc = false;
+static bool            pad = false;
 static int             blockalign = 1; /*default to using 16K block size */
 
 static void process_options (int argc, char * const argv[])
@@ -161,31 +162,31 @@ static void process_options (int argc, char * const argv[])
                                }
                                break;
                        case 'q':
-                               quiet = 1;
+                               quiet = true;
                                break;
                        case 'a':
-                               autoplace = 1;
+                               autoplace = true;
                                break;
                        case 'j':
-                               forcejffs2 = 1;
+                               forcejffs2 = true;
                                break;
                        case 'y':
-                               forceyaffs = 1;
+                               forceyaffs = true;
                                break;
                        case 'f':
-                               forcelegacy = 1;
+                               forcelegacy = true;
                                break;
                        case 'n':
-                               noecc = 1;
+                               noecc = true;
                                break;
                        case 'm':
-                               markbad = 1;
+                               markbad = true;
                                break;
                        case 'o':
-                               writeoob = 1;
+                               writeoob = true;
                                break;
                        case 'p':
-                               pad = 1;
+                               pad = true;
                                break;
                        case 's':
                                mtdoffset = strtol (optarg, NULL, 0);
@@ -211,7 +212,8 @@ static void process_options (int argc, char * const argv[])
  */
 int main(int argc, char * const argv[])
 {
-       int cnt, fd, ifd, imglen = 0, pagelen, baderaseblock, blockstart = -1;
+       int cnt, fd, ifd, imglen = 0, pagelen, blockstart = -1;
+       bool baderaseblock = false;
        struct mtd_info_user meminfo;
        struct mtd_oob_buf oob;
        loff_t offs;
@@ -345,7 +347,7 @@ int main(int argc, char * const argv[])
        imglen = lseek(ifd, 0, SEEK_END);
        lseek (ifd, 0, SEEK_SET);
 
-       pagelen = meminfo.writesize + ((writeoob == 1) ? meminfo.oobsize : 0);
+       pagelen = meminfo.writesize + ((writeoob) ? meminfo.oobsize : 0);
 
        // Check, if file is pagealigned
        if ((!pad) && ((imglen % pagelen) != 0)) {
@@ -372,7 +374,7 @@ int main(int argc, char * const argv[])
                while (blockstart != (mtdoffset & (~meminfo.erasesize + 1))) {
                        blockstart = mtdoffset & (~meminfo.erasesize + 1);
                        offs = blockstart;
-                       baderaseblock = 0;
+                       baderaseblock = false;
                        if (!quiet)
                                fprintf (stdout, "Writing data to block %x\n", blockstart);
 
@@ -383,7 +385,7 @@ int main(int argc, char * const argv[])
                                        goto closeall;
                                }
                                if (ret == 1) {
-                                       baderaseblock = 1;
+                                       baderaseblock = true;
                                        if (!quiet)
                                                fprintf (stderr, "Bad block at %x, %u block(s) "
                                                                "from %x will be skipped\n",