diff --git a/commands/saveenv.c b/commands/saveenv.c index 43f16dc..6f210b7 100644 --- a/commands/saveenv.c +++ b/commands/saveenv.c @@ -27,7 +27,7 @@ { int ret, opt; unsigned envfs_flags = 0; - char *filename, *dirname; + char *filename = NULL, *dirname = NULL; printf("saving environment\n"); while ((opt = getopt(argc, argv, "z")) > 0) { @@ -39,15 +39,11 @@ } /* destination and source are given? */ - if (argc - optind < 2) - dirname = "/env"; - else + if (argc - optind > 1) dirname = argv[optind + 1]; /* destination only given? */ - if (argc - optind < 1) - filename = default_environment_path_get(); - else + if (argc - optind > 0) filename = argv[optind]; ret = envfs_save(filename, dirname, envfs_flags); diff --git a/common/environment.c b/common/environment.c index 2639411..eed4833 100644 --- a/common/environment.c +++ b/common/environment.c @@ -253,6 +253,12 @@ void *buf = NULL, *wbuf; struct envfs_entry *env; + if (!filename) + filename = default_environment_path_get(); + + if (!dirname) + dirname = "/env"; + data.writep = NULL; data.base = dirname; @@ -540,6 +546,12 @@ int ret = 0; size_t size, rsize; + if (!filename) + filename = default_environment_path_get(); + + if (!dir) + dir = "/env"; + envfd = open(filename, O_RDONLY); if (envfd < 0) { printf("environment load %s: %s\n", filename, errno_str());