printinitialenv.c 916 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2022
  4. * Max Krummenacher, Toradex
  5. *
  6. * Snippets taken from tools/env/fw_env.c
  7. *
  8. * This prints the list of default environment variables as currently
  9. * configured.
  10. *
  11. */
  12. #include <stdio.h>
  13. /* Pull in the current config to define the default environment */
  14. #include <linux/kconfig.h>
  15. #ifndef __ASSEMBLY__
  16. #define __ASSEMBLY__ /* get only #defines from config.h */
  17. #include <config.h>
  18. #undef __ASSEMBLY__
  19. #else
  20. #include <config.h>
  21. #endif
  22. #define DEFAULT_ENV_INSTANCE_STATIC
  23. #include <generated/environment.h>
  24. #include <env_default.h>
  25. int main(void)
  26. {
  27. char *env, *nxt;
  28. for (env = default_environment; *env; env = nxt + 1) {
  29. for (nxt = env; *nxt; ++nxt) {
  30. if (nxt >= &default_environment[sizeof(default_environment)]) {
  31. fprintf(stderr, "## Error: environment not terminated\n");
  32. return -1;
  33. }
  34. }
  35. printf("%s\n", env);
  36. }
  37. return 0;
  38. }