Returns 0 if requested config files were loaded, * 1 if default files were loaded, * -1 if no files were loaded. * Prints error message if files cannot be loaded. */
| 472 | * Prints error message if files cannot be loaded. |
| 473 | */ |
| 474 | int |
| 475 | loadSystemConfig( |
| 476 | char *which, |
| 477 | INTN size |
| 478 | ) |
| 479 | { |
| 480 | char *buf, *bp, *cp; |
| 481 | INTN ret, len, doDefault=0; |
| 482 | |
| 483 | buf = bp = malloc(256); |
| 484 | if (which && size) |
| 485 | { |
| 486 | for(cp = which, len = size; len && *cp && *cp != LP; cp++, len--) ; |
| 487 | if (*cp == LP) { |
| 488 | while (len-- && *cp && *cp++ != RP) ; |
| 489 | /* cp now points past device */ |
| 490 | strncpy(buf,which,cp - which); |
| 491 | bp += cp - which; |
| 492 | } else { |
| 493 | cp = which; |
| 494 | len = size; |
| 495 | } |
| 496 | if (*cp != '/') { |
| 497 | strcpy(bp, IO_SYSTEM_CONFIG_DIR); |
| 498 | strncat(bp, cp, len); |
| 499 | if (strncmp(cp + len - strlen(IO_TABLE_EXTENSION), |
| 500 | IO_TABLE_EXTENSION, strlen(IO_TABLE_EXTENSION)) != 0) |
| 501 | strcat(bp, IO_TABLE_EXTENSION); |
| 502 | } else { |
| 503 | strncpy(bp, cp, len); |
| 504 | bp[size] = '\0'; |
| 505 | } |
| 506 | if (strcmp(bp, SYSTEM_DEFAULT_FILE) == 0) |
| 507 | doDefault = 1; |
| 508 | ret = loadConfigFile(bp = buf, 0, 0); |
| 509 | } else { |
| 510 | ret = loadConfigDir((bp = SYSTEM_CONFIG), 0, 0, 0); |
| 511 | } |
| 512 | if (ret < 0) { |
| 513 | error("System config file '%s' not found\n", bp); |
| 514 | } else |
| 515 | sysConfigValid = 1; |
| 516 | free(buf); |
| 517 | return (ret < 0 ? ret : doDefault); |
| 518 | } |
| 519 | |
| 520 | |
| 521 | int |
nothing calls this directly
no test coverage detected