diff mbox

[3/4] nvram: add nvram_query_def()

Message ID 1475038592-24094-3-git-send-email-oohall@gmail.com
State Deferred
Headers show

Commit Message

Oliver O'Halloran Sept. 28, 2016, 4:56 a.m. UTC
Adds a helper function that will return a default value if the key is
not found in the skiboot NVRAM partition.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 core/nvram-format.c | 10 ++++++++++
 include/nvram.h     |  1 +
 2 files changed, 11 insertions(+)

Comments

Stewart Smith Oct. 16, 2016, 11:38 p.m. UTC | #1
Oliver O'Halloran <oohall@gmail.com> writes:
> Adds a helper function that will return a default value if the key is
> not found in the skiboot NVRAM partition.
>
> Signed-off-by: Oliver O'Halloran <oohall@gmail.com>

I've ended up holding off merging this just because we don't *currently*
have a user.
diff mbox

Patch

diff --git a/core/nvram-format.c b/core/nvram-format.c
index b110d804ffb7..7ebfef72dd98 100644
--- a/core/nvram-format.c
+++ b/core/nvram-format.c
@@ -273,3 +273,13 @@  bool nvram_query_eq(const char *key, const char *value)
 
 	return !strcmp(s, value);
 }
+
+const char *nvram_query_def(const char *key, const char *def)
+{
+	const char *s = nvram_query(key);
+
+	if (!s)
+		return def;
+
+	return s;
+}
diff --git a/include/nvram.h b/include/nvram.h
index 288b536827b5..1be771ec9a52 100644
--- a/include/nvram.h
+++ b/include/nvram.h
@@ -23,6 +23,7 @@  void nvram_reinit(void);
 bool nvram_validate(void);
 
 const char *nvram_query(const char *name);
+const char *nvram_query_def(const char *key, const char *def);
 bool nvram_query_eq(const char *key, const char *value);
 
 #endif /* __NVRAM_H */