aboutsummaryrefslogtreecommitdiffstats
path: root/epan/ftypes/ftype-time.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2001-05-31 06:48:00 +0000
committerGuy Harris <guy@alum.mit.edu>2001-05-31 06:48:00 +0000
commit52025d69565657ebe1065c2ed74fe7811aee0dda (patch)
treeb6f6edbff0b1611ecee3c4fcd13e84a303469075 /epan/ftypes/ftype-time.c
parent15336e821c21b86ffa8a31d4049e25a6b2472987 (diff)
Display all the digits of the microsecond field of an absolute time
value. Check that the microseconds field of an absolute time is valid, if it's present. Set "tm_isdst" in the "struct tm" handed to "mktime()" to -1, so that "mktime()" will attempt to figure out whether the time is daylight savings time or not. Check that "mktime()" was able to convert the time. svn path=/trunk/; revision=3487
Diffstat (limited to 'epan/ftypes/ftype-time.c')
-rw-r--r--epan/ftypes/ftype-time.c78
1 files changed, 59 insertions, 19 deletions
diff --git a/epan/ftypes/ftype-time.c b/epan/ftypes/ftype-time.c
index 7dcaf23b97..156b59d68a 100644
--- a/epan/ftypes/ftype-time.c
+++ b/epan/ftypes/ftype-time.c
@@ -1,8 +1,8 @@
/*
- * $Id: ftype-time.c,v 1.5 2001/05/31 06:20:10 guy Exp $
+ * $Id: ftype-time.c,v 1.6 2001/05/31 06:48:00 guy Exp $
*
* Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
* Copyright 2001 Gerald Combs
*
*
@@ -25,6 +25,8 @@
#include "config.h"
#endif
+#include <ctype.h>
+
#include <time.h>
#include <ftypes-int.h>
@@ -107,11 +109,8 @@ relative_val_from_string(fvalue_t *fv, char *s, LogFunc log)
* 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;
- }
+ if (endptr == curptr || (*endptr != '\0' && *endptr != '.'))
+ goto fail;
curptr = endptr;
if (*curptr == '.')
curptr++; /* skip the decimal point */
@@ -132,11 +131,8 @@ relative_val_from_string(fvalue_t *fv, char *s, LogFunc log)
* 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;
- }
+ if (endptr == curptr || *endptr != '\0')
+ goto fail;
} else {
/*
* No microseconds value - it's 0.
@@ -148,6 +144,11 @@ relative_val_from_string(fvalue_t *fv, char *s, LogFunc log)
* XXX - what about negative values?
*/
return TRUE;
+
+fail:
+ if (log != NULL)
+ log("\"%s\" is not a valid time.", s);
+ return FALSE;
}
@@ -155,15 +156,54 @@ static gboolean
absolute_val_from_string(fvalue_t *fv, char *s, LogFunc log)
{
struct tm tm;
- char *str;
- str=strptime(s,"%b %d, %Y %H:%M:%S.",&tm);
- if (!str) {
- log("\"%s\" is not a valid absolute time. Example: \"Nov 12, 1999 08:55:44.123\"",s);
- return FALSE;
- }
+ char *curptr, *endptr;
+
+ curptr = strptime(s,"%b %d, %Y %H:%M:%S", &tm);
+ if (curptr == NULL)
+ goto fail;
+ tm.tm_isdst = -1; /* let the computer figure out if it's DST */
fv->value.time.tv_sec = mktime(&tm);
- sscanf(str,"%lu",&fv->value.time.tv_usec);
+ if (*curptr != '\0') {
+ /*
+ * Something came after the seconds field; it must be
+ * a microseconds field.
+ */
+ if (*curptr != '.')
+ goto fail; /* it's not */
+ curptr++; /* skip the "." */
+ if (!isdigit((unsigned char)*curptr))
+ goto fail; /* not a digit, so not valid */
+ fv->value.time.tv_usec = strtoul(curptr, &endptr, 10);
+ if (endptr == curptr || *endptr != '\0')
+ goto fail;
+ } else {
+ /*
+ * No microseconds value - it's 0.
+ */
+ fv->value.time.tv_usec = 0;
+ }
+
+ if (fv->value.time.tv_sec == -1) {
+ /*
+ * XXX - should we supply an error message that mentions
+ * that the time specified might be syntactically valid
+ * but might not actually have occurred, e.g. a time in
+ * the non-existent time range after the clocks are
+ * set forward during daylight savings time (or possibly
+ * that it's in the time range after the clocks are set
+ * backward, so that there are two different times that
+ * it could be)?
+ */
+ goto fail;
+ }
+
return TRUE;
+
+fail:
+ if (log != NULL)
+ log("\"%s\" is not a valid absolute time. Example: \"Nov 12, 1999 08:55:44.123\"",
+ s);
+ return FALSE;
}
static void