mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] environment: envfs_{load, save}: add possibility to call with filename and dirname == NULL
@ 2015-03-05 14:37 Marc Kleine-Budde
  2015-03-06  6:44 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Marc Kleine-Budde @ 2015-03-05 14:37 UTC (permalink / raw)
  To: barebox

This patch moves fallback to default into the envfs_{load,save} functions.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 commands/saveenv.c   | 10 +++-------
 common/environment.c | 12 ++++++++++++
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/commands/saveenv.c b/commands/saveenv.c
index 43f16dc49059..6f210b7ec109 100644
--- a/commands/saveenv.c
+++ b/commands/saveenv.c
@@ -27,7 +27,7 @@ static int do_saveenv(int argc, char *argv[])
 {
 	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 @@ static int do_saveenv(int argc, char *argv[])
 	}
 
 	/* 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 7e176b3a7eea..f6fd781a8ab8 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -256,6 +256,12 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 	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;
 
@@ -543,6 +549,12 @@ int envfs_load(const char *filename, const char *dir, unsigned flags)
 	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());
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] environment: envfs_{load, save}: add possibility to call with filename and dirname == NULL
  2015-03-05 14:37 [PATCH] environment: envfs_{load, save}: add possibility to call with filename and dirname == NULL Marc Kleine-Budde
@ 2015-03-06  6:44 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2015-03-06  6:44 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: barebox

On Thu, Mar 05, 2015 at 03:37:14PM +0100, Marc Kleine-Budde wrote:
> This patch moves fallback to default into the envfs_{load,save} functions.
> 
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> ---
>  commands/saveenv.c   | 10 +++-------
>  common/environment.c | 12 ++++++++++++
>  2 files changed, 15 insertions(+), 7 deletions(-)

Applied, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-03-06  6:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-05 14:37 [PATCH] environment: envfs_{load, save}: add possibility to call with filename and dirname == NULL Marc Kleine-Budde
2015-03-06  6:44 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox