MCPcopy Create free account
hub / github.com/apache/nuttx / find_variable

Function find_variable

tools/initialconfig.c:247–303  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

245 ****************************************************************************/
246
247static bool find_variable(const char *configpath, const char *varname,
248 char **varvalue)
249{
250 FILE *stream;
251 char *tmpname;
252 char *tmpvalue;
253 char *ptr;
254
255 stream = fopen(configpath, "r");
256 if (!stream)
257 {
258 fprintf(stderr, "ERROR: failed to open %s for reading: %s\n",
259 configpath, strerror(errno));
260 exit(EXIT_FAILURE);
261 }
262
263 /* Loop until the entire file has been parsed. */
264
265 do
266 {
267 /* Read the next line from the file */
268
269 ptr = read_line(stream);
270 if (ptr)
271 {
272 /* Parse the line into a variable and a value field */
273
274 tmpname = NULL;
275 tmpvalue = NULL;
276 parse_line(ptr, &tmpname, &tmpvalue);
277
278 /* Make sure that both a variable name and value name were found. */
279
280 if (tmpname == NULL || tmpvalue == NULL)
281 {
282 continue;
283 }
284
285 /* Check if this the variable name and value we are looking for */
286
287 if (strcmp(varname, tmpname) == 0)
288 {
289 /* Yes.. return the value of the variable */
290
291 *varvalue = tmpvalue;
292 fclose(stream);
293 return true;
294 }
295 }
296 }
297 while (ptr);
298
299 /* Return failure */
300
301 fclose(stream);
302 return false;
303}
304

Callers 2

check_variableFunction · 0.70

Calls 8

fopenFunction · 0.85
fprintfFunction · 0.85
strerrorFunction · 0.85
exitFunction · 0.85
fcloseFunction · 0.85
read_lineFunction · 0.70
parse_lineFunction · 0.70
strcmpFunction · 0.50

Tested by

no test coverage detected