]> wimlib.net Git - wimlib/commitdiff
wimlib.h: define timespec for MSVC compatibility
authorEric Biggers <ebiggers3@gmail.com>
Sun, 27 Nov 2016 23:24:36 +0000 (15:24 -0800)
committerEric Biggers <ebiggers3@gmail.com>
Mon, 28 Nov 2016 02:17:58 +0000 (18:17 -0800)
include/wimlib.h
src/iterate_dir.c

index 09bf1052331b0369fecf6de5b8711621e30c6760..5941b9ee856a970fa0eee7221b0b98212df933f6 100644 (file)
 extern "C" {
 #endif
 
+/*
+ * To represent file timestamps, wimlib's API uses the POSIX 'struct timespec'.
+ * This was probably a mistake because it doesn't play well with Visual Studio.
+ * In old VS versions it isn't present at all; in newer VS versions it is
+ * supposedly present, but I wouldn't trust it to be the same size as the one
+ * MinGW uses.  The solution is to define a compatible structure ourselves when
+ * this header is included on Windows and the compiler is not MinGW.
+ */
+#if defined(_WIN32) && !defined(__GNUC__)
+typedef struct {
+       /* Seconds since start of UNIX epoch (January 1, 1970) */
+#ifdef _WIN64
+       int64_t tv_sec;
+#else
+       int32_t tv_sec;
+#endif
+       /* Nanoseconds (0-999999999) */
+       int32_t tv_nsec;
+} wimlib_timespec;
+#else
+#  define wimlib_timespec  struct timespec  /* standard definition */
+#endif
+
 /**
  * Opaque structure that represents a WIM, possibly backed by an on-disk file.
  * See @ref sec_basic_wim_handling_concepts for more information.
@@ -1559,13 +1582,13 @@ struct wimlib_dir_entry {
        uint64_t hard_link_group_id;
 
        /** Time this file was created.  */
-       struct timespec creation_time;
+       wimlib_timespec creation_time;
 
        /** Time this file was last written to.  */
-       struct timespec last_write_time;
+       wimlib_timespec last_write_time;
 
        /** Time this file was last accessed.  */
-       struct timespec last_access_time;
+       wimlib_timespec last_access_time;
 
        /** The UNIX user ID of this file.  This is a wimlib extension.
         *
index 55d2a2a751a2a51dacea48111ea109133efdf180..e4eb87d7875d0c92dcbf02bdb064997df19f4240 100644 (file)
@@ -121,9 +121,19 @@ init_wimlib_dentry(struct wimlib_dir_entry *wdentry, struct wim_dentry *dentry,
        wdentry->num_links = inode->i_nlink;
        wdentry->attributes = inode->i_attributes;
        wdentry->hard_link_group_id = inode->i_ino;
+
+       /* For Windows builds, to maintain ABI compatibility with previous
+        * versions of the DLLs, double-check that we're using the expected size
+        * for 'struct timespec'. */
+#ifdef _WIN64
+       STATIC_ASSERT(sizeof(struct timespec) == 16);
+#elif defined(_WIN32)
+       STATIC_ASSERT(sizeof(struct timespec) == 8);
+#endif
        wdentry->creation_time = wim_timestamp_to_timespec(inode->i_creation_time);
        wdentry->last_write_time = wim_timestamp_to_timespec(inode->i_last_write_time);
        wdentry->last_access_time = wim_timestamp_to_timespec(inode->i_last_access_time);
+
        if (inode_get_unix_data(inode, &unix_data)) {
                wdentry->unix_uid = unix_data.uid;
                wdentry->unix_gid = unix_data.gid;