m4-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/2] libm4: exclude directories when searching for modules


From: KO Myung-Hun
Subject: [PATCH 1/2] libm4: exclude directories when searching for modules
Date: Sat, 22 Nov 2014 15:29:14 +0900

* m4/path.c (module_access): New. Check if name is a directory as
well.
(m4_path_search, m4_load_filename): Replace access() with
module_access().
---
 m4/path.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/m4/path.c b/m4/path.c
index 7243447..bc8b376 100644
--- a/m4/path.c
+++ b/m4/path.c
@@ -167,6 +167,15 @@ path_truncate (char *path)
 #  define path_truncate(path) (path)
 #endif
 
+static int
+module_access (const char *name, int mode)
+{
+  struct stat stat_buf;
+
+  return access (name, mode) == 0 &&
+         stat (name, &stat_buf) == 0 && !S_ISDIR (stat_buf.st_mode) ? 0 : -1;
+}
+
 
 
 /* Functions for normal input path search */
@@ -232,11 +241,11 @@ m4_path_search (m4 *context, const char *filename, const 
char **suffixes)
       for (i = 0; suffixes && suffixes[i]; ++i)
         {
           strcpy (filepath + mem, suffixes[i]);
-          if (access (filepath, R_OK) == 0)
+          if (module_access (filepath, R_OK) == 0)
            return filepath;
 
           /* If search fails, we'll use the error we got from the first
-            access (usually with no suffix).  */
+            module_access (usually with no suffix).  */
          if (i == 0)
            e = errno;
         }
@@ -257,7 +266,7 @@ m4_path_search (m4 *context, const char *filename, const 
char **suffixes)
       xfprintf (stderr, "path_search (%s) -- trying %s\n", filename, pathname);
 #endif
 
-      if (access (pathname, R_OK) == 0)
+      if (module_access (pathname, R_OK) == 0)
         {
           m4_debug_message (context, M4_DEBUG_TRACE_PATH,
                             _("path search for %s found %s"),
@@ -276,7 +285,7 @@ m4_path_search (m4 *context, const char *filename, const 
char **suffixes)
       for (i = 0; suffixes && suffixes[i]; ++i)
         {
           strcpy (filepath + mem, suffixes[i]);
-          if (access (filepath, R_OK) == 0)
+          if (module_access (filepath, R_OK) == 0)
             return filepath;
         }
       free (filepath);
@@ -329,7 +338,7 @@ m4_load_filename (m4 *context, const m4_call_info *caller,
 
   if (m4_get_posixly_correct_opt (context))
     {
-      if (access (filename, R_OK) == 0)
+      if (module_access (filename, R_OK) == 0)
         filepath = xstrdup (filename);
     }
   else
-- 
1.8.5.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]