dmi: check both the AC and ID flags at the same time
[syslinux.git] / core / fs / lib / searchconfig.c
blobbb1dabf98c24b5e067e502dc0ed8048925e32393
1 #include <dprintf.h>
2 #include <fcntl.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <core.h>
6 #include <fs.h>
8 __export char ConfigName[FILENAME_MAX];
9 __export char config_cwd[FILENAME_MAX];
12 * This searches for a specified set of filenames in a specified set
13 * of directories. If found, set the current working directory to
14 * match.
16 int search_dirs(struct com32_filedata *filedata,
17 const char *search_directories[],
18 const char *filenames[],
19 char *realname)
21 char namebuf[FILENAME_MAX];
22 const char *sd, **sdp;
23 const char *sf, **sfp;
25 for (sdp = search_directories; (sd = *sdp); sdp++) {
26 for (sfp = filenames; (sf = *sfp); sfp++) {
27 snprintf(namebuf, sizeof namebuf,
28 "%s%s%s",
29 sd, (*sd && sd[strlen(sd)-1] == '/') ? "" : "/",
30 sf);
31 if (realpath(realname, namebuf, FILENAME_MAX) == (size_t)-1)
32 continue;
33 dprintf("Config search: %s\n", realname);
34 if (open_file(realname, O_RDONLY, filedata) >= 0) {
35 chdir(sd);
36 return 0; /* Got it */
41 return -1;