summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAriadne Conill <ariadne@dereferenced.org>2021-12-29 11:51:15 -0600
committerTimo Teräs <timo.teras@iki.fi>2021-12-29 20:14:41 +0200
commit9d07d07fe4f663f7ebb5ec6a7ef5d2b1345bcea7 (patch)
treecdf013da6255db61b9c716a602a17030c285fa26 /src
parent6344a0eedbc0bc21b537b51e7cddc13a7ddc5bf3 (diff)
downloadapk-tools-9d07d07fe4f663f7ebb5ec6a7ef5d2b1345bcea7.tar.gz
apk-tools-9d07d07fe4f663f7ebb5ec6a7ef5d2b1345bcea7.tar.bz2
apk-tools-9d07d07fe4f663f7ebb5ec6a7ef5d2b1345bcea7.tar.xz
apk-tools-9d07d07fe4f663f7ebb5ec6a7ef5d2b1345bcea7.zip
abstract differences between GNU and Apple xattr functions
Diffstat (limited to 'src')
-rw-r--r--src/apk_xattr.h30
-rw-r--r--src/fs_fsys.c4
-rw-r--r--src/io.c6
3 files changed, 35 insertions, 5 deletions
diff --git a/src/apk_xattr.h b/src/apk_xattr.h
new file mode 100644
index 0000000..595fe68
--- /dev/null
+++ b/src/apk_xattr.h
@@ -0,0 +1,30 @@
+#pragma once
+#include <unistd.h>
+#include <sys/xattr.h>
+
+static inline int apk_fsetxattr(int fd, const char *name, void *value, size_t size)
+{
+#ifdef __APPLE__
+ return fsetxattr(fd, name, value, size, 0, 0);
+#else
+ return fsetxattr(fd, name, value, size, 0);
+#endif
+}
+
+static inline ssize_t apk_fgetxattr(int fd, const char *name, void *value, size_t size)
+{
+#ifdef __APPLE__
+ return fgetxattr(fd, name, value, size, 0, 0);
+#else
+ return fgetxattr(fd, name, value, size);
+#endif
+}
+
+static inline ssize_t apk_flistxattr(int fd, char *namebuf, size_t size)
+{
+#ifdef __APPLE__
+ return flistxattr(fd, namebuf, size, 0);
+#else
+ return flistxattr(fd, namebuf, size);
+#endif
+}
diff --git a/src/fs_fsys.c b/src/fs_fsys.c
index 3dad4e0..2c43607 100644
--- a/src/fs_fsys.c
+++ b/src/fs_fsys.c
@@ -9,9 +9,9 @@
#include <unistd.h>
#include <sys/stat.h>
-#include <sys/xattr.h>
#include "apk_fs.h"
+#include "apk_xattr.h"
#define TMPNAME_MAX (PATH_MAX + 64)
@@ -186,7 +186,7 @@ static int fsys_file_extract(struct apk_ctx *ac, const struct apk_file_info *fi,
fd = openat(atfd, fn, O_RDWR);
if (fd >= 0) {
foreach_array_item(xattr, fi->xattrs) {
- if (fsetxattr(fd, xattr->name, xattr->value.ptr, xattr->value.len, 0) < 0) {
+ if (apk_fsetxattr(fd, xattr->name, xattr->value.ptr, xattr->value.len) < 0) {
r = -errno;
if (r != -ENOTSUP) break;
}
diff --git a/src/io.c b/src/io.c
index dc7d8b2..b60c58d 100644
--- a/src/io.c
+++ b/src/io.c
@@ -17,7 +17,6 @@
#include <sys/mman.h>
#include <sys/wait.h>
#include <sys/stat.h>
-#include <sys/xattr.h>
#include <pwd.h>
#include <grp.h>
#include <limits.h>
@@ -25,6 +24,7 @@
#include "apk_defines.h"
#include "apk_io.h"
#include "apk_crypto.h"
+#include "apk_xattr.h"
#if defined(__GLIBC__) || defined(__UCLIBC__)
#define HAVE_FGETPWENT_R
@@ -786,12 +786,12 @@ int apk_fileinfo_get(int atfd, const char *filename, unsigned int flags,
r = 0;
fd = openat(atfd, filename, O_RDONLY);
if (fd >= 0) {
- len = flistxattr(fd, buf, sizeof(buf));
+ len = apk_flistxattr(fd, buf, sizeof(buf));
if (len > 0) {
struct apk_xattr_array *xattrs = NULL;
apk_xattr_array_init(&xattrs);
for (i = 0; i < len; i += strlen(&buf[i]) + 1) {
- vlen = fgetxattr(fd, &buf[i], val, sizeof(val));
+ vlen = apk_fgetxattr(fd, &buf[i], val, sizeof(val));
if (vlen < 0) {
r = errno;
if (r == ENODATA) continue;