Releasing debian version 4.04+dfsg-9.
[syslinux-debian/hramrach.git] / core / fs / lib / searchconfig.c
blob24bfde313db438cc23798637800ec6822b942bbe
1 #include <dprintf.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <core.h>
5 #include <fs.h>
7 /*
8 * Common implementation of load_config
10 * This searches for a specified set of filenames in a specified set
11 * of directories. If found, set the current working directory to
12 * match.
14 int search_config(const char *search_directories[], const char *filenames[])
16 char confignamebuf[FILENAME_MAX];
17 com32sys_t regs;
18 const char *sd, **sdp;
19 const char *sf, **sfp;
21 for (sdp = search_directories; (sd = *sdp); sdp++) {
22 for (sfp = filenames; (sf = *sfp); sfp++) {
23 memset(&regs, 0, sizeof regs);
24 snprintf(confignamebuf, sizeof confignamebuf,
25 "%s%s%s",
26 sd, (*sd && sd[strlen(sd)-1] == '/') ? "" : "/",
27 sf);
28 realpath(ConfigName, confignamebuf, FILENAME_MAX);
29 regs.edi.w[0] = OFFS_WRT(ConfigName, 0);
30 dprintf("Config search: %s\n", ConfigName);
31 call16(core_open, &regs, &regs);
32 if (!(regs.eflags.l & EFLAGS_ZF)) {
33 chdir(sd);
34 return 0; /* Got it */
39 return -1;