abstract differences between GNU and Apple xattr functions

cute-signatures
Ariadne Conill 2021-12-29 11:51:15 -06:00 committed by Timo Teräs
parent 6344a0eedb
commit 9d07d07fe4
3 changed files with 35 additions and 5 deletions

30
src/apk_xattr.h Normal file
View File

@ -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
}

View File

@ -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;
}

View File

@ -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;