summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2001-12-19 10:35:39 +0000
committerJim Meyering <jim@meyering.net>2001-12-19 10:35:39 +0000
commit1cc94659adc4825d68892e2c7434eb1289a10560 (patch)
tree7d29a8c2e028bc5cc110a99d62201b97057bf40d /src
parent4ee49675d3db65a9f94b3db0cb5d53c6c9046373 (diff)
downloadcoreutils-1cc94659adc4825d68892e2c7434eb1289a10560.tar.xz
(xstrtoumax): If there is no number but there
is a valid suffix, assume 1. "MB" now means decimal, "MiB" binary. Accept 'K' as well as 'k'.
Diffstat (limited to 'src')
-rw-r--r--src/shred.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/shred.c b/src/shred.c
index 91ad58ea4..1a19b98bb 100644
--- a/src/shred.c
+++ b/src/shred.c
@@ -188,9 +188,14 @@ xstrtoumax (char const *ptr, char const **end, int base, uintmax_t *res,
*end = end_ptr;
if (errno)
return LONGINT_OVERFLOW;
- if (ptr == end_ptr)
- return LONGINT_INVALID;
c = *end_ptr;
+ if (ptr == end_ptr)
+ {
+ if (valid_suffixes && c && strchr (valid_suffixes, c))
+ n = 1;
+ else
+ return LONGINT_INVALID;
+ }
if (!c)
return LONGINT_OK;
/* Now deal with metric-style suffixes */
@@ -227,18 +232,19 @@ def:default:
if (!p)
return LONGINT_INVALID_SUFFIX_CHAR;
/*
- * If valid_suffixes contains '0', then xD (decimal) and xB (binary)
+ * If valid_suffixes contains '0', then B (decimal) and iB (binary)
* are allowed as "supersuffixes". Binary is the default.
*/
if (strchr (valid_suffixes, '0'))
{
- if (end_ptr[1] == 'B')
- end_ptr++;
- else if (end_ptr[1] == 'D')
+ /* 'D' is obsolescent */
+ if (end_ptr[1] == 'B' || end_ptr[1] == 'D')
{
decimal_flag = 1;
end_ptr++;
}
+ else if (end_ptr[1] == 'i' && end_ptr[2] == 'B')
+ end_ptr += 2;
}
/* Now do the scaling */
p++;
@@ -474,7 +480,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\
printf (_("\
-f, --force change permissions to allow writing if necessary\n\
-n, --iterations=N Overwrite N times instead of the default (%d)\n\
- -s, --size=N shred this many bytes (suffixes like k, M, G accepted)\n\
+ -s, --size=N shred this many bytes (suffixes like K, M, G accepted)\n\
"), DEFAULT_PASSES);
fputs (_("\
-u, --remove truncate and remove file after overwriting\n\
@@ -1838,7 +1844,7 @@ main (int argc, char **argv)
case 's':
{
uintmax_t tmp;
- if (xstrtoumax (optarg, NULL, 0, &tmp, "cbBkMGTPEZY0")
+ if (xstrtoumax (optarg, NULL, 0, &tmp, "cbBkKMGTPEZY0")
!= LONGINT_OK)
{
error (1, 0, _("%s: invalid file size"),