tools/perf/util/strbuf.c
Source file repositories/reference/linux-study-clean/tools/perf/util/strbuf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/strbuf.c- Extension
.c- Size
- 3218 bytes
- Lines
- 171
- 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
cache.hdebug.hstrbuf.hlinux/kernel.hlinux/string.hlinux/zalloc.herrno.hstdio.hstdlib.hunistd.h
Detected Declarations
function strbuf_initfunction strbuf_releasefunction strbuf_growfunction strbuf_addchfunction strbuf_addfunction strbuf_addvfunction strbuf_addffunction strbuf_read
Annotated Snippet
if (ret) {
va_end(ap_saved);
return ret;
}
len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap_saved);
if (len > strbuf_avail(sb)) {
pr_debug("this should not happen, your vsnprintf is broken");
va_end(ap_saved);
return -EINVAL;
}
}
va_end(ap_saved);
return strbuf_setlen(sb, sb->len + len);
}
int strbuf_addf(struct strbuf *sb, const char *fmt, ...)
{
va_list ap;
int ret;
va_start(ap, fmt);
ret = strbuf_addv(sb, fmt, ap);
va_end(ap);
return ret;
}
ssize_t strbuf_read(struct strbuf *sb, int fd, ssize_t hint)
{
size_t oldlen = sb->len;
size_t oldalloc = sb->alloc;
int ret;
ret = strbuf_grow(sb, hint ? hint : 8192);
if (ret)
return ret;
for (;;) {
ssize_t cnt;
cnt = read(fd, sb->buf + sb->len, sb->alloc - sb->len - 1);
if (cnt < 0) {
if (oldalloc == 0)
strbuf_release(sb);
else
strbuf_setlen(sb, oldlen);
return cnt;
}
if (!cnt)
break;
sb->len += cnt;
ret = strbuf_grow(sb, 8192);
if (ret)
return ret;
}
sb->buf[sb->len] = '\0';
return sb->len - oldlen;
}
Annotation
- Immediate include surface: `cache.h`, `debug.h`, `strbuf.h`, `linux/kernel.h`, `linux/string.h`, `linux/zalloc.h`, `errno.h`, `stdio.h`.
- Detected declarations: `function strbuf_init`, `function strbuf_release`, `function strbuf_grow`, `function strbuf_addch`, `function strbuf_add`, `function strbuf_addv`, `function strbuf_addf`, `function strbuf_read`.
- 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.