ldlinux: Use open_config() to open config files
authorMatt Fleming <matt.fleming@linux.intel.com>
Mon, 6 Jun 2011 21:45:33 +0000 (22:45 +0100)
committerMatt Fleming <matt.fleming@linux.intel.com>
Tue, 7 Jun 2011 12:06:25 +0000 (13:06 +0100)
Instead of duplicating the logic for finding config files on different
filesystems in both ldlinux/readconfig.c and core/fs/* use the
open_config() wrapper that calls into the fs-specific open_config().

Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
com32/elflink/ldlinux/readconfig.c

index 8ded92a..7d0dd67 100644 (file)
@@ -11,6 +11,7 @@
  *
  * ----------------------------------------------------------------------- */
 
+#include <fcntl.h>
 #include <stdio.h>
 #include <stdbool.h>
 #include <stdlib.h>
@@ -23,6 +24,7 @@
 #include <syslinux/adv.h>
 #include <syslinux/config.h>
 #include <dprintf.h>
+#include <core.h>
 
 #include "menu.h"
 #include "config.h"
@@ -1138,34 +1140,21 @@ do_include:
 
 static int parse_one_config(const char *filename)
 {
+       const char *mode = "r";
        FILE *f;
+       int fd;
 
-       /*
-       if (!strcmp(filename, "~"))
-               filename = syslinux_config_file();
-       */
-
-       f = fopen(filename, "r");
-       if (f)
-               goto config_found;
-
-       /* force to use hard coded config file name */
-       f = fopen("extlinux.conf", "r");
-       if (f)
-               goto config_found;
-
-       f = fopen("isolinux/isolinux.cfg", "r");
-       if (f)
-               goto config_found;
+       if (!filename)
+               fd = open_config();
+       else
+               fd = open(filename, O_RDONLY);
 
-       f = fopen("syslinux.cfg", "r");
-       if (f)
-               goto config_found;
+       if (fd < 0)
+               return fd;
 
-       return -1;
-config_found:
+       f = fdopen(fd, mode);
        parse_config_file(f);
-       fclose(f);
+
        return 0;
 }
 
@@ -1214,7 +1203,7 @@ void parse_configs(char **argv)
     current_menu = root_menu;
 
     if (!argv || !*argv) {
-       parse_one_config("~");
+       parse_one_config(NULL);
     } else {
        while ((filename = *argv++)) {
                dprintf("Parsing config: %s", filename);