mirror of
https://github.com/pengutronix/genimage.git
synced 2024-11-23 17:53:52 +08:00
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:
parent
cf20713886
commit
ab152c7894
41
config.c
41
config.c
@ -20,6 +20,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "genimage.h"
|
#include "genimage.h"
|
||||||
|
|
||||||
@ -244,24 +245,56 @@ err_out:
|
|||||||
return ret;
|
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)
|
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)
|
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)
|
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)
|
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[] = {
|
static struct config opts[] = {
|
||||||
|
Loading…
Reference in New Issue
Block a user