From 592b56c8a5af3dd9e78fe5c8cbdf4e3e46b136ef Mon Sep 17 00:00:00 2001 From: ksherlock Date: Fri, 4 Sep 2009 01:49:55 +0000 Subject: [PATCH] cleanup for non-OS X git-svn-id: https://profuse.googlecode.com/svn/trunk@53 aa027e90-d47c-11dd-86d7-074df07e0730 --- xattr.cpp | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/xattr.cpp b/xattr.cpp index b525954..85b261d 100644 --- a/xattr.cpp +++ b/xattr.cpp @@ -13,6 +13,22 @@ #include +#ifdef __APPLE__ +// apple has additional parameter for position and options. + +inline ssize_t getxattr(const char *path, const char *name, void *value, size_t size) +{ + return getxattr(path, name, value, size, 0, XATTR_NOFOLLOW); +} + +// apple has additional parameter for options. +inline ssize_t listxattr(const char *path, char *namebuf, size_t size) +{ + return listxattr(path, namebuf, size, XATTR_NOFOLLOW); +} + +#endif + void hexdump(const uint8_t *data, ssize_t size) { const char *HexMap = "0123456789abcdef"; @@ -63,13 +79,13 @@ const char *HexMap = "0123456789abcdef"; */ ssize_t get_attr_list(const char * fname, std::vector &out) { - ssize_t asize = listxattr(fname, NULL, 0, XATTR_NOFOLLOW); + ssize_t asize = listxattr(fname, NULL, 0); if (asize < 0) return -1; if (asize == 0) return 0; char *buffer = new char[asize]; - if ((asize = listxattr(fname, buffer, asize, XATTR_NOFOLLOW)) < 0) + if ((asize = listxattr(fname, buffer, asize)) < 0) { delete []buffer; return -1; @@ -98,16 +114,6 @@ ssize_t get_attr_list(const char * fname, std::vector &out) } -#ifdef __APPLE__ -// apple has additional parameter for position (only valid for resource forks) - -inline ssize_t getxattr(const char *path, const char *name, void *value, size_t size, int options) -{ - return getxattr(path, name, value, size, 0, options); -} - - -#endif @@ -119,7 +125,7 @@ void dumpxattr(const char *file, const char *attr) ssize_t asize; char *buffer; - asize = getxattr(file, attr, NULL, 0, XATTR_NOFOLLOW); + asize = getxattr(file, attr, NULL, 0); if (asize < 0) { std::perror(attr); @@ -131,7 +137,7 @@ char *buffer; buffer = new char[asize]; //if (!buffer) return; - asize = getxattr(file, attr, buffer, asize, XATTR_NOFOLLOW); + asize = getxattr(file, attr, buffer, asize); if (asize >= 0) { hexdump((uint8_t *)buffer, asize); @@ -183,7 +189,7 @@ int list(int argc, char **argv) { const char *attr_name = i->c_str(); - ssize_t asize = getxattr(fname, attr_name, NULL, 0, XATTR_NOFOLLOW); + ssize_t asize = getxattr(fname, attr_name, NULL, 0); if (asize >= 0) { std::printf("%-*s % 8u\n", maxname, attr_name, asize);