All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vinicius Costa Gomes <vinicius.gomes@intel.com>
To: netdev@vger.kernel.org
Cc: Vinicius Costa Gomes <vinicius.gomes@intel.com>,
	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 v2 1/6] utils: Implement get_s64()
Date: Thu,  4 Oct 2018 16:17:06 -0700	[thread overview]
Message-ID: <20181004231711.6058-2-vinicius.gomes@intel.com> (raw)
In-Reply-To: <20181004231711.6058-1-vinicius.gomes@intel.com>

Add this helper to read signed 64-bit integers from a string.

Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
 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;
-- 
2.19.0

  reply	other threads:[~2018-10-05  6:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-04 23:17 [PATCH iproute2 net-next v2 0/6] Introduce the taprio scheduler Vinicius Costa Gomes
2018-10-04 23:17 ` Vinicius Costa Gomes [this message]
2018-10-04 23:17 ` [PATCH iproute2 net-next v2 2/6] include: Add helper to retrieve a __s64 from a netlink msg Vinicius Costa Gomes
2018-10-05  8:41   ` Ilias Apalodimas
2018-10-05 17:08     ` Vinicius Costa Gomes
2018-10-04 23:17 ` [PATCH iproute2 net-next v2 3/6] libnetlink: Add helper for getting a __s32 from netlink msgs Vinicius Costa Gomes
2018-10-04 23:17 ` [PATCH iproute2 net-next v2 4/6] include: add definitions for taprio [DO NOT COMMIT] Vinicius Costa Gomes
2018-10-04 23:17 ` [PATCH iproute2 net-next v2 5/6] tc: Add support for configuring the taprio scheduler Vinicius Costa Gomes
2018-10-04 23:17 ` [PATCH iproute2 net-next v2 6/6] taprio: Add manpage for tc-taprio(8) Vinicius Costa Gomes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181004231711.6058-2-vinicius.gomes@intel.com \
    --to=vinicius.gomes@intel.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jesus.sanchez-palencia@intel.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=netdev@vger.kernel.org \
    --cc=simon.fok@baesystems.com \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.