tools/testing/selftests/proc/proc-net-dev-lseek.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/proc/proc-net-dev-lseek.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/proc/proc-net-dev-lseek.c
Extension
.c
Size
2001 bytes
Lines
69
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

if (errno == ENOSYS || errno == EPERM) {
			return 4;
		}
		return 1;
	}

	const int fd = open("/proc/net/dev", O_RDONLY);
	assert(fd >= 0);

	char buf1[4096];
	const ssize_t rv1 = read(fd, buf1, sizeof(buf1));
	/*
	 * Not "<=", this file can't be empty:
	 * there is header, "lo" interface with some zeroes.
	 */
	assert(0 < rv1);
	assert(rv1 <= sizeof(buf1));

	/* Believe it or not, this line broke one day. */
	assert(lseek(fd, 0, SEEK_SET) == 0);

	char buf2[4096];
	const ssize_t rv2 = read(fd, buf2, sizeof(buf2));
	/* Not "<=", see above. */
	assert(0 < rv2);
	assert(rv2 <= sizeof(buf2));

	/* Test that lseek rewinds to the beginning of the file. */
	assert(rv1 == rv2);
	assert(memcmp(buf1, buf2, rv1) == 0);

	/* Contents of the file is not validated: this test is about lseek(). */

	return 0;
}

Annotation

Implementation Notes