]> granicus.if.org Git - graphviz/commitdiff
inline a getenv accessor and use a more appropriate return type
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 10 Apr 2021 00:02:39 +0000 (17:02 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 17 Apr 2021 22:24:44 +0000 (15:24 -0700)
lib/ast/pathpath.c

index 7ceb7fdbf03571679ceca78cf30a7ebb180b0824..94dfa0fc9bf879bbb9a5c0cb24491a02ca338886 100644 (file)
@@ -23,6 +23,7 @@
  */
 
 #include <ast/ast.h>
+#include <stdlib.h>
 #include <string.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #include <ast/compat_unistd.h>
 #endif
 
+static const char *getenv_path(void) {
+  const char *path = getenv("PATH");
+  if (path != NULL) {
+    return path;
+  }
+  return "";
+}
+
 char **opt_info_argv;
 
 char *pathpath(char *path, const char *p, const char *a, int mode)
 {
     char *s;
-    char *x;
+    const char *x;
     char buf[PATH_MAX];
 
     static char *cmd;
@@ -95,7 +104,7 @@ char *pathpath(char *path, const char *p, const char *a, int mode)
            }
        }
     }
-    x = !a && strchr(p, '/') ? "" : pathbin();
+    x = !a && strchr(p, '/') ? "" : getenv_path();
     if (!(s = pathaccess(path, x, p, a, mode)) && !*x
        && (x = getenv("FPATH")))
        s = pathaccess(path, x, p, a, mode);