On Thu, Mar 25, 2010 at 11:39 AM, Américo Wang <xiyou.wangcong@xxxxxxxxx> wrote: > On Thu, Mar 25, 2010 at 11:17 AM, Liu Aleaxander <aleaxander@xxxxxxxxx> wrote: >> Hi Yann, >> >> On Thu, Mar 25, 2010 at 5:05 AM, Yann Droneaud <yann@xxxxxxxxxxx> wrote: >>> >>> Le mercredi 24 mars 2010 à 14:38 +0800, Liu Aleaxander a écrit : >>> >>> > + if (offset) { >>> > + int ret = 0; >>> > + if (offset[0] == '0' && offset[1] == 'x') >>> > + ret = sscanf(offset, "%llx", &off); >>> > + else >>> > + ret = sscanf(offset, "%llu", &off); >>> > + if (ret != 1) >>> > + usage(); >>> > + } >>> > >>> >>> Why not using strtoull(), which handle decimal, hexadecimal and octal >>> for free ? >>> >> >> Thanks for your good point. But I found that the strtoull can't >> recognize the difference between non-digit case and zero number >> case, since it will both returns 0. > > This is exactly why you should check the second value-result parameter > of strtoul(). > Hi Américo, Thanks for your advice. Here is the new patch. --------- >From 78407cf1e1382b564bd0cc9df169accbfb1de7a0 Mon Sep 17 00:00:00 2001 From: Liu Aleaxander <Aleaxander@xxxxxxxxx> Date: Thu, 25 Mar 2010 13:11:56 +0800 Subject: [PATCH] mount: make the --offset option support hex number Sometimes the hex number makes more sense. Version 2, use the strtoull to handle the hex number case. Signed-off-by: Liu Aleaxander <Aleaxander@xxxxxxxxx> --- mount/lomount.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mount/lomount.c b/mount/lomount.c index 67712c6..8ee7fad 100644 --- a/mount/lomount.c +++ b/mount/lomount.c @@ -1015,8 +1015,14 @@ main(int argc, char **argv) { usage(); } - if (offset && sscanf(offset, "%llu", &off) != 1) - usage(); + if (offset) { + char *end; + off = strtoull(offset, &end, 0); + if (*end) { + fprintf(stderr, _("%s is not a valid number\n"), offset); + return -1; + } + } if (sizelimit && sscanf(sizelimit, "%llu", &slimit) != 1) usage(); -- 1.6.0.2 -- regards Liu Aleaxander -- To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html