mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-18 06:03:42 +03:00
xattr-util: add flistxattr_malloc() that returns a NULSTR
This commit is contained in:
parent
6ac99d9d5f
commit
7de2d2e17d
@ -234,3 +234,37 @@ int fd_setcrtime(int fd, usec_t usec) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int flistxattr_malloc(int fd, char **ret) {
|
||||
size_t l = 100;
|
||||
|
||||
assert(fd >= 0);
|
||||
assert(ret);
|
||||
|
||||
for (;;) {
|
||||
_cleanup_free_ char *v = NULL;
|
||||
ssize_t n;
|
||||
|
||||
v = new(char, l+1);
|
||||
if (!v)
|
||||
return -ENOMEM;
|
||||
|
||||
n = flistxattr(fd, v, l);
|
||||
if (n < 0) {
|
||||
if (errno != ERANGE)
|
||||
return -errno;
|
||||
} else {
|
||||
v[n] = 0; /* NUL terminate */
|
||||
*ret = TAKE_PTR(v);
|
||||
return (int) n;
|
||||
}
|
||||
|
||||
n = flistxattr(fd, NULL, 0);
|
||||
if (n < 0)
|
||||
return -errno;
|
||||
if (n > INT_MAX) /* We couldn't return this as 'int' anymore */
|
||||
return -E2BIG;
|
||||
|
||||
l = (size_t) n;
|
||||
}
|
||||
}
|
||||
|
@ -23,3 +23,5 @@ int fd_setcrtime(int fd, usec_t usec);
|
||||
int fd_getcrtime(int fd, usec_t *usec);
|
||||
int path_getcrtime(const char *p, usec_t *usec);
|
||||
int fd_getcrtime_at(int dirfd, const char *name, usec_t *usec, int flags);
|
||||
|
||||
int flistxattr_malloc(int fd, char **ret);
|
||||
|
Loading…
x
Reference in New Issue
Block a user