summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
44722ec)
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>
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)
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);
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)
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));
+
+/* 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;
+}
+
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 {
-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)
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);
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)