diff options
Diffstat (limited to 'contrib/syslinux-4.02/core/fs/lib/searchconfig.c')
-rw-r--r-- | contrib/syslinux-4.02/core/fs/lib/searchconfig.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/contrib/syslinux-4.02/core/fs/lib/searchconfig.c b/contrib/syslinux-4.02/core/fs/lib/searchconfig.c new file mode 100644 index 0000000..24bfde3 --- /dev/null +++ b/contrib/syslinux-4.02/core/fs/lib/searchconfig.c @@ -0,0 +1,40 @@ +#include <dprintf.h> +#include <stdio.h> +#include <string.h> +#include <core.h> +#include <fs.h> + +/* + * Common implementation of load_config + * + * This searches for a specified set of filenames in a specified set + * of directories. If found, set the current working directory to + * match. + */ +int search_config(const char *search_directories[], const char *filenames[]) +{ + char confignamebuf[FILENAME_MAX]; + com32sys_t regs; + const char *sd, **sdp; + const char *sf, **sfp; + + for (sdp = search_directories; (sd = *sdp); sdp++) { + for (sfp = filenames; (sf = *sfp); sfp++) { + memset(®s, 0, sizeof regs); + snprintf(confignamebuf, sizeof confignamebuf, + "%s%s%s", + sd, (*sd && sd[strlen(sd)-1] == '/') ? "" : "/", + sf); + realpath(ConfigName, confignamebuf, FILENAME_MAX); + regs.edi.w[0] = OFFS_WRT(ConfigName, 0); + dprintf("Config search: %s\n", ConfigName); + call16(core_open, ®s, ®s); + if (!(regs.eflags.l & EFLAGS_ZF)) { + chdir(sd); + return 0; /* Got it */ + } + } + } + + return -1; +} |