From: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] tools/env: allow to pass NULL for environment options
Date: Tue, 31 May 2016 09:21:56 +0200 [thread overview]
Message-ID: <1464679316-28752-1-git-send-email-andreas.fenkart@digitalstrom.com> (raw)
If users of the library are happy with the default, e.g. config file
name. They can pass NULL as the opts pointer. This simplifies the
transition of existing library users.
FIXES a compile error. since common_args has been removed by
a previous patch
Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
---
tools/env/fw_env.c | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 52e0bec..692abda 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -35,6 +35,12 @@
#include "fw_env.h"
+struct env_opts default_opts = {
+#ifdef CONFIG_FILE
+ .config_file = CONFIG_FILE
+#endif
+};
+
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
#define min(x, y) ({ \
@@ -229,6 +235,9 @@ int fw_printenv(int argc, char *argv[], int value_only, struct env_opts *opts)
char *env, *nxt;
int i, rc = 0;
+ if (!opts)
+ opts = &default_opts;
+
if (fw_env_open(opts))
return -1;
@@ -289,6 +298,9 @@ int fw_env_close(struct env_opts *opts)
{
int ret;
+ if (!opts)
+ opts = &default_opts;
+
if (opts->aes_flag) {
ret = env_aes_cbc_crypt(environment.data, 1,
opts->aes_key);
@@ -452,6 +464,9 @@ int fw_setenv(int argc, char *argv[], struct env_opts *opts)
char *value = NULL;
int valc;
+ if (!opts)
+ opts = &default_opts;
+
if (argc < 1) {
fprintf(stderr, "## Error: variable name missing\n");
errno = EINVAL;
@@ -524,6 +539,9 @@ int fw_parse_script(char *fname, struct env_opts *opts)
int len;
int ret = 0;
+ if (!opts)
+ opts = &default_opts;
+
if (fw_env_open(opts)) {
fprintf(stderr, "Error: environment not initialized\n");
return -1;
@@ -1139,6 +1157,9 @@ int fw_env_open(struct env_opts *opts)
struct env_image_single *single;
struct env_image_redundant *redundant;
+ if (!opts)
+ opts = &default_opts;
+
if (parse_config(opts)) /* should fill envdevices */
return -1;
@@ -1312,10 +1333,10 @@ static int parse_config(struct env_opts *opts)
{
struct stat st;
-#if defined(CONFIG_FILE)
- if (!common_args.config_file)
- common_args.config_file = CONFIG_FILE;
+ if (!opts)
+ opts = &default_opts;
+#if defined(CONFIG_FILE)
/* Fills in DEVNAME(), ENVSIZE(), DEVESIZE(). Or don't. */
if (get_config(opts->config_file)) {
fprintf(stderr, "Cannot parse config file '%s': %m\n",
--
2.8.1
next reply other threads:[~2016-05-31 7:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-31 7:21 Andreas Fenkart [this message]
2016-05-31 14:50 ` [U-Boot] [PATCH] tools/env: allow to pass NULL for environment options Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1464679316-28752-1-git-send-email-andreas.fenkart@digitalstrom.com \
--to=andreas.fenkart@digitalstrom.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox