]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hexdump: use strtosize() for -n and -s
authorKarel Zak <kzak@redhat.com>
Wed, 21 Mar 2012 18:35:22 +0000 (19:35 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 21 Mar 2012 18:35:22 +0000 (19:35 +0100)
strtosize() is based on uintmax_t and supports all possible suffixes
(B,M,G,T ...)

Reported-by: Simon de Vlieger <simon@ikanobori.jp>
Signed-off-by: Karel Zak <kzak@redhat.com>
text-utils/hexdump.c
text-utils/hexdump.h
text-utils/hexsyntax.c

index 553220d8997c607e9b4997fcff1a2304f181fdb4..7edb053dbac8e4aedc78233a1a4dfe415d1dcdc0 100644 (file)
@@ -47,7 +47,7 @@
 FS *fshead;                            /* head of format strings */
 int blocksize;                         /* data block size */
 int exitval;                           /* final exit value */
-int length = -1;                       /* max bytes to read */
+ssize_t length = -1;                   /* max bytes to read */
 
 int main(int argc, char **argv)
 {
index 52a64bfe9caf9aa79a92350e66261460f983a69c..622407627f24f9ef812ea8358df70395238c29a7 100644 (file)
@@ -75,7 +75,7 @@ extern FS *fshead;                    /* head of format strings list */
 extern int blocksize;                  /* data block size */
 extern int deprecated;                 /* od compatibility */
 extern int exitval;                    /* final exit value */
-extern int length;                     /* max bytes to read */
+extern ssize_t length;                 /* max bytes to read */
 extern off_t skip;                      /* bytes to skip */
 
 enum _vflag { ALL, DUP, FIRST, WAIT }; /* -v values */
index 5cdd1de96295cbeeeca033f6315eddc28d30a177..19bb76b0b2785c522e0790c42401623205f0fe77 100644 (file)
@@ -53,7 +53,8 @@ void
 newsyntax(int argc, char ***argvp)
 {
        int ch;
-       char *p, **argv;
+       char **argv;
+       uintmax_t o;
 
        argv = *argvp;
        while ((ch = getopt(argc, argv, "bcCde:f:n:os:vxV")) != -1) {
@@ -82,26 +83,20 @@ newsyntax(int argc, char ***argvp)
                        addfile(optarg);
                        break;
                case 'n':
-                       length = strtol_or_err(optarg, _("bad length value"));
+                       if (strtosize(optarg, &o))
+                               errx(EXIT_FAILURE,
+                                    _("invalid length value '%s' specified"), optarg);
+                       length = o;
                        break;
                case 'o':
                        add("\"%07.7_Ax\n\"");
                        add("\"%07.7_ax \" 8/2 \" %06o \" \"\\n\"");
                        break;
                case 's':
-                       if ((skip = strtol(optarg, &p, 0)) < 0)
-                               err(EXIT_FAILURE, _("bad skip value"));
-                       switch(*p) {
-                       case 'b':
-                               skip *= 512;
-                               break;
-                       case 'k':
-                               skip *= 1024;
-                               break;
-                       case 'm':
-                               skip *= 1048576;
-                               break;
-                       }
+                       if (strtosize(optarg, &o))
+                               errx(EXIT_FAILURE,
+                                    _("invalid skip value '%s' specified"), optarg);
+                       skip = o;
                        break;
                case 'v':
                        vflag = ALL;