file_utils: add lxc_read_try_buf_at()

parent 6de35cd9
......@@ -122,6 +122,32 @@ int lxc_read_from_file(const char *filename, void *buf, size_t count)
return ret;
}
ssize_t lxc_read_try_buf_at(int dfd, const char *path, void *buf, size_t count)
{
__do_close int fd = -EBADF;
ssize_t ret;
fd = open_at(dfd, path, PROTECT_OPEN_W, PROTECT_LOOKUP_BENEATH, 0);
if (fd < 0)
return -errno;
if (!buf || !count) {
char buf2[100];
size_t count2 = 0;
while ((ret = lxc_read_nointr(fd, buf2, 100)) > 0)
count2 += ret;
if (ret >= 0)
ret = count2;
} else {
memset(buf, 0, count);
ret = lxc_read_nointr(fd, buf, count);
}
return ret;
}
ssize_t lxc_write_nointr(int fd, const void *buf, size_t count)
{
ssize_t ret;
......
......@@ -94,5 +94,7 @@ __hidden int fd_make_nonblocking(int fd);
__hidden extern char *read_file_at(int dfd, const char *fnam,
unsigned int o_flags,
unsigned resolve_flags);
__hidden extern ssize_t lxc_read_try_buf_at(int dfd, const char *path,
void *buf, size_t count);
#endif /* __LXC_FILE_UTILS_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment