Mercurial > hg > toybox
comparison lib/lib.c @ 615:43489d673976
Add NOP b (byte) suffix to atolx() since od needs it.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 30 Jun 2012 16:31:37 -0500 |
parents | 90d6026c36c3 |
children | f51beec92738 |
comparison
equal
deleted
inserted
replaced
614:2b40588a3d25 | 615:43489d673976 |
---|---|
497 | 497 |
498 // atol() with the kilo/mega/giga/tera/peta/exa extensions. | 498 // atol() with the kilo/mega/giga/tera/peta/exa extensions. |
499 // (zetta and yotta don't fit in 64 bits.) | 499 // (zetta and yotta don't fit in 64 bits.) |
500 long atolx(char *numstr) | 500 long atolx(char *numstr) |
501 { | 501 { |
502 char *c, *suffixes="kmgtpe", *end; | 502 char *c, *suffixes="bkmgtpe", *end; |
503 long val = strtol(numstr, &c, 0); | 503 long val = strtol(numstr, &c, 0); |
504 | 504 |
505 if (*c) { | 505 if (*c) { |
506 end = strchr(suffixes, tolower(*c)); | 506 end = strchr(suffixes, tolower(*c)); |
507 if (end) val *= 1024L<<((end-suffixes)*10); | 507 if (end) { |
508 else { | 508 int shift = end-suffixes; |
509 if (shift--) val *= 1024L<<(shift*10); | |
510 } else { | |
509 while (isspace(*c)) c++; | 511 while (isspace(*c)) c++; |
510 if (*c) error_exit("not integer: %s", numstr); | 512 if (*c) error_exit("not integer: %s", numstr); |
511 } | 513 } |
512 } | 514 } |
513 | 515 |