All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/3] tst_test: add tst_parse_long()
@ 2016-12-19 13:36 Alexey Kodanev
  2016-12-19 13:36 ` [LTP] [PATCH 2/3] tst_test: add macro helper to invoke pthread_once() Alexey Kodanev
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Alexey Kodanev @ 2016-12-19 13:36 UTC (permalink / raw)
  To: ltp

Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
---
 include/tst_test.h |    1 +
 lib/tst_test.c     |   15 +++++++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/include/tst_test.h b/include/tst_test.h
index 1492ff5..3c77a98 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -96,6 +96,7 @@ struct tst_option {
  * On failure non-zero (errno) is returned.
  */
 int tst_parse_int(const char *str, int *val, int min, int max);
+int tst_parse_long(const char *str, long *val, long min, long max);
 int tst_parse_float(const char *str, float *val, float min, float max);
 
 struct tst_test {
diff --git a/lib/tst_test.c b/lib/tst_test.c
index c48d718..cd22bb4 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -446,6 +446,17 @@ static void parse_opts(int argc, char *argv[])
 int tst_parse_int(const char *str, int *val, int min, int max)
 {
 	long rval;
+
+	int ret = tst_parse_long(str, &rval, min, max);
+
+	*val = (int)rval;
+
+	return ret;
+}
+
+int tst_parse_long(const char *str, long *val, long min, long max)
+{
+	long rval;
 	char *end;
 
 	if (!str)
@@ -460,10 +471,10 @@ int tst_parse_int(const char *str, int *val, int min, int max)
 	if (errno)
 		return errno;
 
-	if (rval > (long)max || rval < (long)min)
+	if (rval > max || rval < min)
 		return ERANGE;
 
-	*val = (int)rval;
+	*val = rval;
 	return 0;
 }
 
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-01-30 13:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-19 13:36 [LTP] [PATCH 1/3] tst_test: add tst_parse_long() Alexey Kodanev
2016-12-19 13:36 ` [LTP] [PATCH 2/3] tst_test: add macro helper to invoke pthread_once() Alexey Kodanev
2017-01-23 14:58   ` Cyril Hrubis
2016-12-19 13:36 ` [LTP] [PATCH 3/3] netstress.c: convert to new library API Alexey Kodanev
2017-01-23 14:57   ` Cyril Hrubis
2017-01-27 14:07     ` Alexey Kodanev
2017-01-30 13:13       ` Cyril Hrubis
2017-01-30 13:32         ` Alexey Kodanev
2017-01-23 14:26 ` [LTP] [PATCH 1/3] tst_test: add tst_parse_long() Cyril Hrubis

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.