Adding upstream version 4.01+dfsg.
[syslinux-debian/hramrach.git] / core / fs / lib / loadconfig.c
blob356d5a2e5c06574f15b9a8a963f60a144de1f48c
1 #include <dprintf.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <core.h>
5 #include <fs.h>
7 /*
8 * Standard version of load_config for extlinux/syslinux filesystems.
10 * This searches for extlinux.conf and syslinux.cfg in the install
11 * directory, followed by a set of fallback directories. If found,
12 * set the current working directory to match.
14 int generic_load_config(void)
16 static const char *search_directories[] = {
17 NULL, /* CurrentDirName */
18 "/boot/syslinux",
19 "/syslinux",
20 "/",
21 NULL
23 static const char *filenames[] = {
24 "extlinux.conf",
25 "syslinux.cfg",
26 NULL
28 com32sys_t regs;
29 int i, j;
31 search_directories[0] = CurrentDirName;
33 dprintf("CurrentDirName: \"%s\"\n", CurrentDirName);
35 for (i = *CurrentDirName ? 0 : 1; search_directories[i]; i++) {
36 const char *sd = search_directories[i];
37 for (j = 0; filenames[j]; j++) {
38 memset(&regs, 0, sizeof regs);
39 snprintf(ConfigName, FILENAME_MAX, "%s%s%s",
40 sd, (*sd && sd[strlen(sd)-1] == '/') ? "" : "/",
41 filenames[j]);
42 regs.edi.w[0] = OFFS_WRT(ConfigName, 0);
43 dprintf("Config search: %s\n", ConfigName);
44 call16(core_open, &regs, &regs);
45 if (!(regs.eflags.l & EFLAGS_ZF)) {
46 chdir(search_directories[i]);
47 return 0; /* Got it */
52 return -1;