diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2020-08-13 10:02:29 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2020-08-13 10:14:29 -0400 |
commit | 564142a029fda86b2d87f8f39c12acea34241098 (patch) | |
tree | 802a8225cacfc1d9f8ba80c0959651353f728325 /fsade.c | |
parent | 6a4c2677075adca143fa8501096a2a59499503b5 (diff) | |
download | bfs-564142a029fda86b2d87f8f39c12acea34241098.tar.xz |
Implement -xattrname
From macOS find.
Diffstat (limited to 'fsade.c')
-rw-r--r-- | fsade.c | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -330,6 +330,45 @@ int bfs_check_xattrs(const struct BFTW *ftwbuf) { } } +int bfs_check_xattr_named(const struct BFTW *ftwbuf, const char *name) { + const char *path = fake_at(ftwbuf); + ssize_t len; + +#if BFS_HAS_SYS_EXTATTR + ssize_t (*extattr_get)(const char *, int, const char *, void*, size_t) = + ftwbuf->type == BFTW_LNK ? extattr_get_link : extattr_get_file; + + len = extattr_get(path, EXTATTR_NAMESPACE_SYSTEM, name, NULL, 0); + if (len < 0) { + len = extattr_get(path, EXTATTR_NAMESPACE_USER, name, NULL, 0); + } +#elif __APPLE__ + int options = ftwbuf->type == BFTW_LNK ? XATTR_NOFOLLOW : 0; + len = getxattr(path, name, NULL, 0, 0, options); +#else + if (ftwbuf->type == BFTW_LNK) { + len = lgetxattr(path, name, NULL, 0); + } else { + len = getxattr(path, name, NULL, 0); + } +#endif + + int error = errno; + + free_fake_at(ftwbuf, path); + + if (len >= 0) { + return 1; + } else if (is_absence_error(error)) { + return 0; + } else if (error == E2BIG) { + return 1; + } else { + errno = error; + return -1; + } +} + #else // !BFS_CAN_CHECK_XATTRS int bfs_check_xattrs(const struct BFTW *ftwbuf) { @@ -337,4 +376,9 @@ int bfs_check_xattrs(const struct BFTW *ftwbuf) { return -1; } +int bfs_check_xattr_named(const struct BFTW *ftwbuf, const char *name) { + errno = ENOTSUP; + return -1; +} + #endif |