From: Richard D. <ric...@us...> - 2006-08-15 09:14:25
|
Update of /cvsroot/file-extattr/File-ExtAttr In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv24027 Modified Files: extattr_bsd.c extattr_bsd.h extattr_os.h portable.h Log Message: Fix BSD build; support for File::ExtAttr::Tie on BSD Index: portable.h =================================================================== RCS file: /cvsroot/file-extattr/File-ExtAttr/portable.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** portable.h 14 Aug 2006 22:00:27 -0000 1.6 --- portable.h 15 Aug 2006 09:14:20 -0000 1.7 *************** *** 138,142 **** return listxattr(path, buf, slen, 0); #elif defined(EXTATTR_BSD) ! #error "FIXME" #elif defined(EXTATTR_SOLARIS) return solaris_listxattr(path, buf, slen); --- 138,142 ---- return listxattr(path, buf, slen, 0); #elif defined(EXTATTR_BSD) ! return bsd_listxattr(path, buf, slen); #elif defined(EXTATTR_SOLARIS) return solaris_listxattr(path, buf, slen); *************** *** 152,156 **** return flistxattr(fd, buf, slen, 0); #elif defined(EXTATTR_BSD) ! #error "FIXME" #elif defined(EXTATTR_SOLARIS) return solaris_flistxattr(fd, buf, slen); --- 152,156 ---- return flistxattr(fd, buf, slen, 0); #elif defined(EXTATTR_BSD) ! return bsd_flistxattr(fd, buf, slen); #elif defined(EXTATTR_SOLARIS) return solaris_flistxattr(fd, buf, slen); Index: extattr_os.h =================================================================== RCS file: /cvsroot/file-extattr/File-ExtAttr/extattr_os.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** extattr_os.h 14 Aug 2006 21:10:54 -0000 1.1 --- extattr_os.h 15 Aug 2006 09:14:20 -0000 1.2 *************** *** 3,6 **** --- 3,8 ---- /* OS detection */ + #include <sys/param.h> + #ifdef BSD #define EXTATTR_BSD *************** *** 18,22 **** /* Include appropriate header for this OS, defaulting to Linux-style */ ! #ifdef EXTATTR_BSD #include "extattr_bsd.h" #elif defined(EXTATTR_MACOSX) --- 20,24 ---- /* Include appropriate header for this OS, defaulting to Linux-style */ ! #if defined(EXTATTR_BSD) #include "extattr_bsd.h" #elif defined(EXTATTR_MACOSX) Index: extattr_bsd.h =================================================================== RCS file: /cvsroot/file-extattr/File-ExtAttr/extattr_bsd.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** extattr_bsd.h 14 Aug 2006 21:16:47 -0000 1.2 --- extattr_bsd.h 15 Aug 2006 09:14:20 -0000 1.3 *************** *** 16,18 **** --- 16,26 ---- const size_t slen); + ssize_t bsd_listxattr (const char *path, + char *buf, + const size_t buflen); + + ssize_t bsd_flistxattr (const int fd, + char *buf, + const size_t buflen); + #endif /* EXTATTR_BSD_H */ Index: extattr_bsd.c =================================================================== RCS file: /cvsroot/file-extattr/File-ExtAttr/extattr_bsd.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** extattr_bsd.c 14 Aug 2006 21:16:47 -0000 1.1 --- extattr_bsd.c 15 Aug 2006 09:14:20 -0000 1.2 *************** *** 1,4 **** --- 1,8 ---- + #include "extattr_os.h" + #ifdef EXTATTR_BSD + #include <errno.h> + #include "extattr_bsd.h" *************** *** 47,49 **** --- 51,105 ---- } + /* Convert the BSD-style list to a nul-separated list. */ + static void + reformat_list (char *buf, const ssize_t len) + { + ssize_t pos = 0; + ssize_t attrlen; + + while (pos < len) + { + attrlen = (unsigned char) buf[pos]; + memmove(buf + pos, buf + pos + 1, attrlen); + buf[pos + attrlen] = '\0'; + pos += attrlen + 1; + } + } + + ssize_t + bsd_listxattr (const char *path, char *buf, const size_t buflen) + { + ssize_t ret; + + /* XXX: Namespace? */ + ret = extattr_list_file(path, + EXTATTR_NAMESPACE_USER, + /* To get the length on *BSD, pass NULL here. */ + buflen ? buf : NULL, + buflen); + + if (buflen && (ret > 0)) + reformat_list(buf, ret); + + return ret; + } + + ssize_t + bsd_flistxattr (const int fd, char *buf, const size_t buflen) + { + ssize_t ret; + + /* XXX: Namespace? */ + ret = extattr_list_fd(fd, + EXTATTR_NAMESPACE_USER, + /* To get the length on *BSD, pass NULL here. */ + buflen ? buf : NULL, + buflen); + + if (buflen && (ret > 0)) + reformat_list(buf, ret); + + return ret; + } + #endif /* EXTATTR_BSD */ |