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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
assert.herrno.hfcntl.hstring.hunistd.hsched.h
Detected Declarations
function Copyright
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
- Immediate include surface: `assert.h`, `errno.h`, `fcntl.h`, `string.h`, `unistd.h`, `sched.h`.
- Detected declarations: `function Copyright`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.