summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2012-10-27 19:15:58 +1100
committerAndrew Bartlett <abartlet@samba.org>2012-10-28 16:32:42 +1100
commit2756c3ce5c7d5d066dc76592dd1078a8594b983b (patch)
tree61f89ddeb82fbcafa7af6cc718ca25a589e78354 /lib
parenta7b8d0260a55959c72614251db880fed04a48316 (diff)
downloadsamba-2756c3ce5c7d5d066dc76592dd1078a8594b983b.tar.gz
samba-2756c3ce5c7d5d066dc76592dd1078a8594b983b.tar.bz2
samba-2756c3ce5c7d5d066dc76592dd1078a8594b983b.zip
lib/replace: Return size of xattr if size argument is 0
This makes rep_{f,}getxattr a more complete replacement for the linux function. Andrew Bartlett
Diffstat (limited to 'lib')
-rw-r--r--lib/replace/xattr.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/replace/xattr.c b/lib/replace/xattr.c
index 8e1c989a3d..a26ff674a1 100644
--- a/lib/replace/xattr.c
+++ b/lib/replace/xattr.c
@@ -71,7 +71,9 @@ ssize_t rep_getxattr (const char *path, const char *name, void *value, size_t si
* that the buffer is large enough to fit the returned value.
*/
if((retval=extattr_get_file(path, attrnamespace, attrname, NULL, 0)) >= 0) {
- if(retval > size) {
+ if (size == 0) {
+ return retval;
+ } else if (retval > size) {
errno = ERANGE;
return -1;
}
@@ -88,6 +90,9 @@ ssize_t rep_getxattr (const char *path, const char *name, void *value, size_t si
if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
retval = attr_get(path, attrname, (char *)value, &valuelength, flags);
+ if (size == 0 && retval == -1 && errno == E2BIG) {
+ return valuelength;
+ }
return retval ? retval : valuelength;
#elif defined(HAVE_ATTROPEN)
@@ -126,7 +131,9 @@ ssize_t rep_fgetxattr (int filedes, const char *name, void *value, size_t size)
const char *attrname = ((s=strchr(name, '.')) == NULL) ? name : s + 1;
if((retval=extattr_get_fd(filedes, attrnamespace, attrname, NULL, 0)) >= 0) {
- if(retval > size) {
+ if (size == 0) {
+ return retval;
+ } else if (retval > size) {
errno = ERANGE;
return -1;
}
@@ -143,7 +150,9 @@ ssize_t rep_fgetxattr (int filedes, const char *name, void *value, size_t size)
if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
retval = attr_getf(filedes, attrname, (char *)value, &valuelength, flags);
-
+ if (size == 0 && retval == -1 && errno == E2BIG) {
+ return valuelength;
+ }
return retval ? retval : valuelength;
#elif defined(HAVE_ATTROPEN)
ssize_t ret = -1;