[hackers] [sbase][PATCH] sleep: Support omitted 0 before ., and . without trailing digits.

From: Mattias Andrée <maandree_AT_kth.se>
Date: Sat, 26 Mar 2016 19:02:23 +0100

That is, you can write for example .1 instead of 0.1,
or 1. instead of 1.0. The parsing is not strict, so can
also type . instead of 0.

Signed-off-by: Mattias Andrée <maandree_AT_kth.se>
---
 sleep.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/sleep.c b/sleep.c
index 693ce88..ccf90a4 100644
--- a/sleep.c
+++ b/sleep.c
_AT_@ -31,17 +31,19 @@ strtotime(char *str, struct timespec *ts)
 	c = *suf;
 	*suf = *p = '\0';
 
-	ts->tv_sec = estrtonum(str, 0, TIME_MAX);
+	ts->tv_sec = 0;
+	ts->tv_nsec = 0;
 
-	if (p++ != suf) {
+	if (isdigit(*str))
+		ts->tv_sec = estrtonum(str, 0, TIME_MAX);
+
+	if (p++ != suf && isdigit(*p)) {
 		n = strlen(p);
 		n = n < 9 ? n : 9;
 		memcpy(buf, p, n);
 		memset(buf + n, '0', 9 - n);
 		buf[9] = '\0';
 		ts->tv_nsec = estrtonum(buf, 0, 999999999L);
-	} else {
-		ts->tv_nsec = 0;
 	}
 
 	*suf = c;
-- 
2.7.3
Received on Sat Mar 26 2016 - 19:02:23 CET

This archive was generated by hypermail 2.3.0 : Sat Mar 26 2016 - 19:12:14 CET