aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-06-07 16:18:00 -0700
committerRob Landley <rob@landley.net>2019-06-08 13:10:10 -0500
commit78954416db3032f93317deae1120be9cd7ec9783 (patch)
tree9c8f58f8c5d4c56ba5fd951b39e84dd15c68a0bd /toys
parent61ef1dccec4e6bf1c56384ed1cd45f93dcb6bd4c (diff)
downloadtoybox-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 'toys')
-rw-r--r--toys/other/stat.c14
-rw-r--r--toys/posix/cp.c10
2 files changed, 16 insertions, 8 deletions
diff --git a/toys/other/stat.c b/toys/other/stat.c
index 054e2ee7..c4c1bf42 100644
--- a/toys/other/stat.c
+++ b/toys/other/stat.c
@@ -141,8 +141,15 @@ static void print_statfs(char type) {
else if (type == 'c') out('u', statfs->f_files);
else if (type == 'd') out('u', statfs->f_ffree);
else if (type == 'f') out('u', statfs->f_bfree);
- else if (type == 'l') out('d', statfs->f_namelen);
- else if (type == 't') out('x', statfs->f_type);
+ else if (type == 'l') {
+#ifdef __APPLE__
+ // TODO: move this into portability.c somehow, or just use this everywhere?
+ // (glibc and bionic will just re-do the statfs and return f_namelen.)
+ out('d', pathconf(TT.file, _PC_NAME_MAX));
+#else
+ out('d', statfs->f_namelen);
+#endif
+ } else if (type == 't') out('x', statfs->f_type);
else if (type == 'T') {
char *s = "unknown";
struct {unsigned num; char *name;} nn[] = {
@@ -161,9 +168,10 @@ static void print_statfs(char type) {
if (nn[i].num == statfs->f_type) s = nn[i].name;
strout(s);
} else if (type == 'i') {
+ int *val = (int *) &statfs->f_fsid;
char buf[32];
- sprintf(buf, "%08x%08x", statfs->f_fsid.__val[0], statfs->f_fsid.__val[1]);
+ sprintf(buf, "%08x%08x", val[0], val[1]);
strout(buf);
} else if (type == 's') out('d', statfs->f_frsize);
else if (type == 'S') out('d', statfs->f_bsize);
diff --git a/toys/posix/cp.c b/toys/posix/cp.c
index 751a718c..e37b360d 100644
--- a/toys/posix/cp.c
+++ b/toys/posix/cp.c
@@ -278,20 +278,20 @@ static int cp_node(struct dirtree *try)
// We only copy xattrs for files because there's no flistxattrat()
if (TT.pflags&(_CP_xattr|_CP_context)) {
- ssize_t listlen = flistxattr(fdin, 0, 0), len;
+ ssize_t listlen = xattr_flist(fdin, 0, 0), len;
char *name, *value, *list;
if (listlen>0) {
list = xmalloc(listlen);
- flistxattr(fdin, list, listlen);
+ xattr_flist(fdin, list, listlen);
list[listlen-1] = 0; // I do not trust this API.
for (name = list; name-list < listlen; name += strlen(name)+1) {
if (!(TT.pflags&_CP_xattr) && strncmp(name, "security.", 9))
continue;
- if ((len = fgetxattr(fdin, name, 0, 0))>0) {
+ if ((len = xattr_fget(fdin, name, 0, 0))>0) {
value = xmalloc(len);
- if (len == fgetxattr(fdin, name, value, len))
- if (fsetxattr(fdout, name, value, len, 0))
+ if (len == xattr_fget(fdin, name, value, len))
+ if (xattr_fset(fdout, name, value, len, 0))
perror_msg("%s setxattr(%s=%s)", catch, name, value);
free(value);
}