aboutsummaryrefslogtreecommitdiffstats
path: root/fileset.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-10-22 03:18:06 -0700
committerGuy Harris <guy@alum.mit.edu>2016-10-22 10:18:47 +0000
commite80a8acbe3cb0d0bdefeff51292bd90c3461a02a (patch)
tree2861095d0ed2a49f5a5014d7780d2c2d5e9638e8 /fileset.c
parent5f68435a079dc7ce633e1da22f363e4e715d66f6 (diff)
Clean up conditional code for getting creation time.
Define a macro to get the creation time from a stat structure, or to return 0 if the creation time is unavailable, and use that in both places where we fetch the creation time. Change-Id: I15354f2d52a40cb1227f30ae274120575eec2055 Reviewed-on: https://code.wireshark.org/review/18387 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'fileset.c')
-rw-r--r--fileset.c45
1 files changed, 19 insertions, 26 deletions
diff --git a/fileset.c b/fileset.c
index 06cf335f9c..b2bda3bc68 100644
--- a/fileset.c
+++ b/fileset.c
@@ -49,6 +49,23 @@ typedef struct _fileset {
/* this is the fileset's global data */
static fileset set = { NULL, NULL};
+/*
+ * Given a stat structure, get the creation time of the file if available,
+ * or 0 if not.
+ */
+#ifdef _WIN32
+ /* Microsoft's documentation says this is the creation time */
+ #define ST_CREATE_TIME(statb) ((statb).st_ctime)
+#else /* _WIN32 */
+ /* UN*X - do we have a creation time? */
+ #if defined(HAVE_STRUCT_STAT_ST_BIRTHTIME)
+ #define ST_CREATE_TIME(statb) ((statb).st_birthtime)
+ #elif defined(HAVE_STRUCT_STAT___ST_BIRTHTIME)
+ #define ST_CREATE_TIME(statb) ((statb).__st_birthtime)
+ #else /* nothing */
+ #define ST_CREATE_TIME(statb) (0)
+ #endif /* creation time on UN*X */
+#endif /* _WIN32 */
/* is this a probable file of a file set (does the naming pattern match)? */
gboolean
@@ -186,19 +203,7 @@ fileset_update_file(const char *path)
if (entry_list) {
entry = (fileset_entry *) entry_list->data;
-#ifdef __WIN32
- /* Microsoft's documentation says this is the creation time */
- entry->ctime = buf.st_ctime;
-#else /* _WIN32 */
- /* UN*X - do we have a creation time? */
-#if defined(HAVE_STRUCT_STAT_ST_BIRTHTIME)
- entry->ctime = buf.st_birthtime;
-#elif defined(HAVE_STRUCT_STAT___ST_BIRTHTIME)
- entry->ctime = buf.__st_birthtime;
-#else /* nothing */
- entry->ctime = 0;
-#endif /* creation time on UN*X */
-#endif /* _WIN32 */
+ entry->ctime = ST_CREATE_TIME(buf);
entry->mtime = buf.st_mtime;
entry->size = buf.st_size;
}
@@ -232,19 +237,7 @@ fileset_add_file(const char *dirname, const char *fname, gboolean current)
entry->fullname = g_strdup(path);
entry->name = g_strdup(fname);
-#ifdef __WIN32
- /* Microsoft's documentation says this is the creation time */
- entry->ctime = buf.st_ctime;
-#else /* _WIN32 */
- /* UN*X - do we have a creation time? */
-#if defined(HAVE_STRUCT_STAT_ST_BIRTHTIME)
- entry->ctime = buf.st_birthtime;
-#elif defined(HAVE_STRUCT_STAT___ST_BIRTHTIME)
- entry->ctime = buf.__st_birthtime;
-#else /* nothing */
- entry->ctime = 0;
-#endif /* creation time on UN*X */
-#endif /* _WIN32 */
+ entry->ctime = ST_CREATE_TIME(buf);
entry->mtime = buf.st_mtime;
entry->size = buf.st_size;
entry->current = current;