[libgsf] GsfTimestamp: clean up.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Subject: [libgsf] GsfTimestamp: clean up.
- Date: Wed, 17 Jun 2009 20:35:31 -0400 (EDT)
commit d4b825c33fb7e1acafded332fc0d12e0be1cdf15
Author: Morten Welinder <terra gnome org>
Date: Wed Jun 17 20:34:58 2009 -0400
GsfTimestamp: clean up.
ChangeLog | 10 ++++++++++
NEWS | 1 +
gsf/gsf-libxml.c | 10 ++++++----
gsf/gsf-msole-utils.c | 9 ++++++---
gsf/gsf-timestamp.c | 24 ++++++++++++++++++++++--
gsf/gsf-timestamp.h | 4 ++++
6 files changed, 49 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9174816..9d1345f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-06-17 Morten Welinder <terra gnome org>
+
+ * gsf/gsf-msole-utils.c (msole_prop_parse): Use gsf_timestamp_new
+ and gsf_timestamp_set_time.
+
+ * gsf/gsf-timestamp.c (gsf_timestamp_from_string): Improve error
+ checking.
+ (gsf_timestamp_set_time): New function.
+ (gsf_timestamp_new): New function.
+
2009-06-05 Morten Welinder <terra gnome org>
* gsf/gsf-msole-utils.c (msole_prop_parse): If parsing fails,
diff --git a/NEWS b/NEWS
index 4d4f609..84f5610 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ Andreas:
Morten:
* Fix criticals when parsing bogus OLE properties. [#584848]
+ * Start cleaning up timestamp code.
--------------------------------------------------------------------------
libgsf 1.14.14
diff --git a/gsf/gsf-libxml.c b/gsf/gsf-libxml.c
index 79fa159..2c90818 100644
--- a/gsf/gsf-libxml.c
+++ b/gsf/gsf-libxml.c
@@ -258,11 +258,13 @@ gsf_xml_gvalue_from_str (GValue *res, GType t, char const *str)
default:
if (GSF_TIMESTAMP_TYPE == t) {
- GsfTimestamp ts;
- if (gsf_timestamp_from_string (str, &ts)) {
- gsf_value_set_timestamp (res, &ts);
+ GsfTimestamp *ts = gsf_timestamp_new ();
+ gboolean ok = gsf_timestamp_from_string (str, ts);
+ if (ok)
+ gsf_value_set_timestamp (res, ts);
+ gsf_timestamp_free (ts);
+ if (ok)
break;
- }
} else g_warning ("gsf_xml_gvalue_from_str(): Don't know how to handle type '%s'", g_type_name (t));
return FALSE;
diff --git a/gsf/gsf-msole-utils.c b/gsf/gsf-msole-utils.c
index 83cc8b9..21f9aef 100644
--- a/gsf/gsf-msole-utils.c
+++ b/gsf/gsf-msole-utils.c
@@ -774,7 +774,7 @@ msole_prop_parse (GsfMSOleMetaDataSection *section,
case VT_FILETIME : {
/* 64-bit FILETIME structure, as defined by Win32. */
guint64 ft;
- GsfTimestamp ts;
+ GsfTimestamp *ts;
NEED_BYTES (8);
@@ -783,9 +783,12 @@ msole_prop_parse (GsfMSOleMetaDataSection *section,
ft /= 10000000; /* convert to seconds */
ft -= G_GINT64_CONSTANT (11644473600); /* move to Jan 1 1970 */
- ts.timet = (time_t)ft;
+ ts = gsf_timestamp_new ();
+ gsf_timestamp_set_time (ts, ft);
g_value_init (res, GSF_TIMESTAMP_TYPE);
- gsf_value_set_timestamp (res, &ts);
+ gsf_value_set_timestamp (res, ts);
+ gsf_timestamp_free (ts);
+
ADVANCE;
break;
}
diff --git a/gsf/gsf-timestamp.c b/gsf/gsf-timestamp.c
index c4d741c..f9dc081 100644
--- a/gsf/gsf-timestamp.c
+++ b/gsf/gsf-timestamp.c
@@ -51,6 +51,14 @@ gsf_timestamp_get_type (void)
return our_type;
}
+GsfTimestamp *
+gsf_timestamp_new (void)
+{
+ GsfTimestamp *res = g_new0 (GsfTimestamp, 1);
+ res->timet = -1;
+ return res;
+}
+
/**
* gsf_timestamp_copy:
* @stamp: timestamp to be copied
@@ -62,7 +70,7 @@ gsf_timestamp_get_type (void)
GsfTimestamp *
gsf_timestamp_copy (GsfTimestamp const *stamp)
{
- GsfTimestamp *res = g_new0 (GsfTimestamp, 1);
+ GsfTimestamp *res = gsf_timestamp_new ();
res->timet = stamp->timet;
return res;
}
@@ -134,13 +142,19 @@ gsf_timestamp_from_string (char const *spec, GsfTimestamp *stamp)
if (6 == sscanf (spec, "%d-%d-%dT%d:%d:%d",
&tm.tm_year, &tm.tm_mon, &tm.tm_mday,
&tm.tm_hour, &tm.tm_min, &tm.tm_sec)) {
+ time_t t;
+
tm.tm_mon--; /* 0..11 */
/* err on the side of avoiding negatives */
if (tm.tm_year >= 1900)
tm.tm_year -= 1900;
- stamp->timet = mktime (&tm) + GMTOFF(tm);
+ t = mktime (&tm);
+ if (t == -1)
+ return FALSE;
+
+ stamp->timet = t + GMTOFF(tm);
return TRUE;
}
return FALSE;
@@ -224,3 +238,9 @@ gsf_value_set_timestamp (GValue *value, GsfTimestamp const *stamp)
{
g_value_set_boxed (value, stamp);
}
+
+void
+gsf_timestamp_set_time (GsfTimestamp *stamp, guint64 t)
+{
+ stamp->timet = t;
+}
diff --git a/gsf/gsf-timestamp.h b/gsf/gsf-timestamp.h
index 527bfb0..060e0e6 100644
--- a/gsf/gsf-timestamp.h
+++ b/gsf/gsf-timestamp.h
@@ -42,6 +42,8 @@ struct _GsfTimestamp {
GType gsf_timestamp_get_type (void) G_GNUC_CONST;
/* void gsf_timestamp_register_type (GTypeModule *module); glib dynamic types are not thread safe */
+GsfTimestamp *gsf_timestamp_new (void);
+
GsfTimestamp *gsf_timestamp_copy (GsfTimestamp const *stamp);
void gsf_timestamp_free (GsfTimestamp *stamp);
int gsf_timestamp_from_string (char const *spec, GsfTimestamp *stamp);
@@ -50,6 +52,8 @@ guint gsf_timestamp_hash (GsfTimestamp const *stamp);
gboolean gsf_timestamp_equal (GsfTimestamp const *a,
GsfTimestamp const *b);
+void gsf_timestamp_set_time (GsfTimestamp *stamp, guint64 t);
+
void gsf_value_set_timestamp (GValue *value, GsfTimestamp const *stamp);
/* Deprecated */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]