MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / loadConfigFile

Function loadConfigFile

Trash/stringTable.c:381–414  ·  view source on GitHub ↗

* Returns 0 if file loaded OK, * -1 if file was not loaded * Does not print error messages. * Returns pointer to table in memory in *table. */

Source from the content-addressed store, hash-verified

379 * Returns pointer to table in memory in *table.
380 */
381int
382loadConfigFile( char *configFile, char **table, INTN allocTable)
383{
384 char *configPtr = bootArgs->configEnd;
385 INTN fd, count;
386
387 /* Read config file into memory */
388 if ((fd = open(configFile, 0)) >= 0)
389 {
390 if (allocTable) {
391 configPtr = malloc(file_size(fd)+2);
392 } else {
393 if ((configPtr - bootArgs->config) > CONFIG_SIZE) {
394 error("No room in memory for config file %s\n",configFile);
395 close(fd);
396 return -1;
397 }
398 localPrintf("Reading config: %s\n",configFile);
399 }
400 if (table) *table = configPtr;
401 count = read(fd, configPtr, IO_CONFIG_DATA_SIZE);
402 close(fd);
403
404 configPtr += count;
405 *configPtr++ = 0;
406 *configPtr = 0;
407 if (!allocTable)
408 bootArgs->configEnd = configPtr;
409
410 return 0;
411 } else {
412 return -1;
413 }
414}
415
416/* Returns 0 if requested config files were loaded,
417 * 1 if default files were loaded,

Callers 2

loadConfigDirFunction · 0.85
loadSystemConfigFunction · 0.85

Calls 4

closeFunction · 0.85
readFunction · 0.85
mallocFunction · 0.50
errorFunction · 0.50

Tested by

no test coverage detected