tools/testing/selftests/powerpc/utils.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/utils.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/powerpc/utils.c- Extension
.c- Size
- 11501 bytes
- Lines
- 645
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
elf.herrno.hfcntl.hinttypes.hlimits.hlink.hsched.hstdio.hstdlib.hstring.hsys/ioctl.hsys/stat.hsys/sysinfo.hsys/types.hsys/utsname.hunistd.hasm/unistd.hlinux/limits.hutils.h
Detected Declarations
function read_filefunction read_file_allocfunction write_filefunction read_auxvfunction read_debugfs_filefunction write_debugfs_filefunction validate_int_parsefunction parse_bounded_intfunction parse_bounded_uintfunction parse_intmaxfunction parse_uintmaxfunction parse_intfunction parse_uintfunction parse_longfunction parse_ulongfunction read_longfunction read_ulongfunction write_longfunction write_ulongfunction pick_online_cpufunction bind_to_cpufunction is_ppc64lefunction read_sysfs_filefunction read_debugfs_intfunction write_debugfs_intfunction perf_event_openfunction perf_event_attr_initfunction perf_event_open_counterfunction perf_event_enablefunction perf_event_disablefunction perf_event_resetfunction using_hash_mmufunction push_signal_handlerfunction pop_signal_handler
Annotated Snippet
if (rc != 0) {
err = -EOVERFLOW;
goto out;
}
}
err = 0;
out:
close(fd);
errno = -err;
return err;
}
int read_file_alloc(const char *path, char **buf, size_t *len)
{
size_t read_offset = 0;
size_t buffer_len = 0;
char *buffer = NULL;
int err;
int fd;
fd = open(path, O_RDONLY);
if (fd < 0)
return -errno;
/*
* We don't use stat & preallocate st_size because some non-files
* report 0 file size. Instead just dynamically grow the buffer
* as needed.
*/
while (1) {
ssize_t rc;
if (read_offset >= buffer_len / 2) {
char *next_buffer;
buffer_len = buffer_len ? buffer_len * 2 : 4096;
next_buffer = realloc(buffer, buffer_len);
if (!next_buffer) {
err = -errno;
goto out;
}
buffer = next_buffer;
}
rc = read(fd, buffer + read_offset, buffer_len - read_offset);
if (rc < 0) {
err = -errno;
goto out;
}
if (rc == 0)
break;
read_offset += rc;
}
*buf = buffer;
if (len)
*len = read_offset;
err = 0;
out:
close(fd);
if (err)
free(buffer);
errno = -err;
return err;
}
int write_file(const char *path, const char *buf, size_t count)
{
int fd;
int err;
ssize_t rc;
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd < 0)
return -errno;
rc = write(fd, buf, count);
if (rc < 0) {
err = -errno;
goto out;
}
if (rc != count) {
err = -EOVERFLOW;
Annotation
- Immediate include surface: `elf.h`, `errno.h`, `fcntl.h`, `inttypes.h`, `limits.h`, `link.h`, `sched.h`, `stdio.h`.
- Detected declarations: `function read_file`, `function read_file_alloc`, `function write_file`, `function read_auxv`, `function read_debugfs_file`, `function write_debugfs_file`, `function validate_int_parse`, `function parse_bounded_int`, `function parse_bounded_uint`, `function parse_intmax`.
- 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.