From patchwork Mon Sep 27 06:42:28 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 65812 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9E8A6B70D6 for ; Mon, 27 Sep 2010 16:42:58 +1000 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1P07P9-0002jQ-B6; Mon, 27 Sep 2010 06:41:39 +0000 Received: from smtp.gentoo.org ([140.211.166.183]) by bombadil.infradead.org with esmtps (Exim 4.72 #1 (Red Hat Linux)) id 1P07P6-0002il-AG for linux-mtd@lists.infradead.org; Mon, 27 Sep 2010 06:41:38 +0000 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id D5E8B1B4091 for ; Mon, 27 Sep 2010 06:41:33 +0000 (UTC) From: Mike Frysinger To: linux-mtd@lists.infradead.org Subject: [PATCH v3] mtd-utils: new strtoX helpers Date: Mon, 27 Sep 2010 02:42:28 -0400 Message-Id: <1285569748-16152-1-git-send-email-vapier@gentoo.org> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1285394808-29795-1-git-send-email-vapier@gentoo.org> References: <1285394808-29795-1-git-send-email-vapier@gentoo.org> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20100927_024136_486699_9A67C308 X-CRM114-Status: GOOD ( 12.07 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.3.1 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [140.211.166.183 listed in list.dnswl.org] -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Simply usage of converting strings to numbers by adding some wrappers around the standard strtoX functions. These helpers simplify the api of these functions a bit by providing an optional "error" pointer and automatic error message. Signed-off-by: Mike Frysinger --- v3 - merge into common.h now that PROGRAM_NAME has been sorted out include/common.h | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-) diff --git a/include/common.h b/include/common.h index dce067b..472315e 100644 --- a/include/common.h +++ b/include/common.h @@ -20,6 +20,7 @@ #define __MTD_UTILS_COMMON_H__ #include +#include #include #include #include @@ -79,6 +80,29 @@ static inline int is_power_of_2(unsigned long long n) return (n != 0 && ((n & (n - 1)) == 0)); } +/** + * simple_strtoX - convert a hex/dec/oct string into a number + * @snum: buffer to convert + * @error: set to 1 when buffer isn't fully consumed + */ +#define simple_strtoX(func, type) \ +static inline type simple_##func(const char *snum, int *error) \ +{ \ + char *endptr; \ + type ret = func(snum, &endptr, 0); \ + \ + if (error && (!*snum || *endptr)) { \ + errmsg("%s: unable to parse the number '%s'", #func, snum); \ + *error = 1; \ + } \ + \ + return ret; \ +} +simple_strtoX(strtol, long int) +simple_strtoX(strtoll, long int) +simple_strtoX(strtoul, unsigned long int) +simple_strtoX(strtoull, unsigned long int) + #ifdef __cplusplus } #endif