Commit 14070e69ad6d01abf65c06150dc9302bca1b7973

Authored by Andreas Fenkart
Committed by Tom Rini
1 parent 6f41751f46

tools/env: allow to pass NULL for environment options

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>

Showing 1 changed file with 24 additions and 3 deletions Side-by-side Diff

... ... @@ -35,6 +35,12 @@
35 35  
36 36 #include "fw_env.h"
37 37  
  38 +struct env_opts default_opts = {
  39 +#ifdef CONFIG_FILE
  40 + .config_file = CONFIG_FILE
  41 +#endif
  42 +};
  43 +
38 44 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
39 45  
40 46 #define min(x, y) ({ \
... ... @@ -229,6 +235,9 @@
229 235 char *env, *nxt;
230 236 int i, rc = 0;
231 237  
  238 + if (!opts)
  239 + opts = &default_opts;
  240 +
232 241 if (fw_env_open(opts))
233 242 return -1;
234 243  
... ... @@ -289,6 +298,9 @@
289 298 {
290 299 int ret;
291 300  
  301 + if (!opts)
  302 + opts = &default_opts;
  303 +
292 304 if (opts->aes_flag) {
293 305 ret = env_aes_cbc_crypt(environment.data, 1,
294 306 opts->aes_key);
... ... @@ -452,6 +464,9 @@
452 464 char *value = NULL;
453 465 int valc;
454 466  
  467 + if (!opts)
  468 + opts = &default_opts;
  469 +
455 470 if (argc < 1) {
456 471 fprintf(stderr, "## Error: variable name missing\n");
457 472 errno = EINVAL;
... ... @@ -524,6 +539,9 @@
524 539 int len;
525 540 int ret = 0;
526 541  
  542 + if (!opts)
  543 + opts = &default_opts;
  544 +
527 545 if (fw_env_open(opts)) {
528 546 fprintf(stderr, "Error: environment not initialized\n");
529 547 return -1;
... ... @@ -1139,6 +1157,9 @@
1139 1157 struct env_image_single *single;
1140 1158 struct env_image_redundant *redundant;
1141 1159  
  1160 + if (!opts)
  1161 + opts = &default_opts;
  1162 +
1142 1163 if (parse_config(opts)) /* should fill envdevices */
1143 1164 return -1;
1144 1165  
1145 1166  
... ... @@ -1312,10 +1333,10 @@
1312 1333 {
1313 1334 struct stat st;
1314 1335  
1315   -#if defined(CONFIG_FILE)
1316   - if (!common_args.config_file)
1317   - common_args.config_file = CONFIG_FILE;
  1336 + if (!opts)
  1337 + opts = &default_opts;
1318 1338  
  1339 +#if defined(CONFIG_FILE)
1319 1340 /* Fills in DEVNAME(), ENVSIZE(), DEVESIZE(). Or don't. */
1320 1341 if (get_config(opts->config_file)) {
1321 1342 fprintf(stderr, "Cannot parse config file '%s': %m\n",