From 819299852c2dc9a984a30f6d8c4a279a0197bf63 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Fri, 12 Jun 2026 09:44:25 +0200 Subject: [PATCH] conf: introduce SCConfGetNonNull Ticket: 8651 Behaves like SCConfGet but returns 0 on null value (cherry picked from commit a9e1dff4a6e2138364a9fb1a7879e34f4415747c) --- rust/sys/src/sys.rs | 5 +++++ src/conf.c | 30 +++++++++++++++++++++++++++--- src/conf.h | 1 + 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/rust/sys/src/sys.rs b/rust/sys/src/sys.rs index 3b7c147658..49d5acfaf0 100644 --- a/rust/sys/src/sys.rs +++ b/rust/sys/src/sys.rs @@ -474,6 +474,11 @@ extern "C" { name: *const ::std::os::raw::c_char, vptr: *mut *const ::std::os::raw::c_char, ) -> ::std::os::raw::c_int; } +extern "C" { + pub fn SCConfGetNonNull( + name: *const ::std::os::raw::c_char, vptr: *mut *const ::std::os::raw::c_char, + ) -> ::std::os::raw::c_int; +} extern "C" { pub fn SCConfGetInt( name: *const ::std::os::raw::c_char, val: *mut intmax_t, diff --git a/src/conf.c b/src/conf.c index 252dcb897f..e70fababa8 100644 --- a/src/conf.c +++ b/src/conf.c @@ -361,6 +361,30 @@ int SCConfGet(const char *name, const char **vptr) } } +/** + * \brief Retrieve the non-null value of a configuration node. + * + * This function will return the value for a configuration node based + * on the full name of the node. If the value were NULL, return 0 + * (this could happen if the requested node does exist but is not a node + * that contains a value, but contains children SCConfNodes instead.) + * + * \param name Name of configuration parameter to get. + * \param vptr Pointer that will be set to the configuration value parameter. + * Note that this is just a reference to the actual value, not a copy. + * + * \retval 1 will be returned if the value is found, otherwise 0 will + * be returned. + */ +int SCConfGetNonNull(const char *name, const char **vptr) +{ + int r = SCConfGet(name, vptr); + if (r == 1 && *vptr == NULL) { + return 0; + } + return r; +} + int SCConfGetChildValue(const SCConfNode *base, const char *name, const char **vptr) { SCConfNode *node = SCConfNodeLookupChild(base, name); @@ -500,7 +524,7 @@ int SCConfGetBool(const char *name, int *val) const char *strval = NULL; *val = 0; - if (SCConfGet(name, &strval) != 1) + if (SCConfGetNonNull(name, &strval) != 1) return 0; *val = SCConfValIsTrue(strval); @@ -604,7 +628,7 @@ int SCConfGetDouble(const char *name, double *val) double tmpdo; char *endptr; - if (SCConfGet(name, &strval) == 0) + if (SCConfGetNonNull(name, &strval) == 0) return 0; errno = 0; @@ -634,7 +658,7 @@ int SCConfGetFloat(const char *name, float *val) double tmpfl; char *endptr; - if (SCConfGet(name, &strval) == 0) + if (SCConfGetNonNull(name, &strval) == 0) return 0; errno = 0; diff --git a/src/conf.h b/src/conf.h index 1de4481df1..9861f08b79 100644 --- a/src/conf.h +++ b/src/conf.h @@ -63,6 +63,7 @@ void SCConfInit(void); void SCConfDeInit(void); SCConfNode *SCConfGetRootNode(void); int SCConfGet(const char *name, const char **vptr); +int SCConfGetNonNull(const char *name, const char **vptr); int SCConfGetInt(const char *name, intmax_t *val); int SCConfGetBool(const char *name, int *val); int SCConfGetDouble(const char *name, double *val);