public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v2 1/3] tst_test: add tst_parse_long()
@ 2016-12-20 17:31 Alexey Kodanev
  2016-12-20 17:31 ` [LTP] [PATCH v2 2/3] tst_test: add macro helper to invoke pthread_once() Alexey Kodanev
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Alexey Kodanev @ 2016-12-20 17:31 UTC (permalink / raw)
  To: ltp

Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
---
v2: Fixes in tst_parse_int():
    * return back checking 'str' for NULL
    * set value in tst_parse_int() only if 'long' version returns 0.

 include/tst_test.h |    1 +
 lib/tst_test.c     |   20 ++++++++++++++++++--
 2 files changed, 19 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..3e7f9a0 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -446,6 +446,22 @@ static void parse_opts(int argc, char *argv[])
 int tst_parse_int(const char *str, int *val, int min, int max)
 {
 	long rval;
+
+	if (!str)
+		return 0;
+
+	int ret = tst_parse_long(str, &rval, min, max);
+
+	if (ret)
+		return ret;
+
+	*val = (int)rval;
+	return 0;
+}
+
+int tst_parse_long(const char *str, long *val, long min, long max)
+{
+	long rval;
 	char *end;
 
 	if (!str)
@@ -460,10 +476,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] 5+ messages in thread

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

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-20 17:31 [LTP] [PATCH v2 1/3] tst_test: add tst_parse_long() Alexey Kodanev
2016-12-20 17:31 ` [LTP] [PATCH v2 2/3] tst_test: add macro helper to invoke pthread_once() Alexey Kodanev
2016-12-20 17:31 ` [LTP] [PATCH v2 3/3] netstress.c: convert to new library API Alexey Kodanev
2017-01-23 15:02 ` [LTP] [PATCH v2 1/3] tst_test: add tst_parse_long() Cyril Hrubis
2017-01-25 13:34   ` Alexey Kodanev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox