abstract differences between GNU and Apple xattr functions
parent
6344a0eedb
commit
9d07d07fe4
|
@ -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
|
||||||
|
}
|
|
@ -9,9 +9,9 @@
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/xattr.h>
|
|
||||||
|
|
||||||
#include "apk_fs.h"
|
#include "apk_fs.h"
|
||||||
|
#include "apk_xattr.h"
|
||||||
|
|
||||||
#define TMPNAME_MAX (PATH_MAX + 64)
|
#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);
|
fd = openat(atfd, fn, O_RDWR);
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
foreach_array_item(xattr, fi->xattrs) {
|
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;
|
r = -errno;
|
||||||
if (r != -ENOTSUP) break;
|
if (r != -ENOTSUP) break;
|
||||||
}
|
}
|
||||||
|
|
6
src/io.c
6
src/io.c
|
@ -17,7 +17,6 @@
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/xattr.h>
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
@ -25,6 +24,7 @@
|
||||||
#include "apk_defines.h"
|
#include "apk_defines.h"
|
||||||
#include "apk_io.h"
|
#include "apk_io.h"
|
||||||
#include "apk_crypto.h"
|
#include "apk_crypto.h"
|
||||||
|
#include "apk_xattr.h"
|
||||||
|
|
||||||
#if defined(__GLIBC__) || defined(__UCLIBC__)
|
#if defined(__GLIBC__) || defined(__UCLIBC__)
|
||||||
#define HAVE_FGETPWENT_R
|
#define HAVE_FGETPWENT_R
|
||||||
|
@ -786,12 +786,12 @@ int apk_fileinfo_get(int atfd, const char *filename, unsigned int flags,
|
||||||
r = 0;
|
r = 0;
|
||||||
fd = openat(atfd, filename, O_RDONLY);
|
fd = openat(atfd, filename, O_RDONLY);
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
len = flistxattr(fd, buf, sizeof(buf));
|
len = apk_flistxattr(fd, buf, sizeof(buf));
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
struct apk_xattr_array *xattrs = NULL;
|
struct apk_xattr_array *xattrs = NULL;
|
||||||
apk_xattr_array_init(&xattrs);
|
apk_xattr_array_init(&xattrs);
|
||||||
for (i = 0; i < len; i += strlen(&buf[i]) + 1) {
|
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) {
|
if (vlen < 0) {
|
||||||
r = errno;
|
r = errno;
|
||||||
if (r == ENODATA) continue;
|
if (r == ENODATA) continue;
|
||||||
|
|
Loading…
Reference in New Issue