chiark / gitweb /
bool cache optional
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 7 Jun 2012 18:14:28 +0000 (19:14 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 7 Jun 2012 18:14:28 +0000 (19:14 +0100)
cprogs/xacpi-simple.c

index 73bea7f508973b40338751e7888ec435db4a095e..eb761a290635ca85ab8f80db11b6d26444c26dca 100644 (file)
@@ -531,9 +531,11 @@ static const char *getresource(const char *want) {
 }
 
 static int getresource_bool(const char *want, int def, int *cache) {
 }
 
 static int getresource_bool(const char *want, int def, int *cache) {
-  /* *cache should be initialised to -1 and will be set to !!value */
+  /* *cache should be initialised to -1 and will be set to !!value
+   * alternatively cache==0 is allowed */
+
+  if (cache && *cache >= 0) return *cache;
 
 
-  if (*cache >= 0) return *cache;
   const char *str= getresource(want);
   int result = def;
   if (str && str[0]) {
   const char *str= getresource(want);
   int result = def;
   if (str && str[0]) {
@@ -549,7 +551,9 @@ static int getresource_bool(const char *want, int def, int *cache) {
       }
     }
   }
       }
     }
   }
-  return *cache= result;
+
+  if (cache) *cache= result;
+  return result;
 }
 
 static void more_resources(const char *str, const char *why) {
 }
 
 static void more_resources(const char *str, const char *why) {