scripts/dtc/data.c
Source file repositories/reference/linux-study-clean/scripts/dtc/data.c
File Facts
- System
- Linux kernel
- Corpus path
scripts/dtc/data.c- Extension
.c- Size
- 5340 bytes
- Lines
- 294
- 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
dtc.h
Detected Declarations
function data_freefunction data_grow_forfunction data_copy_memfunction data_copy_escape_stringfunction data_copy_filefunction data_append_datafunction data_insert_at_markerfunction data_append_markersfunction data_mergefunction data_append_integerfunction data_append_refunction data_append_cellfunction data_append_addrfunction data_append_bytefunction data_append_zeroesfunction data_append_alignfunction data_add_markerfunction data_is_one_stringfunction data_insert_data
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
*/
#include "dtc.h"
void data_free(struct data d)
{
struct marker *m, *nm;
m = d.markers;
while (m) {
nm = m->next;
free(m->ref);
free(m);
m = nm;
}
if (d.val)
free(d.val);
}
struct data data_grow_for(struct data d, unsigned int xlen)
{
struct data nd;
unsigned int newsize;
if (xlen == 0)
return d;
nd = d;
newsize = xlen;
while ((d.len + xlen) > newsize)
newsize *= 2;
nd.val = xrealloc(d.val, newsize);
return nd;
}
struct data data_copy_mem(const char *mem, int len)
{
struct data d;
d = data_grow_for(empty_data, len);
d.len = len;
memcpy(d.val, mem, len);
return d;
}
struct data data_copy_escape_string(const char *s, int len)
{
int i = 0;
struct data d;
char *q;
d = data_add_marker(empty_data, TYPE_STRING, NULL);
d = data_grow_for(d, len + 1);
q = d.val;
while (i < len) {
char c = s[i++];
if (c == '\\')
c = get_escape_char(s, &i);
q[d.len++] = c;
}
q[d.len++] = '\0';
return d;
}
struct data data_copy_file(FILE *f, size_t maxlen)
{
struct data d = empty_data;
d = data_add_marker(d, TYPE_NONE, NULL);
while (!feof(f) && (d.len < maxlen)) {
size_t chunksize, ret;
if (maxlen == (size_t)-1)
chunksize = 4096;
else
chunksize = maxlen - d.len;
Annotation
- Immediate include surface: `dtc.h`.
- Detected declarations: `function data_free`, `function data_grow_for`, `function data_copy_mem`, `function data_copy_escape_string`, `function data_copy_file`, `function data_append_data`, `function data_insert_at_marker`, `function data_append_markers`, `function data_merge`, `function data_append_integer`.
- 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.