summaryrefslogtreecommitdiff
path: root/src/basic/parse-util.c
diff options
context:
space:
mode:
authorHristo Venev <hristo@venev.name>2015-11-16 10:15:05 +0200
committerHristo Venev <hristo@venev.name>2015-11-17 23:52:09 +0200
commit436dd70f5331ec541ebdd84e106abaa63203f6f1 (patch)
treeaeb12e97a49051979dce893fa1b92bed52ba1153 /src/basic/parse-util.c
parent92939fc4c0261dccd4b755186aba84a9b1412bed (diff)
calendarspec: sub-second support, v3
Diffstat (limited to 'src/basic/parse-util.c')
-rw-r--r--src/basic/parse-util.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c
index 151067e916..3ae99d9334 100644
--- a/src/basic/parse-util.c
+++ b/src/basic/parse-util.c
@@ -490,3 +490,39 @@ int safe_atod(const char *s, double *ret_d) {
*ret_d = (double) d;
return 0;
}
+
+int parse_fractional_part_u(const char **p, size_t digits, unsigned *res) {
+ size_t i;
+ unsigned val = 0;
+ const char *s;
+
+ s = *p;
+
+ /* accept any number of digits, strtoull is limted to 19 */
+ for(i=0; i < digits; i++,s++) {
+ if (*s < '0' || *s > '9') {
+ if (i == 0)
+ return -EINVAL;
+
+ /* too few digits, pad with 0 */
+ for (; i < digits; i++)
+ val *= 10;
+
+ break;
+ }
+
+ val *= 10;
+ val += *s - '0';
+ }
+
+ /* maybe round up */
+ if (*s >= '5' && *s <= '9')
+ val++;
+
+ s += strspn(s, DIGITS);
+
+ *p = s;
+ *res = val;
+
+ return 0;
+}