Update of /cvsroot/file-extattr/File-ExtAttr
In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv28277
Modified Files:
extattr_solaris.c extattr_solaris.h portable.h
Log Message:
Solaris support for *listxattr() -- now 95% passes on Solaris
Index: portable.h
===================================================================
RCS file: /cvsroot/file-extattr/File-ExtAttr/portable.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** portable.h 14 Aug 2006 21:10:54 -0000 1.5
--- portable.h 14 Aug 2006 22:00:27 -0000 1.6
***************
*** 140,144 ****
#error "FIXME"
#elif defined(EXTATTR_SOLARIS)
! /*#error "XXX: FIXME"*/
#else
return listxattr(path, buf, slen);
--- 140,144 ----
#error "FIXME"
#elif defined(EXTATTR_SOLARIS)
! return solaris_listxattr(path, buf, slen);
#else
return listxattr(path, buf, slen);
***************
*** 154,158 ****
#error "FIXME"
#elif defined(EXTATTR_SOLARIS)
! /*#error "XXX: FIXME" */
#else
return flistxattr(fd, buf, slen);
--- 154,158 ----
#error "FIXME"
#elif defined(EXTATTR_SOLARIS)
! return solaris_flistxattr(fd, buf, slen);
#else
return flistxattr(fd, buf, slen);
Index: extattr_solaris.c
===================================================================
RCS file: /cvsroot/file-extattr/File-ExtAttr/extattr_solaris.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** extattr_solaris.c 14 Aug 2006 21:10:54 -0000 1.1
--- extattr_solaris.c 14 Aug 2006 22:00:27 -0000 1.2
***************
*** 4,12 ****
#include <errno.h>
#include <unistd.h>
static const mode_t ATTRMODE = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP;
! static inline int
writexattr (const int attrfd,
const char *attrvalue,
--- 4,15 ----
#include <errno.h>
+ #include <string.h>
#include <unistd.h>
+ #include <dirent.h>
+ #include <sys/types.h>
static const mode_t ATTRMODE = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP;
! static int
writexattr (const int attrfd,
const char *attrvalue,
***************
*** 23,27 ****
}
! static inline int
readclose (const int attrfd,
void *attrvalue,
--- 26,30 ----
}
! static int
readclose (const int attrfd,
void *attrvalue,
***************
*** 66,70 ****
}
! static inline int
unlinkclose (const int attrdirfd, const char *attrname)
{
--- 69,73 ----
}
! static int
unlinkclose (const int attrdirfd, const char *attrname)
{
***************
*** 89,92 ****
--- 92,156 ----
}
+ static ssize_t
+ listclose (const int attrdirfd, char *buf, const size_t buflen)
+ {
+ int saved_errno = 0;
+ int ok = 1;
+ ssize_t len = 0;
+ DIR *dirp;
+
+ if (attrdirfd == -1)
+ ok = 0;
+
+ if (ok)
+ dirp = fdopendir(attrdirfd);
+
+ if (ok)
+ {
+ struct dirent *de;
+
+ while ((de = readdir(dirp)))
+ {
+ const size_t namelen = strlen(de->d_name);
+
+ /* Ignore "." and ".." entries */
+ if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
+ continue;
+
+ if (buflen)
+ {
+ /* Check for space, then copy directory name + nul into list. */
+ if ((len + namelen + 1) > buflen)
+ {
+ errno = ERANGE;
+ ok = 0;
+ break;
+ }
+ else
+ {
+ strcpy(buf + len, de->d_name);
+ len += namelen;
+ buf[len] = '\0';
+ ++len;
+ }
+ }
+ else
+ {
+ /* Seeing how much space is needed? */
+ len += namelen + 1;
+ }
+ }
+ }
+
+ if (!ok)
+ saved_errno = errno;
+ if ((attrdirfd >= 0) && (close(attrdirfd) == -1) && !saved_errno)
+ saved_errno = errno;
+ if (saved_errno)
+ errno = saved_errno;
+
+ return ok ? len : -1;
+ }
+
int
solaris_setxattr (const char *path,
***************
*** 178,180 ****
--- 242,258 ----
}
+ ssize_t
+ solaris_listxattr (const char *path, char *buf, const size_t buflen)
+ {
+ int attrdirfd = attropen(path, ".", O_RDONLY);
+ return listclose(attrdirfd, buf, buflen);
+ }
+
+ ssize_t
+ solaris_flistxattr (const int fd, char *buf, const size_t buflen)
+ {
+ int attrdirfd = openat(fd, ".", O_RDONLY|O_XATTR);
+ return listclose(attrdirfd, buf, buflen);
+ }
+
#endif /* EXTATTR_SOLARIS */
Index: extattr_solaris.h
===================================================================
RCS file: /cvsroot/file-extattr/File-ExtAttr/extattr_solaris.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** extattr_solaris.h 14 Aug 2006 21:10:54 -0000 1.1
--- extattr_solaris.h 14 Aug 2006 22:00:27 -0000 1.2
***************
*** 40,42 ****
--- 40,50 ----
int solaris_fremovexattr (const int fd, const char *attrname);
+ ssize_t solaris_listxattr (const char *path,
+ char *buf,
+ const size_t buflen);
+
+ ssize_t solaris_flistxattr (const int fd,
+ char *buf,
+ const size_t buflen);
+
#endif /* EXTATTR_SOLARIS_H */
|