disk_cache: add disk_cache_enabled() helper

This will make windows support easier to add in future.

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6197>
diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index d70cf2e..f7fe428 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -182,8 +182,7 @@
    uint8_t cache_version = CACHE_VERSION;
    size_t cv_size = sizeof(cache_version);
 
-   /* If running as a users other than the real user disable cache */
-   if (geteuid() != getuid())
+   if (!disk_cache_enabled())
       return NULL;
 
    /* A ralloc context for transient data during this invocation. */
@@ -191,10 +190,6 @@
    if (local == NULL)
       goto fail;
 
-   /* At user request, disable shader cache entirely. */
-   if (env_var_as_boolean("MESA_GLSL_CACHE_DISABLE", false))
-      goto fail;
-
    cache = rzalloc(NULL, struct disk_cache);
    if (cache == NULL)
       goto fail;
diff --git a/src/util/disk_cache_os.c b/src/util/disk_cache_os.c
index 516245b..37a8d56 100644
--- a/src/util/disk_cache_os.c
+++ b/src/util/disk_cache_os.c
@@ -38,6 +38,7 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include "util/debug.h"
 #include "util/disk_cache.h"
 #include "util/disk_cache_os.h"
 #include "util/ralloc.h"
@@ -171,6 +172,20 @@
 
    return path;
 }
+
+bool
+disk_cache_enabled()
+{
+   /* If running as a users other than the real user disable cache */
+   if (geteuid() != getuid())
+      return false;
+
+   /* At user request, disable shader cache entirely. */
+   if (env_var_as_boolean("MESA_GLSL_CACHE_DISABLE", false))
+      return false;
+
+   return true;
+}
 #endif
 
 #endif /* ENABLE_SHADER_CACHE */
diff --git a/src/util/disk_cache_os.h b/src/util/disk_cache_os.h
index 0b7755f..f64ac85 100644
--- a/src/util/disk_cache_os.h
+++ b/src/util/disk_cache_os.h
@@ -33,6 +33,9 @@
 char *
 disk_cache_generate_cache_dir(void *mem_ctx);
 
+bool
+disk_cache_enabled(void);
+
 #endif
 
 #endif /* DISK_CACHE_OS_H */