tools/testing/selftests/bpf/io_helpers.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/io_helpers.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/io_helpers.c
Extension
.c
Size
450 bytes
Lines
22
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0
#include <sys/select.h>
#include <unistd.h>
#include <errno.h>

int read_with_timeout(int fd, char *buf, size_t count, long usec)
{
	const long M = 1000 * 1000;
	struct timeval tv = { usec / M, usec % M };
	fd_set fds;
	int err;

	FD_ZERO(&fds);
	FD_SET(fd, &fds);
	err = select(fd + 1, &fds, NULL, NULL, &tv);
	if (err < 0)
		return err;
	if (FD_ISSET(fd, &fds))
		return read(fd, buf, count);
	return -EAGAIN;
}

Annotation

Implementation Notes