mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-07-27 12:37:35 +00:00
Implement simple utility functions for reading and writing to fds
Signed-off-by: Christian Seiler <christian@iwakd.de> Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
parent
65fbbb0a0f
commit
92f023dccc
@ -281,3 +281,38 @@ again:
|
|||||||
goto again;
|
goto again;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lxc_write_nointr(int fd, const void* buf, size_t count)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
again:
|
||||||
|
ret = write(fd, buf, count);
|
||||||
|
if (ret < 0 && errno == EINTR)
|
||||||
|
goto again;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_read_nointr(int fd, void* buf, size_t count)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
again:
|
||||||
|
ret = read(fd, buf, count);
|
||||||
|
if (ret < 0 && errno == EINTR)
|
||||||
|
goto again;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lxc_read_nointr_expect(int fd, void* buf, size_t count, const void* expected_buf)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
ret = lxc_read_nointr(fd, buf, count);
|
||||||
|
if (ret <= 0)
|
||||||
|
return ret;
|
||||||
|
if (ret != count)
|
||||||
|
return -1;
|
||||||
|
if (expected_buf && memcmp(buf, expected_buf, count) != 0) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -68,4 +68,9 @@ extern int __build_bug_on_failed;
|
|||||||
extern int wait_for_pid(pid_t pid);
|
extern int wait_for_pid(pid_t pid);
|
||||||
extern int lxc_wait_for_pid_status(pid_t pid);
|
extern int lxc_wait_for_pid_status(pid_t pid);
|
||||||
|
|
||||||
|
/* send and receive buffers completely */
|
||||||
|
extern int lxc_write_nointr(int fd, const void* buf, size_t count);
|
||||||
|
extern int lxc_read_nointr(int fd, void* buf, size_t count);
|
||||||
|
extern int lxc_read_nointr_expect(int fd, void* buf, size_t count, const void* expected_buf);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user