]> git.ozlabs.org Git - petitboot/commitdiff
Remove duplicate prepend_mountpoint() functions.
authorJeremy Kerr <jk@ozlabs.org>
Wed, 4 Apr 2007 09:48:11 +0000 (19:48 +1000)
committerJeremy Kerr <jk@ozlabs.org>
Wed, 4 Apr 2007 09:48:11 +0000 (19:48 +1000)
Replace prepend_mountpoint() with join_paths(), and make it available
to all parsers, instead of duplicating it in each.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
devices/native-parser.c
devices/udev-helper.c
devices/udev-helper.h
devices/yaboot-parser.c

index bb1ca51e3e3e720bc9ab81588eb28dddd4d0e70a..4f94d9da343cda29d9298bc23e4a42f19f16ebe3 100644 (file)
@@ -13,20 +13,6 @@ static struct device *dev;
 static const char *mountpoint;
 int device_added;
 
 static const char *mountpoint;
 int device_added;
 
-static char *prepend_mountpoint(const char *path)
-{
-       char *full_path;
-
-       full_path = malloc(strlen(path) + strlen(mountpoint) + 2);
-
-       strcpy(full_path, mountpoint);
-       if (path[0] != '/')
-               strcat(full_path, "/");
-       strcat(full_path, path);
-
-       return full_path;
-}
-
 int check_and_add_device(struct device *dev)
 {
        if (!dev->icon_file)
 int check_and_add_device(struct device *dev)
 {
        if (!dev->icon_file)
@@ -61,13 +47,13 @@ static void set_boot_option_parameter(struct boot_option *opt,
                opt->description = strdup(value);
 
        else if (streq(name, "image"))
                opt->description = strdup(value);
 
        else if (streq(name, "image"))
-               opt->boot_image_file = prepend_mountpoint(value);
+               opt->boot_image_file = join_paths(mountpoint, value);
 
        else if (streq(name, "icon"))
 
        else if (streq(name, "icon"))
-               opt->icon_file = prepend_mountpoint(value);
+               opt->icon_file = join_paths(mountpoint, value);
 
        else if (streq(name, "initrd"))
 
        else if (streq(name, "initrd"))
-               opt->initrd_file = prepend_mountpoint(value);
+               opt->initrd_file = join_paths(mountpoint, value);
 
        else if (streq(name, "args"))
                opt->boot_args = strdup(value);
 
        else if (streq(name, "args"))
                opt->boot_args = strdup(value);
@@ -86,7 +72,7 @@ static void set_device_parameter(struct device *dev,
                dev->description = strdup(value);
 
        else if (streq(name, "icon"))
                dev->description = strdup(value);
 
        else if (streq(name, "icon"))
-               dev->icon_file = prepend_mountpoint(value);
+               dev->icon_file = join_paths(mountpoint, value);
 }
 
 static int parameter(char *param_name, char *param_value)
 }
 
 static int parameter(char *param_name, char *param_value)
@@ -106,7 +92,7 @@ int parse(const char *devicepath, const char *_mountpoint)
 
        mountpoint = _mountpoint;
 
 
        mountpoint = _mountpoint;
 
-       filepath = prepend_mountpoint(conf_filename);
+       filepath = join_paths(mountpoint, conf_filename);
 
        cur_opt = NULL;
        dev = malloc(sizeof(*dev));
 
        cur_opt = NULL;
        dev = malloc(sizeof(*dev));
index c113e55432177217c7fc144ded1b9e4ddc11ce69..da12129316142814462162674d4e7aabdd69513f 100644 (file)
@@ -568,3 +568,19 @@ int main(int argc, char **argv)
        }
        return rc;
 }
        }
        return rc;
 }
+
+/* convenience function for parsers */
+char *join_paths(const char *a, const char *b)
+{
+       char *full_path;
+
+       full_path = malloc(strlen(a) + strlen(b) + 2);
+
+       strcpy(full_path, a);
+       if (b[0] != '/')
+               strcat(full_path, "/");
+       strcat(full_path, b);
+
+       return full_path;
+}
+
index 10e5d2b032d28e39bc2953c32ea400f5c1885abd..6b9ba9d7c3b4bdcb5ce5465ec68a5a8f4fef76c6 100644 (file)
@@ -6,6 +6,8 @@ int add_device(const struct device *dev);
 int add_boot_option(const struct boot_option *opt);
 void free_boot_option(struct boot_option *opt);
 
 int add_boot_option(const struct boot_option *opt);
 void free_boot_option(struct boot_option *opt);
 
+char *join_paths(const char *a, const char *b);
+
 int mount_device(const char *dev_path, char *mount_path);
 
 struct parser {
 int mount_device(const char *dev_path, char *mount_path);
 
 struct parser {
index ee1b992dca0b17e56edee06af3fc4687828c1d53..ee14cb1b41d144fcbcf1e59cd35791c8cff3a45a 100644 (file)
@@ -86,20 +86,6 @@ make_params(char *label, char *params)
      return buffer;
 }
 
      return buffer;
 }
 
-static char *prepend_mountpoint(const char *path)
-{
-       char *full_path;
-
-       full_path = malloc(strlen(path) + strlen(mountpoint) + 2);
-
-       strcpy(full_path, mountpoint);
-       if (path[0] != '/')
-               strcat(full_path, "/");
-       strcat(full_path, path);
-
-       return full_path;
-}
-
 static int check_and_add_device(struct device *dev)
 {
        if (!dev->icon_file)
 static int check_and_add_device(struct device *dev)
 {
        if (!dev->icon_file)
@@ -117,13 +103,13 @@ void process_image(char *label)
 
        opt.name = label;
        cfgopt = cfg_get_strg(label, "image");
 
        opt.name = label;
        cfgopt = cfg_get_strg(label, "image");
-       opt.boot_image_file = prepend_mountpoint(cfgopt);
+       opt.boot_image_file = join_paths(mountpoint, cfgopt);
        if (cfgopt == defimage)
                printf("This one is default. What do we do about it?\n");
 
        cfgopt = cfg_get_strg(label, "initrd");
        if (cfgopt)
        if (cfgopt == defimage)
                printf("This one is default. What do we do about it?\n");
 
        cfgopt = cfg_get_strg(label, "initrd");
        if (cfgopt)
-               opt.initrd_file = prepend_mountpoint(cfgopt);
+               opt.initrd_file = join_paths(mountpoint, cfgopt);
 
        opt.boot_args = make_params(label, NULL);
 
 
        opt.boot_args = make_params(label, NULL);
 
@@ -145,12 +131,12 @@ static int yaboot_parse(const char *devicepath, const char *_mountpoint)
 
        mountpoint = _mountpoint;
 
 
        mountpoint = _mountpoint;
 
-       filepath = prepend_mountpoint("/etc/yaboot.conf");
+       filepath = join_paths(mountpoint, "/etc/yaboot.conf");
 
        fd = open(filepath, O_RDONLY);
        if (fd < 0) {
                free(filepath);
 
        fd = open(filepath, O_RDONLY);
        if (fd < 0) {
                free(filepath);
-               filepath = prepend_mountpoint("/yaboot.conf");
+               filepath = join_paths(mountpoint, "/yaboot.conf");
                fd = open(filepath, O_RDONLY);
                
                if (fd < 0)
                fd = open(filepath, O_RDONLY);
                
                if (fd < 0)