aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/compat.h95
-rw-r--r--include/fstree.h3
-rw-r--r--include/highlevel.h3
-rw-r--r--include/sqfs/predef.h1
-rw-r--r--include/tar.h1
-rw-r--r--include/util.h3
-rw-r--r--lib/fstree/fstree_from_dir.c1
-rw-r--r--lib/fstree/fstree_from_file.c2
-rw-r--r--lib/sqfs/dir_writer.c2
-rw-r--r--lib/sqfs/id_table.c1
-rw-r--r--lib/sqfs/read_inode.c1
-rw-r--r--lib/sqfs/read_super.c1
-rw-r--r--lib/sqfs/read_table.c1
-rw-r--r--lib/sqfs/readdir.c1
-rw-r--r--lib/sqfs/super.c1
-rw-r--r--lib/sqfs/write_inode.c1
-rw-r--r--lib/sqfs/write_table.c1
-rw-r--r--lib/sqfshelper/tree_node_to_inode.c1
-rw-r--r--lib/tar/internal.h1
-rw-r--r--lib/util/Makemodule.am2
-rw-r--r--lib/util/dirstack.c2
-rw-r--r--lib/util/mkdir_p.c2
-rw-r--r--tar/tar2sqfs.c1
-rw-r--r--tests/fstree_from_file.c1
-rw-r--r--unpack/rdsquashfs.h4
25 files changed, 103 insertions, 30 deletions
diff --git a/include/compat.h b/include/compat.h
new file mode 100644
index 0000000..74d0b6f
--- /dev/null
+++ b/include/compat.h
@@ -0,0 +1,95 @@
+/* SPDX-License-Identifier: LGPL-3.0-or-later */
+/*
+ * util.h
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#ifndef COMPAT_H
+#define COMPAT_H
+
+#if defined(__APPLE__)
+#include <libkern/OSByteOrder.h>
+
+#define htole16(x) OSSwapHostToLittleInt16(x)
+#define htole32(x) OSSwapHostToLittleInt32(x)
+#define htole64(x) OSSwapHostToLittleInt64(x)
+
+#define le32toh(x) OSSwapLittleToHostInt32(x)
+#define le16toh(x) OSSwapLittleToHostInt16(x)
+#define le64toh(x) OSSwapLittleToHostInt64(x)
+#elif defined(__OpenBSD__)
+#include <sys/endian.h>
+#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
+#include <sys/endian.h>
+
+#define le16toh(x) letoh16(x)
+#define le32toh(x) letoh32(x)
+#define le64toh(x) letoh64(x)
+#elif defined(_WIN32) || defined(__WINDOWS__)
+#define htole16(x) (x)
+#define htole32(x) (x)
+#define htole64(x) (x)
+
+#define le16toh(x) (x)
+#define le32toh(x) (x)
+#define le64toh(x) (x)
+#else
+#include <endian.h>
+#endif
+
+#if defined(_WIN32) || defined(__WINDOWS__)
+#define S_IFSOCK SQFS_INODE_MODE_SOCK
+#define S_IFLNK SQFS_INODE_MODE_LNK
+#define S_IFREG SQFS_INODE_MODE_REG
+#define S_IFBLK SQFS_INODE_MODE_BLK
+#define S_IFDIR SQFS_INODE_MODE_DIR
+#define S_IFCHR SQFS_INODE_MODE_CHR
+#define S_IFIFO SQFS_INODE_MODE_FIFO
+#define S_IFMT SQFS_INODE_MODE_MASK
+
+#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
+#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
+#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
+#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
+#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
+#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
+#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
+
+#define S_ISUID SQFS_INODE_SET_UID
+#define S_ISGID SQFS_INODE_SET_GID
+#define S_ISVTX SQFS_INODE_STICKY
+
+#define S_IRWXU SQFS_INODE_OWNER_MASK
+#define S_IRUSR SQFS_INODE_OWNER_R
+#define S_IWUSR SQFS_INODE_OWNER_W
+#define S_IXUSR SQFS_INODE_OWNER_X
+
+#define S_IRWXG SQFS_INODE_GROUP_MASK
+#define S_IRGRP SQFS_INODE_GROUP_R
+#define S_IWGRP SQFS_INODE_GROUP_W
+#define S_IXGRP SQFS_INODE_GROUP_X
+
+#define S_IRWXO SQFS_INODE_OTHERS_MASK
+#define S_IROTH SQFS_INODE_OTHERS_R
+#define S_IWOTH SQFS_INODE_OTHERS_W
+#define S_IXOTH SQFS_INODE_OTHERS_X
+
+/* lifted from musl libc */
+#define major(x) \
+ ((unsigned)( (((x)>>31>>1) & 0xfffff000) | (((x)>>8) & 0x00000fff) ))
+
+#define minor(x) \
+ ((unsigned)( (((x)>>12) & 0xffffff00) | ((x) & 0x000000ff) ))
+
+#define makedev(x,y) ( \
+ (((x)&0xfffff000ULL) << 32) | \
+ (((x)&0x00000fffULL) << 8) | \
+ (((y)&0xffffff00ULL) << 12) | \
+ (((y)&0x000000ffULL)) )
+#else
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+#endif
+
+#endif /* COMPAT_H */
diff --git a/include/fstree.h b/include/fstree.h
index dbd2cd6..337b598 100644
--- a/include/fstree.h
+++ b/include/fstree.h
@@ -9,14 +9,13 @@
#include "config.h"
-#include <sys/types.h>
-#include <sys/stat.h>
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include "str_table.h"
+#include "compat.h"
#define FSTREE_XATTR_KEY_BUCKETS 31
#define FSTREE_XATTR_VALUE_BUCKETS 511
diff --git a/include/highlevel.h b/include/highlevel.h
index 13c85a7..6e4ad5e 100644
--- a/include/highlevel.h
+++ b/include/highlevel.h
@@ -22,12 +22,11 @@
#include "sqfs/xattr.h"
#include "sqfs/dir.h"
#include "sqfs/io.h"
+#include "compat.h"
#include "fstree.h"
#include "util.h"
#include "tar.h"
-#include <sys/stat.h>
-#include <stdint.h>
#include <stddef.h>
typedef struct {
diff --git a/include/sqfs/predef.h b/include/sqfs/predef.h
index 2e835f3..13e49f3 100644
--- a/include/sqfs/predef.h
+++ b/include/sqfs/predef.h
@@ -27,7 +27,6 @@
* macros and integer types.
*/
-#include <sys/types.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
diff --git a/include/tar.h b/include/tar.h
index d4e72ec..d0a483c 100644
--- a/include/tar.h
+++ b/include/tar.h
@@ -10,7 +10,6 @@
#include "config.h"
#include "util.h"
-#include <sys/stat.h>
#include <stdbool.h>
#include <stdint.h>
diff --git a/include/util.h b/include/util.h
index 61754ed..e7bc431 100644
--- a/include/util.h
+++ b/include/util.h
@@ -10,10 +10,11 @@
#include "config.h"
#include "sqfs/predef.h"
-#include <sys/types.h>
#include <stdint.h>
#include <stddef.h>
+#include "compat.h"
+
#if defined(__GNUC__) || defined(__clang__)
#define UI_ADD_OV __builtin_uadd_overflow
#define UL_ADD_OV __builtin_uaddl_overflow
diff --git a/lib/fstree/fstree_from_dir.c b/lib/fstree/fstree_from_dir.c
index c31b1a0..d68fafa 100644
--- a/lib/fstree/fstree_from_dir.c
+++ b/lib/fstree/fstree_from_dir.c
@@ -9,7 +9,6 @@
#include "fstree.h"
#include "util.h"
-#include <sys/types.h>
#ifdef HAVE_SYS_XATTR_H
#include <sys/xattr.h>
#endif
diff --git a/lib/fstree/fstree_from_file.c b/lib/fstree/fstree_from_file.c
index 619e83f..ec2f941 100644
--- a/lib/fstree/fstree_from_file.c
+++ b/lib/fstree/fstree_from_file.c
@@ -9,8 +9,6 @@
#include "fstree.h"
#include "util.h"
-#include <sys/sysmacros.h>
-#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
diff --git a/lib/sqfs/dir_writer.c b/lib/sqfs/dir_writer.c
index 2efc10d..3598dd2 100644
--- a/lib/sqfs/dir_writer.c
+++ b/lib/sqfs/dir_writer.c
@@ -15,8 +15,6 @@
#include "sqfs/dir.h"
#include "util.h"
-#include <sys/stat.h>
-#include <endian.h>
#include <stdlib.h>
#include <string.h>
diff --git a/lib/sqfs/id_table.c b/lib/sqfs/id_table.c
index 78a5d26..a320eca 100644
--- a/lib/sqfs/id_table.c
+++ b/lib/sqfs/id_table.c
@@ -11,6 +11,7 @@
#include "sqfs/super.h"
#include "sqfs/table.h"
#include "sqfs/error.h"
+#include "compat.h"
#include <stdlib.h>
#include <string.h>
diff --git a/lib/sqfs/read_inode.c b/lib/sqfs/read_inode.c
index 1916c96..51662eb 100644
--- a/lib/sqfs/read_inode.c
+++ b/lib/sqfs/read_inode.c
@@ -13,7 +13,6 @@
#include "sqfs/inode.h"
#include "util.h"
-#include <sys/stat.h>
#include <stdlib.h>
#include <errno.h>
diff --git a/lib/sqfs/read_super.c b/lib/sqfs/read_super.c
index b2f363a..6ac2ac4 100644
--- a/lib/sqfs/read_super.c
+++ b/lib/sqfs/read_super.c
@@ -12,7 +12,6 @@
#include "sqfs/io.h"
#include "util.h"
-#include <endian.h>
#include <string.h>
int sqfs_super_read(sqfs_super_t *super, sqfs_file_t *file)
diff --git a/lib/sqfs/read_table.c b/lib/sqfs/read_table.c
index 4c5a5cc..096ac1a 100644
--- a/lib/sqfs/read_table.c
+++ b/lib/sqfs/read_table.c
@@ -14,7 +14,6 @@
#include "sqfs/io.h"
#include "util.h"
-#include <endian.h>
#include <stdlib.h>
int sqfs_read_table(sqfs_file_t *file, sqfs_compressor_t *cmp,
diff --git a/lib/sqfs/readdir.c b/lib/sqfs/readdir.c
index 6b549b7..8899475 100644
--- a/lib/sqfs/readdir.c
+++ b/lib/sqfs/readdir.c
@@ -10,6 +10,7 @@
#include "sqfs/meta_reader.h"
#include "sqfs/error.h"
#include "sqfs/dir.h"
+#include "compat.h"
#include <stdlib.h>
#include <string.h>
diff --git a/lib/sqfs/super.c b/lib/sqfs/super.c
index 5cd5a87..8e39b55 100644
--- a/lib/sqfs/super.c
+++ b/lib/sqfs/super.c
@@ -12,7 +12,6 @@
#include "sqfs/io.h"
#include "util.h"
-#include <endian.h>
#include <string.h>
#include <unistd.h>
diff --git a/lib/sqfs/write_inode.c b/lib/sqfs/write_inode.c
index b16ef65..debaa00 100644
--- a/lib/sqfs/write_inode.c
+++ b/lib/sqfs/write_inode.c
@@ -10,6 +10,7 @@
#include "sqfs/meta_writer.h"
#include "sqfs/error.h"
#include "sqfs/inode.h"
+#include "compat.h"
static int write_block_sizes(sqfs_meta_writer_t *ir,
const sqfs_inode_generic_t *n)
diff --git a/lib/sqfs/write_table.c b/lib/sqfs/write_table.c
index c50cf06..1931b83 100644
--- a/lib/sqfs/write_table.c
+++ b/lib/sqfs/write_table.c
@@ -15,7 +15,6 @@
#include "sqfs/io.h"
#include "util.h"
-#include <endian.h>
#include <stdlib.h>
int sqfs_write_table(sqfs_file_t *file, sqfs_compressor_t *cmp,
diff --git a/lib/sqfshelper/tree_node_to_inode.c b/lib/sqfshelper/tree_node_to_inode.c
index 62a804d..d75e959 100644
--- a/lib/sqfshelper/tree_node_to_inode.c
+++ b/lib/sqfshelper/tree_node_to_inode.c
@@ -12,7 +12,6 @@
#include "util.h"
#include <assert.h>
-#include <endian.h>
#include <stdlib.h>
#include <string.h>
diff --git a/lib/tar/internal.h b/lib/tar/internal.h
index f30de29..435cb73 100644
--- a/lib/tar/internal.h
+++ b/lib/tar/internal.h
@@ -12,7 +12,6 @@
#include "util.h"
#include "tar.h"
-#include <sys/sysmacros.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
diff --git a/lib/util/Makemodule.am b/lib/util/Makemodule.am
index 1d77fd5..58333ac 100644
--- a/lib/util/Makemodule.am
+++ b/lib/util/Makemodule.am
@@ -1,6 +1,6 @@
libutil_la_SOURCES = lib/util/write_data.c
libutil_la_SOURCES += lib/util/read_data.c include/util.h
-libutil_la_SOURCES += lib/util/mkdir_p.c
+libutil_la_SOURCES += lib/util/mkdir_p.c include/compat.h
libutil_la_SOURCES += lib/util/str_table.c include/str_table.h
libutil_la_SOURCES += lib/util/dirstack.c lib/util/padd_file.c
libutil_la_SOURCES += lib/util/alloc.c
diff --git a/lib/util/dirstack.c b/lib/util/dirstack.c
index 8f7baf1..20a89cc 100644
--- a/lib/util/dirstack.c
+++ b/lib/util/dirstack.c
@@ -6,8 +6,6 @@
*/
#include "config.h"
-#include <sys/types.h>
-#include <sys/stat.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
diff --git a/lib/util/mkdir_p.c b/lib/util/mkdir_p.c
index f9d7730..93d0f59 100644
--- a/lib/util/mkdir_p.c
+++ b/lib/util/mkdir_p.c
@@ -6,8 +6,6 @@
*/
#include "config.h"
-#include <sys/types.h>
-#include <sys/stat.h>
#include <string.h>
#include <alloca.h>
#include <stdio.h>
diff --git a/tar/tar2sqfs.c b/tar/tar2sqfs.c
index 1175273..5a404f4 100644
--- a/tar/tar2sqfs.c
+++ b/tar/tar2sqfs.c
@@ -17,7 +17,6 @@
#include "util.h"
#include "tar.h"
-#include <sys/sysmacros.h>
#include <stdlib.h>
#include <getopt.h>
#include <unistd.h>
diff --git a/tests/fstree_from_file.c b/tests/fstree_from_file.c
index a8e05c3..76e378a 100644
--- a/tests/fstree_from_file.c
+++ b/tests/fstree_from_file.c
@@ -8,7 +8,6 @@
#include "fstree.h"
-#include <sys/sysmacros.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
diff --git a/unpack/rdsquashfs.h b/unpack/rdsquashfs.h
index 90e94fe..26c5d08 100644
--- a/unpack/rdsquashfs.h
+++ b/unpack/rdsquashfs.h
@@ -20,13 +20,9 @@
#include "fstree.h"
#include "util.h"
-#include <sys/sysmacros.h>
-#include <sys/types.h>
#ifdef HAVE_SYS_XATTR_H
#include <sys/xattr.h>
#endif
-#include <sys/prctl.h>
-#include <sys/wait.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>