summaryrefslogtreecommitdiffstats
path: root/fsade.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2020-08-13 10:02:29 -0400
committerTavian Barnes <tavianator@tavianator.com>2020-08-13 10:14:29 -0400
commit564142a029fda86b2d87f8f39c12acea34241098 (patch)
tree802a8225cacfc1d9f8ba80c0959651353f728325 /fsade.c
parent6a4c2677075adca143fa8501096a2a59499503b5 (diff)
downloadbfs-564142a029fda86b2d87f8f39c12acea34241098.tar.xz
Implement -xattrname
From macOS find.
Diffstat (limited to 'fsade.c')
-rw-r--r--fsade.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/fsade.c b/fsade.c
index acd39bb..efe5092 100644
--- a/fsade.c
+++ b/fsade.c
@@ -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