// SPDX-License-Identifier: GPL-2.0-or-later /* ASST - Plug A Simple Socket Transport * for qemu/UNIX domain socket mode * * PASTA - Pack A Subtle Tap Abstraction * for network namespace/tap device mode * * PESTO - Programmable Extensible Socket Translation Orchestrator * front-end for passt(1) and pasta(1) forwarding configuration * * pesto_util.c - Helpers used by both passt/pasta and pesto * * Copyright Red Hat * Author: Stefano Brivio * Author: David Gibson */ #include #include #include #include #include "pesto_util.h" /** * read_all_buf() - Fill a whole buffer from a file descriptor * @fd: File descriptor * @buf: Pointer to base of buffer * @len: Length of buffer * * Return: 0 on success, -1 on error (with errno set) * * #syscalls read */ int read_all_buf(int fd, void *buf, size_t len) { size_t left = len; char *p = buf; while (left) { ssize_t rc; assert(left <= len); do rc = read(fd, p, left); while ((rc < 0) && errno == EINTR); if (rc < 0) return -1; if (rc == 0) { errno = ENODATA; return -1; } p += rc; left -= rc; } return 0; }