diff options
author | Elliott Hughes <enh@google.com> | 2019-06-07 16:18:00 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-06-08 13:10:10 -0500 |
commit | 78954416db3032f93317deae1120be9cd7ec9783 (patch) | |
tree | 9c8f58f8c5d4c56ba5fd951b39e84dd15c68a0bd /lib/portability.h | |
parent | 61ef1dccec4e6bf1c56384ed1cd45f93dcb6bd4c (diff) | |
download | toybox-78954416db3032f93317deae1120be9cd7ec9783.tar.gz |
macOS: numerous fixes.
This patch adds a BSD version of xgetmountlist (for the path ==
NULL case only), tested on macOS. It also papers over the differences
between macOS' and Linux's xattr APIs. For once I think the macOS
one is better. The imitation of mknodat I've had to write swings
things back in Linux's favor though.
BSD calls f_frsize by the name f_iosize instead. (FWIW, it looks
like this is meaningless on Linux and actually meaningful on macOS.)
I've added one #if to toys/ --- I'm calling pathconf in stat.c to
work around the absence of f_namelen, and have left a TODO with an
explanation. I'm not sure what the best fix is here, so punting.
No-one can agree what f_fsid is, even if they're all basically the
same, so work around the `val` versus `__val` issue between macOS
and Linux.
With this patch, it's now possible to build cp/mv/install and stat
for macOS too. (Which completes the set of "toybox commands currently
used on Linux as part of the AOSP build" if you ignore stuff that
deals with processes, which I doubt we'll ever be able to support
for lack of any API.)
Diffstat (limited to 'lib/portability.h')
-rw-r--r-- | lib/portability.h | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/portability.h b/lib/portability.h index f57eb026..c955eddf 100644 --- a/lib/portability.h +++ b/lib/portability.h @@ -186,8 +186,24 @@ char *strcasestr(const char *haystack, const char *needle); #endif #endif -#ifndef __FreeBSD__ +#if defined(__APPLE__) || defined(__linux__) +// Linux and macOS has both have getxattr and friends in <sys/xattr.h>, but +// they aren't compatible. #include <sys/xattr.h> +ssize_t xattr_get(const char *, const char *, void *, size_t); +ssize_t xattr_lget(const char *, const char *, void *, size_t); +ssize_t xattr_fget(int fd, const char *, void *, size_t); +ssize_t xattr_list(const char *, char *, size_t); +ssize_t xattr_llist(const char *, char *, size_t); +ssize_t xattr_flist(int, char *, size_t); +ssize_t xattr_set(const char*, const char*, const void*, size_t, int); +ssize_t xattr_lset(const char*, const char*, const void*, size_t, int); +ssize_t xattr_fset(int, const char*, const void*, size_t, int); +#endif + +// macOS doesn't have mknodat, but we can fake it. +#ifdef __APPLE__ +int mknodat(int, const char*, mode_t, dev_t); #endif // Android is missing some headers and functions @@ -312,3 +328,7 @@ struct xnotify { struct xnotify *xnotify_init(int max); int xnotify_add(struct xnotify *not, int fd, char *path); int xnotify_wait(struct xnotify *not, char **path); + +#ifdef __APPLE__ +#define f_frsize f_iosize +#endif |