[libgsf] GsfInputMemory: handle modtime.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgsf] GsfInputMemory: handle modtime.
- Date: Fri, 23 Mar 2018 02:23:31 +0000 (UTC)
commit 8b2ec68bd2e77f45dc79f15a1c7600360ded1c4d
Author: Morten Welinder <terra gnome org>
Date: Thu Mar 22 22:23:01 2018 -0400
GsfInputMemory: handle modtime.
ChangeLog | 10 ++++++++++
NEWS | 3 +++
gsf/gsf-input-impl.h | 4 ++++
gsf/gsf-input-memory.c | 1 +
gsf/gsf-input-stdio.c | 18 +-----------------
gsf/gsf-input.c | 27 +++++++++++++++++++++++++++
6 files changed, 46 insertions(+), 17 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 63af9d0..e10ba9d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2018-03-22 Morten Welinder <terra gnome org>
+
+ * gsf/gsf-input-memory.c (gsf_input_mmap_new): Set modtime.
+
+ * gsf/gsf-input-stdio.c (gsf_input_stdio_new): Use
+ gsf_input_set_modtime_from_stat.
+
+ * gsf/gsf-input.c (gsf_input_set_modtime_from_stat): New internal
+ function.
+
2017-11-11 Morten Welinder <terra gnome org>
* configure.ac: Post-release bump.
diff --git a/NEWS b/NEWS
index 41765e6..2a2a6ac 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
libgsf 1.14.43
+Morten:
+ * Handle modtime for memory mapped files.
+
--------------------------------------------------------------------------
libgsf 1.14.42
diff --git a/gsf/gsf-input-impl.h b/gsf/gsf-input-impl.h
index 35a7473..f33f405 100644
--- a/gsf/gsf-input-impl.h
+++ b/gsf/gsf-input-impl.h
@@ -63,6 +63,10 @@ gboolean gsf_input_set_size (GsfInput *input, gsf_off_t size);
gboolean gsf_input_set_modtime (GsfInput *input, GDateTime *modtime);
gboolean gsf_input_seek_emulate (GsfInput *input, gsf_off_t pos);
+struct stat;
+gboolean gsf_input_set_modtime_from_stat (GsfInput *input,
+ const struct stat *st);
+
G_END_DECLS
#endif /* GSF_INPUT_IMPL_H */
diff --git a/gsf/gsf-input-memory.c b/gsf/gsf-input-memory.c
index 7b4479f..351cfc0 100644
--- a/gsf/gsf-input-memory.c
+++ b/gsf/gsf-input-memory.c
@@ -272,6 +272,7 @@ gsf_input_mmap_new (char const *filename, GError **err)
mem->shared = gsf_shared_memory_mmapped_new (buf, (gsf_off_t) size);
gsf_input_set_size (GSF_INPUT (mem), (gsf_off_t) size);
gsf_input_set_name (GSF_INPUT (mem), filename);
+ gsf_input_set_modtime_from_stat (GSF_INPUT (mem), &st);
close (fd);
diff --git a/gsf/gsf-input-stdio.c b/gsf/gsf-input-stdio.c
index 783fe75..16172de 100644
--- a/gsf/gsf-input-stdio.c
+++ b/gsf/gsf-input-stdio.c
@@ -148,23 +148,7 @@ gsf_input_stdio_new (char const *filename, GError **err)
input->keep_open = FALSE;
gsf_input_set_size (GSF_INPUT (input), size);
gsf_input_set_name_from_filename (GSF_INPUT (input), filename);
- if (st.st_mtime != (time_t)-1) {
- GDateTime *modtime;
- GTimeVal tv;
-
- tv.tv_sec = st.st_mtime;
-#if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC)
- tv.tv_usec = st.st_mtimensec / 1000;
-#elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
- tv.tv_usec = st.st_mtim.tv_nsec / 1000;
-#else
- tv.tv_usec = 0;
-#endif
-
- modtime = g_date_time_new_from_timeval_utc (&tv);
- gsf_input_set_modtime (GSF_INPUT (input), modtime);
- g_date_time_unref (modtime);
- }
+ gsf_input_set_modtime_from_stat (GSF_INPUT (input), &st);
return GSF_INPUT (input);
}
diff --git a/gsf/gsf-input.c b/gsf/gsf-input.c
index f9b777d..14de590 100644
--- a/gsf/gsf-input.c
+++ b/gsf/gsf-input.c
@@ -25,6 +25,7 @@
#include <glib/gi18n-lib.h>
#include <string.h>
+#include <sys/stat.h>
/*
@@ -627,6 +628,32 @@ gsf_input_set_modtime (GsfInput *input, GDateTime *modtime)
return TRUE;
}
+gboolean
+gsf_input_set_modtime_from_stat (GsfInput *input,
+ const struct stat *st)
+{
+ GDateTime *modtime;
+ GTimeVal tv;
+ gboolean res;
+
+ if (st->st_mtime == (time_t)-1)
+ return FALSE;
+
+ tv.tv_sec = st->st_mtime;
+#if defined (HAVE_STRUCT_STAT_ST_MTIMENSEC)
+ tv.tv_usec = st->st_mtimensec / 1000;
+#elif defined (HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
+ tv.tv_usec = st->st_mtim.tv_nsec / 1000;
+#else
+ tv.tv_usec = 0;
+#endif
+
+ modtime = g_date_time_new_from_timeval_utc (&tv);
+ res = gsf_input_set_modtime (GSF_INPUT (input), modtime);
+ g_date_time_unref (modtime);
+
+ return res;
+}
/****************************************************************************/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]