From patchwork Fri Oct 5 23:25:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinicius Costa Gomes X-Patchwork-Id: 979828 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42Rm8y64MGz9s4s for ; Sat, 6 Oct 2018 09:26:10 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729267AbeJFG1F (ORCPT ); Sat, 6 Oct 2018 02:27:05 -0400 Received: from mga02.intel.com ([134.134.136.20]:39625 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726538AbeJFG0y (ORCPT ); Sat, 6 Oct 2018 02:26:54 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Oct 2018 16:25:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,346,1534834800"; d="scan'208";a="269915141" Received: from ellie.jf.intel.com (HELO localhost.localdomain) ([10.54.70.75]) by fmsmga006.fm.intel.com with ESMTP; 05 Oct 2018 16:25:33 -0700 From: Vinicius Costa Gomes To: netdev@vger.kernel.org Cc: Vinicius Costa Gomes , jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, jesus.sanchez-palencia@intel.com, ilias.apalodimas@linaro.org, simon.fok@baesystems.com Subject: [PATCH iproute2 net-next v3 1/6] utils: Implement get_s64() Date: Fri, 5 Oct 2018 16:25:17 -0700 Message-Id: <20181005232522.4848-2-vinicius.gomes@intel.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181005232522.4848-1-vinicius.gomes@intel.com> References: <20181005232522.4848-1-vinicius.gomes@intel.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add this helper to read signed 64-bit integers from a string. Signed-off-by: Vinicius Costa Gomes --- include/utils.h | 1 + lib/utils.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/utils.h b/include/utils.h index 8cb4349e..58574a05 100644 --- a/include/utils.h +++ b/include/utils.h @@ -139,6 +139,7 @@ int get_time_rtt(unsigned *val, const char *arg, int *raw); #define get_byte get_u8 #define get_ushort get_u16 #define get_short get_s16 +int get_s64(__s64 *val, const char *arg, int base); int get_u64(__u64 *val, const char *arg, int base); int get_u32(__u32 *val, const char *arg, int base); int get_s32(__s32 *val, const char *arg, int base); diff --git a/lib/utils.c b/lib/utils.c index e87ecf31..1b84b801 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -383,6 +383,27 @@ int get_u8(__u8 *val, const char *arg, int base) return 0; } +int get_s64(__s64 *val, const char *arg, int base) +{ + long res; + char *ptr; + + errno = 0; + + if (!arg || !*arg) + return -1; + res = strtoll(arg, &ptr, base); + if (!ptr || ptr == arg || *ptr) + return -1; + if ((res == LLONG_MIN || res == LLONG_MAX) && errno == ERANGE) + return -1; + if (res > INT64_MAX || res < INT64_MIN) + return -1; + + *val = res; + return 0; +} + int get_s32(__s32 *val, const char *arg, int base) { long res;