environment: envfs_{load, save}: add possibility to call with filename and dirname == NULL
This patch moves fallback to default into the envfs_{load,save} functions. Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
85799d1b75
commit
7033089ddf
|
@ -27,7 +27,7 @@ static int do_saveenv(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ret, opt;
|
int ret, opt;
|
||||||
unsigned envfs_flags = 0;
|
unsigned envfs_flags = 0;
|
||||||
char *filename, *dirname;
|
char *filename = NULL, *dirname = NULL;
|
||||||
|
|
||||||
printf("saving environment\n");
|
printf("saving environment\n");
|
||||||
while ((opt = getopt(argc, argv, "z")) > 0) {
|
while ((opt = getopt(argc, argv, "z")) > 0) {
|
||||||
|
@ -39,15 +39,11 @@ static int do_saveenv(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* destination and source are given? */
|
/* destination and source are given? */
|
||||||
if (argc - optind < 2)
|
if (argc - optind > 1)
|
||||||
dirname = "/env";
|
|
||||||
else
|
|
||||||
dirname = argv[optind + 1];
|
dirname = argv[optind + 1];
|
||||||
|
|
||||||
/* destination only given? */
|
/* destination only given? */
|
||||||
if (argc - optind < 1)
|
if (argc - optind > 0)
|
||||||
filename = default_environment_path_get();
|
|
||||||
else
|
|
||||||
filename = argv[optind];
|
filename = argv[optind];
|
||||||
|
|
||||||
ret = envfs_save(filename, dirname, envfs_flags);
|
ret = envfs_save(filename, dirname, envfs_flags);
|
||||||
|
|
|
@ -253,6 +253,12 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
|
||||||
void *buf = NULL, *wbuf;
|
void *buf = NULL, *wbuf;
|
||||||
struct envfs_entry *env;
|
struct envfs_entry *env;
|
||||||
|
|
||||||
|
if (!filename)
|
||||||
|
filename = default_environment_path_get();
|
||||||
|
|
||||||
|
if (!dirname)
|
||||||
|
dirname = "/env";
|
||||||
|
|
||||||
data.writep = NULL;
|
data.writep = NULL;
|
||||||
data.base = dirname;
|
data.base = dirname;
|
||||||
|
|
||||||
|
@ -540,6 +546,12 @@ int envfs_load(const char *filename, const char *dir, unsigned flags)
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
size_t size, rsize;
|
size_t size, rsize;
|
||||||
|
|
||||||
|
if (!filename)
|
||||||
|
filename = default_environment_path_get();
|
||||||
|
|
||||||
|
if (!dir)
|
||||||
|
dir = "/env";
|
||||||
|
|
||||||
envfd = open(filename, O_RDONLY);
|
envfd = open(filename, O_RDONLY);
|
||||||
if (envfd < 0) {
|
if (envfd < 0) {
|
||||||
printf("environment load %s: %s\n", filename, errno_str());
|
printf("environment load %s: %s\n", filename, errno_str());
|
||||||
|
|
Loading…
Reference in New Issue