aboutsummaryrefslogtreecommitdiffstats
path: root/epan/ftypes/ftype-time.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2001-05-31 06:20:10 +0000
committerGuy Harris <guy@alum.mit.edu>2001-05-31 06:20:10 +0000
commit15336e821c21b86ffa8a31d4049e25a6b2472987 (patch)
treeee46e3e412319d9e32d4996ab2987ef1b86a64eb /epan/ftypes/ftype-time.c
parent963de49427bfcbe7afd67d7bd4117682a5586ac1 (diff)
Don't require both the seconds and microseconds parts of a relative time
to be present - "1" is just as good as "1.0", and ".1" is just as good as "1.1". svn path=/trunk/; revision=3486
Diffstat (limited to 'epan/ftypes/ftype-time.c')
-rw-r--r--epan/ftypes/ftype-time.c55
1 files changed, 51 insertions, 4 deletions
diff --git a/epan/ftypes/ftype-time.c b/epan/ftypes/ftype-time.c
index 059a77d9cf..7dcaf23b97 100644
--- a/epan/ftypes/ftype-time.c
+++ b/epan/ftypes/ftype-time.c
@@ -1,5 +1,5 @@
/*
- * $Id: ftype-time.c,v 1.4 2001/05/31 05:01:06 guy Exp $
+ * $Id: ftype-time.c,v 1.5 2001/05/31 06:20:10 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -94,12 +94,59 @@ cmp_le(fvalue_t *a, fvalue_t *b)
static gboolean
relative_val_from_string(fvalue_t *fv, char *s, LogFunc log)
{
+ char *curptr, *endptr;
+
+ curptr = s;
+
+ /*
+ * If it doesn't begin with ".", it should contain a seconds
+ * value.
+ */
+ if (*curptr != '.') {
+ /*
+ * Get the seconds value.
+ */
+ fv->value.time.tv_sec = strtoul(curptr, &endptr, 10);
+ if (endptr == curptr || (*endptr != '\0' && *endptr != '.')) {
+ if (log != NULL)
+ log("\"%s\" is not a valid time.", s);
+ return FALSE;
+ }
+ curptr = endptr;
+ if (*curptr == '.')
+ curptr++; /* skip the decimal point */
+ } else {
+ /*
+ * No seconds value - it's 0.
+ */
+ fv->value.time.tv_sec = 0;
+ curptr++; /* skip the decimal point */
+ }
- if (sscanf(s,"%lu.%lu",&fv->value.time.tv_sec,&fv->value.time.tv_usec)!=2) {
- log("\"%s\" is not a valid relative time. Use \"<seconds>.<useconds>\"",s);
- return FALSE;
+ /*
+ * If there's more stuff left in the string, it should be the
+ * microseconds value.
+ */
+ if (*endptr != '\0') {
+ /*
+ * Get the microseconds value.
+ */
+ fv->value.time.tv_usec = strtoul(curptr, &endptr, 10);
+ if (endptr == curptr || *endptr != '\0') {
+ if (log != NULL)
+ log("\"%s\" is not a valid time.", s);
+ return FALSE;
+ }
+ } else {
+ /*
+ * No microseconds value - it's 0.
+ */
+ fv->value.time.tv_usec = 0;
}
+ /*
+ * XXX - what about negative values?
+ */
return TRUE;
}