浏览代码

Basic MSC Compatibility (#4147)

MSC Compatibility (Native Compile on Windows)
motwok 6 年之前
父节点
当前提交
78a3f2475e
共有 2 个文件被更改,包括 18 次插入5 次删除
  1. 5 2
      src/borg/_endian.h
  2. 13 3
      src/borg/_hashindex.c

+ 5 - 2
src/borg/_endian.h

@@ -1,4 +1,6 @@
-#include <unistd.h>
+#if !defined(_MSC_VER)
+#   include <unistd.h>
+#endif
 #include <stdlib.h>
 #include <stdint.h>
 
@@ -12,7 +14,8 @@
 #define BORG_BIG_ENDIAN 1
 #elif (defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && (BYTE_ORDER == LITTLE_ENDIAN)) || \
       (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) || \
-      (defined(_LITTLE_ENDIAN) && defined(__SVR4) && defined(__sun))
+      (defined(_LITTLE_ENDIAN) && defined(__SVR4) && defined(__sun)) || \
+      (defined(_MSC_VER) && (defined(_M_AMD64) || defined(_M_IX86)))
 #define BORG_BIG_ENDIAN 0
 #else
 #error Unknown byte order

+ 13 - 3
src/borg/_hashindex.c

@@ -8,10 +8,18 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <unistd.h>
+#if !defined(_MSC_VER)
+#   include <unistd.h>
+#endif
 
 #include "_endian.h"
 
+#if defined(_MSC_VER)
+#   define BORG_PACKED(x) __pragma(pack(push, 1)) x __pragma(pack(pop))
+#else
+#   define BORG_PACKED(x) x __attribute__((packed))
+#endif
+
 #define MAGIC "BORG_IDX"
 #define MAGIC_LEN 8
 
@@ -25,13 +33,14 @@
     }                                           \
 } while (0)
 
+BORG_PACKED(
 typedef struct {
     char magic[MAGIC_LEN];
     int32_t num_entries;
     int32_t num_buckets;
     int8_t  key_size;
     int8_t  value_size;
-} __attribute__((__packed__)) HashHeader;
+}) HashHeader;
 
 typedef struct {
     unsigned char *buckets;
@@ -693,7 +702,8 @@ hashindex_size(HashIndex *index)
 /*
  * Used by the FuseVersionsIndex.
  */
+BORG_PACKED(
 typedef struct {
     uint32_t version;
     char hash[16];
-} __attribute__((__packed__)) FuseVersionsElement;
+} ) FuseVersionsElement;