tools/perf/util/lzma.c
Source file repositories/reference/linux-study-clean/tools/perf/util/lzma.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/lzma.c- Extension
.c- Size
- 2790 bytes
- Lines
- 130
- 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
errno.hlzma.hstdio.hlinux/compiler.hsys/types.hsys/stat.hfcntl.hcompress.hdebug.hstring.hunistd.hinternal/lib.h
Detected Declarations
function lzma_decompress_stream_to_filefunction lzma_decompress_to_filefunction lzma_is_compressed
Annotated Snippet
if (strm.avail_in == 0 && !feof(infile)) {
strm.next_in = buf_in;
strm.avail_in = fread(buf_in, 1, sizeof(buf_in), infile);
if (ferror(infile)) {
pr_debug("lzma: read error: %m\n");
goto err_lzma_end;
}
if (feof(infile))
action = LZMA_FINISH;
}
ret = lzma_code(&strm, action);
if (strm.avail_out == 0 || ret == LZMA_STREAM_END) {
ssize_t write_size = sizeof(buf_out) - strm.avail_out;
if (writen(output_fd, buf_out, write_size) != write_size) {
pr_debug("lzma: write error: %m\n");
goto err_lzma_end;
}
strm.next_out = buf_out;
strm.avail_out = sizeof(buf_out);
}
if (ret != LZMA_OK) {
if (ret == LZMA_STREAM_END)
break;
pr_debug("lzma: failed %s\n", lzma_strerror(ret));
goto err_lzma_end;
}
}
err = 0;
err_lzma_end:
lzma_end(&strm);
return err;
}
int lzma_decompress_to_file(const char *input, int output_fd)
{
FILE *infile;
int ret;
infile = fopen(input, "rb");
if (!infile) {
pr_debug("lzma: fopen failed on %s: '%m'\n", input);
return -1;
}
ret = lzma_decompress_stream_to_file(infile, output_fd);
fclose(infile);
return ret;
}
bool lzma_is_compressed(const char *input)
{
int fd = open(input, O_RDONLY);
const uint8_t magic[6] = { 0xFD, '7', 'z', 'X', 'Z', 0x00 };
char buf[6] = { 0 };
ssize_t rc;
if (fd < 0)
return false;
rc = read(fd, buf, sizeof(buf));
close(fd);
return rc == sizeof(buf) ?
memcmp(buf, magic, sizeof(buf)) == 0 : false;
}
Annotation
- Immediate include surface: `errno.h`, `lzma.h`, `stdio.h`, `linux/compiler.h`, `sys/types.h`, `sys/stat.h`, `fcntl.h`, `compress.h`.
- Detected declarations: `function lzma_decompress_stream_to_file`, `function lzma_decompress_to_file`, `function lzma_is_compressed`.
- 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.