commit: a9e81d3a107310775ac4d37b44bff45e61c442b6
parent 11eabcaa6061cbc016498037c576d9d52373a141
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Thu, 15 Aug 2024 21:42:12 +0200
lib/truncation: accept lowercase suffixes in apply_size_suffix
Diffstat:
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/truncation.c b/lib/truncation.c
@@ -6,6 +6,7 @@
#include "truncation.h"
#include <assert.h>
+#include <ctype.h> // toupper
#include <errno.h>
#include <stdio.h> // fprintf
#include <stdlib.h> // strtol
@@ -76,11 +77,12 @@ apply_size_suffix(long *size, char *endptr)
size_t i = 0;
long si = 1, iec = 1;
+ char pfx = toupper(endptr[0]);
for(; i < sizeof(units); i++)
{
si *= 1000;
iec *= 1024;
- if(units[i] == endptr[0]) break;
+ if(units[i] == pfx) break;
}
if(i >= sizeof(units) || si == 1)
{
diff --git a/test-cmd/head.t b/test-cmd/head.t
@@ -12,8 +12,8 @@
40
$ </dev/zero head -c 40K | wc -c
40960
- $ </dev/zero head -c 40k | wc -c
- head: Unrecognised unit 'k'
+ $ </dev/zero head -c 40d | wc -c
+ head: Unrecognised unit 'd'
0
[1]