]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
MSVC: xz: Make file_io.c and file_io.h compatible with MSVC.
authorLasse Collin <lasse.collin@tukaani.org>
Tue, 5 Sep 2023 19:42:10 +0000 (22:42 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Fri, 22 Sep 2023 17:00:38 +0000 (20:00 +0300)
Thanks to Kelvin Lee for the original patches
and testing the modifications I made.

src/xz/file_io.c
src/xz/file_io.h

index 767c819a18817176db965a50436c1063c776f684..f0d895bc77ce0bc23474eff7bba1cef5994309d7 100644 (file)
@@ -39,6 +39,32 @@ static bool warn_fchown;
 
 #include "tuklib_open_stdxxx.h"
 
+#ifdef _MSC_VER
+#      ifdef _WIN64
+               typedef __int64 ssize_t;
+#      else
+               typedef int ssize_t;
+#      endif
+
+       typedef int mode_t;
+#      define S_IRUSR _S_IREAD
+#      define S_IWUSR _S_IWRITE
+
+#      define setmode _setmode
+#      define open _open
+#      define close _close
+#      define lseek _lseeki64
+#      define unlink _unlink
+
+       // The casts are to silence warnings.
+       // The sizes are known to be small enough.
+#      define read(fd, buf, size) _read(fd, buf, (unsigned int)(size))
+#      define write(fd, buf, size) _write(fd, buf, (unsigned int)(size))
+
+#      define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
+#      define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
+#endif
+
 #ifndef O_BINARY
 #      define O_BINARY 0
 #endif
index 6992efa4f86cc9079165ba523c6d9200ed51223c..906fd96079efb602ff098c725d6a8546926fee2f 100644 (file)
 #      define IO_BUFFER_SIZE (BUFSIZ & ~7U)
 #endif
 
+#ifdef _MSC_VER
+       // The first one renames both "struct stat" -> "struct _stat64"
+       // and stat() -> _stat64(). The documentation mentions only
+       // "struct __stat64", not "struct _stat64", but the latter
+       // works too.
+#      define stat _stat64
+#      define fstat _fstat64
+#      define off_t __int64
+#endif
+
 
 /// is_sparse() accesses the buffer as uint64_t for maximum speed.
 /// The u32 and u64 members must only be access through this union