tools/testing/selftests/kvm/lib/guest_sprintf.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/lib/guest_sprintf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/lib/guest_sprintf.c- Extension
.c- Size
- 6348 bytes
- Lines
- 315
- 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
test_util.hkvm_util.hucall_common.h
Detected Declarations
function isdigitfunction skip_atoifunction guest_vsnprintffunction guest_snprintf
Annotated Snippet
if (num < 0) {
sign = '-';
num = -num;
size--;
} else if (type & PLUS) {
sign = '+';
size--;
} else if (type & SPACE) {
sign = ' ';
size--;
}
}
if (type & SPECIAL) {
if (base == 16)
size -= 2;
else if (base == 8)
size--;
}
i = 0;
if (num == 0)
tmp[i++] = '0';
else
while (num != 0)
tmp[i++] = (digits[__do_div(num, base)] | locase);
if (i > precision)
precision = i;
size -= precision;
if (!(type & (ZEROPAD + LEFT)))
while (size-- > 0)
APPEND_BUFFER_SAFE(str, end, ' ');
if (sign)
APPEND_BUFFER_SAFE(str, end, sign);
if (type & SPECIAL) {
if (base == 8)
APPEND_BUFFER_SAFE(str, end, '0');
else if (base == 16) {
APPEND_BUFFER_SAFE(str, end, '0');
APPEND_BUFFER_SAFE(str, end, 'x');
}
}
if (!(type & LEFT))
while (size-- > 0)
APPEND_BUFFER_SAFE(str, end, c);
while (i < precision--)
APPEND_BUFFER_SAFE(str, end, '0');
while (i-- > 0)
APPEND_BUFFER_SAFE(str, end, tmp[i]);
while (size-- > 0)
APPEND_BUFFER_SAFE(str, end, ' ');
return str;
}
int guest_vsnprintf(char *buf, int n, const char *fmt, va_list args)
{
char *str, *end;
const char *s;
u64 num;
int i, base;
int len;
int flags; /* flags to number() */
int field_width; /* width of output field */
int precision; /*
* min. # of digits for integers; max
* number of chars for from string
*/
int qualifier; /* 'h', 'l', or 'L' for integer fields */
end = buf + n;
GUEST_ASSERT(buf < end);
GUEST_ASSERT(n > 0);
for (str = buf; *fmt; ++fmt) {
if (*fmt != '%') {
APPEND_BUFFER_SAFE(str, end, *fmt);
continue;
}
/* process flags */
flags = 0;
repeat:
++fmt; /* this also skips first '%' */
switch (*fmt) {
case '-':
flags |= LEFT;
goto repeat;
case '+':
flags |= PLUS;
Annotation
- Immediate include surface: `test_util.h`, `kvm_util.h`, `ucall_common.h`.
- Detected declarations: `function isdigit`, `function skip_atoi`, `function guest_vsnprintf`, `function guest_snprintf`.
- 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.