MCPcopy Create free account
hub / github.com/coreboot/coreboot / make_data

Function make_data

util/smmstoretool/data.c:115–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113}
114
115void *make_data(const char source[], size_t *data_size, enum data_type type)
116{
117 switch (type) {
118 void *data;
119 bool boolean;
120 uint64_t uint;
121 struct mem_range_t file;
122 bool failed;
123
124 case DATA_TYPE_BOOL:
125 if (str_eq(source, "true")) {
126 boolean = true;
127 } else if (str_eq(source, "false")) {
128 boolean = false;
129 } else {
130 fprintf(stderr, "Invalid boolean value: \"%s\"\n",
131 source);
132 return NULL;
133 }
134
135 *data_size = 1;
136 data = xmalloc(*data_size);
137 *(uint8_t *)data = boolean;
138 return data;
139 case DATA_TYPE_UINT8:
140 uint = parse_uint(source, "uint8", UINT8_MAX, &failed);
141 if (failed)
142 return NULL;
143
144 *data_size = 1;
145 data = xmalloc(*data_size);
146 *(uint8_t *)data = uint;
147 return data;
148 case DATA_TYPE_UINT16:
149 uint = parse_uint(source, "uint16", UINT16_MAX, &failed);
150 if (failed)
151 return NULL;
152
153 *data_size = 2;
154 data = xmalloc(*data_size);
155 *(uint16_t *)data = uint;
156 return data;
157 case DATA_TYPE_UINT32:
158 uint = parse_uint(source, "uint32", UINT32_MAX, &failed);
159 if (failed)
160 return NULL;
161
162 *data_size = 4;
163 data = xmalloc(*data_size);
164 *(uint32_t *)data = uint;
165 return data;
166 case DATA_TYPE_UINT64:
167 uint = parse_uint(source, "uint64", UINT64_MAX, &failed);
168 if (failed)
169 return NULL;
170
171 *data_size = 8;
172 data = xmalloc(*data_size);

Callers 1

process_setFunction · 0.85

Calls 10

str_eqFunction · 0.85
fprintfFunction · 0.85
parse_uintFunction · 0.85
strlenFunction · 0.85
to_ucharsFunction · 0.85
xmallocFunction · 0.70
map_fileFunction · 0.70
unmap_fileFunction · 0.70
strdupFunction · 0.50
memcpyFunction · 0.50

Tested by

no test coverage detected