]> Git Repo - J-linux.git/blob - tools/testing/selftests/bpf/io_helpers.c
Merge tag 'vfs-6.13-rc7.fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
[J-linux.git] / tools / testing / selftests / bpf / io_helpers.c
1 // SPDX-License-Identifier: GPL-2.0
2 #include <sys/select.h>
3 #include <unistd.h>
4 #include <errno.h>
5
6 int read_with_timeout(int fd, char *buf, size_t count, long usec)
7 {
8         const long M = 1000 * 1000;
9         struct timeval tv = { usec / M, usec % M };
10         fd_set fds;
11         int err;
12
13         FD_ZERO(&fds);
14         FD_SET(fd, &fds);
15         err = select(fd + 1, &fds, NULL, NULL, &tv);
16         if (err < 0)
17                 return err;
18         if (FD_ISSET(fd, &fds))
19                 return read(fd, buf, count);
20         return -EAGAIN;
21 }
This page took 0.02494 seconds and 4 git commands to generate.