From: Richard D. <ric...@us...> - 2006-10-02 21:58:39
|
Update of /cvsroot/file-extattr/File-ExtAttr In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv30204 Modified Files: extattr_bsd.c extattr_bsd.h Log Message: *BSD for namespace lists Index: extattr_bsd.h =================================================================== RCS file: /cvsroot/file-extattr/File-ExtAttr/extattr_bsd.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** extattr_bsd.h 30 Sep 2006 22:10:12 -0000 1.4 --- extattr_bsd.h 2 Oct 2006 21:58:34 -0000 1.5 *************** *** 50,52 **** --- 50,62 ---- struct hv *flags); + ssize_t bsd_listxattrns (const char *path, + char *buf, + const size_t buflen, + struct hv *flags); + + ssize_t bsd_flistxattrns (const int fd, + char *buf, + const size_t buflen, + struct hv *flags); + #endif /* EXTATTR_BSD_H */ Index: extattr_bsd.c =================================================================== RCS file: /cvsroot/file-extattr/File-ExtAttr/extattr_bsd.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** extattr_bsd.c 2 Oct 2006 20:05:22 -0000 1.4 --- extattr_bsd.c 2 Oct 2006 21:58:34 -0000 1.5 *************** *** 332,334 **** --- 332,444 ---- } + static ssize_t + listxattrns (char *buf, const size_t buflen, + const int iHasUser, const int iHasSystem) + { + size_t len = 0; + int ret; + + if (iHasUser) + len += sizeof(NAMESPACE_USER); + if (iHasSystem) + len += sizeof(NAMESPACE_SYSTEM); + + if (buflen >= len) + { + char *p = buf; + + if (iHasUser) + { + memcpy(p, NAMESPACE_USER, sizeof(NAMESPACE_USER)); + p += sizeof(NAMESPACE_USER); + } + if (iHasSystem) + { + memcpy(p, NAMESPACE_SYSTEM, sizeof(NAMESPACE_SYSTEM)); + p += sizeof(NAMESPACE_SYSTEM); + } + + ret = len; + } + else if (buflen == 0) + { + ret = len; + } + else + { + errno = ERANGE; + ret = -1; + } + + return ret; + } + + ssize_t + bsd_listxattrns (const char *path, + char *buf, + const size_t buflen, + struct hv *flags) + { + int iHasUser = 0; + int iHasSystem = 0; + ssize_t ret; + + ret = extattr_list_file(path, EXTATTR_NAMESPACE_USER, NULL, 0); + if (ret > 0) + iHasUser = 1; + + if (ret >= 0) + { + ret = extattr_list_file(path, EXTATTR_NAMESPACE_SYSTEM, NULL, 0); + if (ret > 0) + iHasSystem = 1; + + /* + * XXX: How do we cope with EPERM? Throw an exception. + * For now ignore it, although this could cause problems. + */ + if (ret == -1 && errno == EPERM) + ret = 0; + } + + if (ret >= 0) + ret = listxattrns(buf, buflen, iHasUser, iHasSystem); + + return ret; + } + + ssize_t + bsd_flistxattrns (const int fd, + char *buf, + const size_t buflen, + struct hv *flags) + { + int iHasUser = 0; + int iHasSystem = 0; + ssize_t ret; + + ret = extattr_list_fd(fd, EXTATTR_NAMESPACE_USER, NULL, 0); + if (ret > 0) + iHasUser = 1; + + if (ret >= 0) + { + ret = extattr_list_fd(fd, EXTATTR_NAMESPACE_SYSTEM, NULL, 0); + if (ret > 0) + iHasSystem = 1; + + /* + * XXX: How do we cope with EPERM? Throw an exception. + * For now ignore it, although this could cause problems. + */ + if (ret == -1 && errno == EPERM) + ret = 0; + } + + if (ret >= 0) + ret = listxattrns(buf, buflen, iHasUser, iHasSystem); + + return ret; + } + #endif /* EXTATTR_BSD */ |