scripts/dtc/util.c
Source file repositories/reference/linux-study-clean/scripts/dtc/util.c
File Facts
- System
- Linux kernel
- Corpus path
scripts/dtc/util.c- Extension
.c- Size
- 9075 bytes
- Lines
- 496
- Domain
- Support Tooling And Documentation
- Bucket
- scripts
- 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
ctype.hstdio.hstdlib.hstdarg.hstring.hassert.hinttypes.herrno.hfcntl.hunistd.hlibfdt.hutil.hversion_gen.h
Detected Declarations
function fprint_path_escapedfunction xavsprintf_appendfunction xasprintf_appendfunction xasprintffunction util_is_printable_stringfunction get_oct_charfunction get_hex_charfunction get_escape_charfunction utilfdt_read_errfunction utilfdt_write_errfunction utilfdt_writefunction utilfdt_decode_typefunction utilfdt_print_datafunction util_versionfunction util_usage
Annotated Snippet
if (*p == ' ') {
fputc('\\', fp);
fputc(' ', fp);
} else {
fputc(*p, fp);
}
p++;
}
}
char *xstrdup(const char *s)
{
int len = strlen(s) + 1;
char *d = xmalloc(len);
memcpy(d, s, len);
return d;
}
char *xstrndup(const char *s, size_t n)
{
size_t len = strnlen(s, n) + 1;
char *d = xmalloc(len);
memcpy(d, s, len - 1);
d[len - 1] = '\0';
return d;
}
int xavsprintf_append(char **strp, const char *fmt, va_list ap)
{
int n, size = 0; /* start with 128 bytes */
char *p;
va_list ap_copy;
p = *strp;
if (p)
size = strlen(p);
va_copy(ap_copy, ap);
n = vsnprintf(NULL, 0, fmt, ap_copy) + 1;
va_end(ap_copy);
p = xrealloc(p, size + n);
n = vsnprintf(p + size, n, fmt, ap);
*strp = p;
return strlen(p);
}
int xasprintf_append(char **strp, const char *fmt, ...)
{
int n;
va_list ap;
va_start(ap, fmt);
n = xavsprintf_append(strp, fmt, ap);
va_end(ap);
return n;
}
int xasprintf(char **strp, const char *fmt, ...)
{
int n;
va_list ap;
*strp = NULL;
va_start(ap, fmt);
n = xavsprintf_append(strp, fmt, ap);
va_end(ap);
return n;
}
char *join_path(const char *path, const char *name)
{
int lenp = strlen(path);
int lenn = strlen(name);
int len;
int needslash = 1;
char *str;
len = lenp + lenn + 2;
if ((lenp > 0) && (path[lenp-1] == '/')) {
Annotation
- Immediate include surface: `ctype.h`, `stdio.h`, `stdlib.h`, `stdarg.h`, `string.h`, `assert.h`, `inttypes.h`, `errno.h`.
- Detected declarations: `function fprint_path_escaped`, `function xavsprintf_append`, `function xasprintf_append`, `function xasprintf`, `function util_is_printable_string`, `function get_oct_char`, `function get_hex_char`, `function get_escape_char`, `function utilfdt_read_err`, `function utilfdt_write_err`.
- Atlas domain: Support Tooling And Documentation / scripts.
- 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.