gvc gvconfig: replace existence check using 'stat' with using 'access'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 11 Oct 2022 01:13:19 +0000 (18:13 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 13 Oct 2022 01:08:59 +0000 (18:08 -0700)
This probably uses `stat` under the hood too, but is slightly more concise and
clear about intent.

lib/gvc/gvconfig.c

index 1b8c0af50233cd46c85d17f930e34b7affccf898..76f7fac15d8a2fbfc8b971b672b5def46f898312 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdbool.h>
 #include <stddef.h>
 #include       <string.h>
+#include <unistd.h>
 
 #ifdef ENABLE_LTDL
 #ifdef HAVE_DL_ITERATE_PHDR
@@ -552,7 +553,7 @@ void gvconfig(GVC_t * gvc, bool rescan)
 {
 #ifdef ENABLE_LTDL
     int rc;
-    struct stat config_st, libdir_st;
+    struct stat config_st;
     FILE *f = NULL;
     char *config_text = NULL;
     char *libdir;
@@ -568,8 +569,7 @@ void gvconfig(GVC_t * gvc, bool rescan)
     if (gvc->common.demand_loading) {
         /* see if there are any new plugins */
         libdir = gvconfig_libdir(gvc);
-        rc = stat(libdir, &libdir_st);
-        if (rc == -1) {
+        if (access(libdir, F_OK) < 0) {
            gvtextlayout_select(gvc);   /* choose best available textlayout plugin immediately */
            /* if we fail to stat it then it probably doesn't exist so just fail silently */
            return;