genimage: Use absolute pathes

Relative pathes can be error prone when it's not clear to
which path the pathes are relative to. For FIT image support
we have to create pathes that are not relative to the current
directory, but to the path where the current its input file is.

This patch lets imagepath(), inputpath(), rootpath() and tmppath()
return absolute filenames rather than directly the (absolute or
relative) input pathes.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2018-02-15 14:03:58 +01:00 committed by Michael Olbrich
parent cf20713886
commit ab152c7894

View File

@ -20,6 +20,7 @@
#include <stdlib.h>
#include <errno.h>
#include <getopt.h>
#include <unistd.h>
#include "genimage.h"
@ -244,24 +245,56 @@ err_out:
return ret;
}
static char *abspath(const char *path)
{
char *p;
if (*path == '/')
return strdup(path);
xasprintf(&p, "%s/%s", get_current_dir_name(), path);
return p;
}
const char *imagepath(void)
{
return get_opt("outputpath");
static const char *outputpath;
if (!outputpath)
outputpath = abspath(get_opt("outputpath"));
return outputpath;
}
const char *inputpath(void)
{
return get_opt("inputpath");
static const char *inputpath;
if (!inputpath)
inputpath = abspath(get_opt("inputpath"));
return inputpath;
}
const char *rootpath(void)
{
return get_opt("rootpath");
static const char *rootpath;
if (!rootpath)
rootpath = abspath(get_opt("rootpath"));
return rootpath;
}
const char *tmppath(void)
{
return get_opt("tmppath");
static const char *tmppath;
if (!tmppath)
tmppath = abspath(get_opt("tmppath"));
return tmppath;
}
static struct config opts[] = {