From patchwork Fri Aug 5 20:55:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 108735 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5BA1EB6F62 for ; Sat, 6 Aug 2011 06:56:57 +1000 (EST) Received: from localhost ([::1]:35943 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QpRRu-000399-I7 for incoming@patchwork.ozlabs.org; Fri, 05 Aug 2011 16:56:54 -0400 Received: from eggs.gnu.org ([140.186.70.92]:34547) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QpRRE-0000xb-7v for qemu-devel@nongnu.org; Fri, 05 Aug 2011 16:56:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QpRRD-000256-3z for qemu-devel@nongnu.org; Fri, 05 Aug 2011 16:56:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:17361) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QpRRC-00024w-O9 for qemu-devel@nongnu.org; Fri, 05 Aug 2011 16:56:11 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p75Ku9b6021641 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 5 Aug 2011 16:56:09 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p75Ku8ho013516; Fri, 5 Aug 2011 16:56:08 -0400 Received: from amt.cnet (vpn1-7-153.ams2.redhat.com [10.36.7.153]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p75Ku7Hk020590; Fri, 5 Aug 2011 16:56:07 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 925B9656101; Fri, 5 Aug 2011 17:55:48 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.5/8.14.5/Submit) id p75KtiPD023377; Fri, 5 Aug 2011 17:55:44 -0300 From: Marcelo Tosatti To: Anthony Liguori Date: Fri, 5 Aug 2011 17:55:28 -0300 Message-Id: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Joerg Roedel , Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH 3/6] qemu: Add strtosz_suffix_unit function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Joerg Roedel This function does the same as the strtosz_suffix function except that it allows to specify the unit to which the k/M/B/T suffixes apply. This function will be used later to parse the tsc-frequency from the command-line. Signed-off-by: Joerg Roedel Signed-off-by: Marcelo Tosatti --- cutils.c | 16 +++++++++++----- qemu-common.h | 2 ++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cutils.c b/cutils.c index f9a7e36..28049e0 100644 --- a/cutils.c +++ b/cutils.c @@ -322,7 +322,8 @@ int fcntl_setfl(int fd, int flag) * value must be terminated by whitespace, ',' or '\0'. Return -1 on * error. */ -int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) +int64_t strtosz_suffix_unit(const char *nptr, char **end, + const char default_suffix, int64_t unit) { int64_t retval = -1; char *endptr; @@ -362,20 +363,20 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) } break; case STRTOSZ_DEFSUFFIX_KB: - mul = 1 << 10; + mul = unit; break; case 0: if (mul_required) { goto fail; } case STRTOSZ_DEFSUFFIX_MB: - mul = 1ULL << 20; + mul = unit * unit; break; case STRTOSZ_DEFSUFFIX_GB: - mul = 1ULL << 30; + mul = unit * unit * unit; break; case STRTOSZ_DEFSUFFIX_TB: - mul = 1ULL << 40; + mul = unit * unit * unit * unit; break; default: goto fail; @@ -405,6 +406,11 @@ fail: return retval; } +int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) +{ + return strtosz_suffix_unit(nptr, end, default_suffix, 1024); +} + int64_t strtosz(const char *nptr, char **end) { return strtosz_suffix(nptr, end, STRTOSZ_DEFSUFFIX_MB); diff --git a/qemu-common.h b/qemu-common.h index afbd04d..389f4d2 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -157,6 +157,8 @@ int fcntl_setfl(int fd, int flag); #define STRTOSZ_DEFSUFFIX_B 'B' int64_t strtosz(const char *nptr, char **end); int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix); +int64_t strtosz_suffix_unit(const char *nptr, char **end, + const char default_suffix, int64_t unit); /* path.c */ void init_paths(const char *prefix);