]> git.ipfire.org Git - thirdparty/make.git/commitdiff
Set PATH_MAX on systems without a default value
authorPaul Smith <psmith@gnu.org>
Sat, 22 Oct 2022 23:42:07 +0000 (19:42 -0400)
committerPaul Smith <psmith@gnu.org>
Sun, 23 Oct 2022 02:40:26 +0000 (22:40 -0400)
Some systems (HURD) use fully-dynamic pathnames, with no limit.
We can't support this without significant effort so for now set
PATH_MAX to a large value.

* src/makeint.h: Set PATH_MAX to 4096 if not set and MAXPATHLEN
is also not set.  Remove MAXPATHLEN setting: we won't use it.
* src/misc.c (get_path_max): If we can't get the path max via
pathconf() use the default PATH_MAX.
* src/dir.c (find_directory) [W32]: Use MAX_PATH not MAXPATHLEN.
(local_stat) [W32]: Ditto.
* src/job.c (create_batch_file) [W32]: Ditto.
* src/remake.c (name_mtime) [W32]: Ditto.
* src/w32/w32os.c (os_anontmp) [W32]: Ditto.

src/dir.c
src/job.c
src/makeint.h
src/misc.c
src/remake.c
src/w32/w32os.c

index 38a7806ec4d401eb226659535dda0bc04ce7ac1c..3577a12ddec26ae74ad19029ccf64532f9986ea3 100644 (file)
--- a/src/dir.c
+++ b/src/dir.c
@@ -521,7 +521,7 @@ find_directory (const char *name)
   /* See if the directory exists.  */
 #if defined(WINDOWS32)
   {
-    char tem[MAXPATHLEN], *tstart, *tend;
+    char tem[MAX_PATH+1], *tstart, *tend;
     size_t len = strlen (name);
 
     /* Remove any trailing slashes.  Windows32 stat fails even on
@@ -1314,10 +1314,10 @@ local_stat (const char *path, struct stat *buf)
      foo/. => foo without checking first that foo is a directory.  */
   if (plen > 2 && path[plen - 1] == '.' && ISDIRSEP (path[plen - 2]))
     {
-      char parent[MAXPATHLEN+1];
+      char parent[MAX_PATH+1];
 
-      strncpy (parent, path, MAXPATHLEN);
-      parent[MIN(plen - 2, MAXPATHLEN)] = '\0';
+      strncpy (parent, path, MAX_PATH);
+      parent[MIN(plen - 2, MAX_PATH)] = '\0';
       if (stat (parent, buf) < 0 || !_S_ISDIR (buf->st_mode))
         return -1;
     }
index 9d38190485d7f636fa275806785ecd93a477492a..21492441761f610e48b531eb54e621d968369149 100644 (file)
--- a/src/job.c
+++ b/src/job.c
@@ -283,7 +283,7 @@ create_batch_file (char const *base, int unixy, int *fd)
 {
   const char *const ext = unixy ? "sh" : "bat";
   const char *error_string = NULL;
-  char temp_path[MAXPATHLEN]; /* need to know its length */
+  char temp_path[MAX_PATH+1]; /* need to know its length */
   unsigned path_size = GetTempPath (sizeof temp_path, temp_path);
   int path_is_dot = 0;
   /* The following variable is static so we won't try to reuse a name
index c924b31ebda0ee996e20fdc96b80cb8299f5f10e..f9de63d081aeedf8e532e76bb7370c41d8c49e71 100644 (file)
@@ -152,13 +152,14 @@ extern int errno;
 #endif
 
 #ifndef PATH_MAX
-# ifndef POSIX
+# ifdef MAXPATHLEN
 #  define PATH_MAX      MAXPATHLEN
+# else
+/* Some systems (HURD) have fully dynamic pathnames with no maximum.
+   Ideally we'd support this but it will take some work.  */
+#  define PATH_MAX      4096
 # endif
 #endif
-#ifndef MAXPATHLEN
-# define MAXPATHLEN 1024
-#endif
 
 #ifdef  PATH_MAX
 # define GET_PATH_MAX   PATH_MAX
index 15fddcd1c387ca297be362dc0d4f80073437ee7a..18728f3531e5cbb0bb1dc042fa2d38e4566e4407 100644 (file)
@@ -769,11 +769,11 @@ get_path_max (void)
 
   if (value == 0)
     {
-      long int x = pathconf ("/", _PC_PATH_MAX);
+      long x = pathconf ("/", _PC_PATH_MAX);
       if (x > 0)
-        value = x;
+        value = (unsigned int) x;
       else
-        return MAXPATHLEN;
+        value = PATH_MAX;
     }
 
   return value;
index 4c87f783baa6590e5df0d5f7df03661320ac3068..4ce3d2a379d7b261e82a8a973d5f4dfb8dd542b8 100644 (file)
@@ -34,6 +34,7 @@ this program.  If not, see <https://www.gnu.org/licenses/>.  */
 #include <starlet.h>
 #endif
 #ifdef WINDOWS32
+#include <windows.h>
 #include <io.h>
 #include <sys/stat.h>
 #if defined(_MSC_VER) && _MSC_VER > 1200
@@ -1551,7 +1552,7 @@ name_mtime (const char *name)
 
 #if defined(WINDOWS32)
   {
-    char tem[MAXPATHLEN], *tstart, *tend;
+    char tem[MAX_PATH+1], *tstart, *tend;
     const char *p = name + strlen (name);
 
     /* Remove any trailing slashes and "."/"..".  MS-Windows stat
index 28b6430f670f47f63f2fc9a81a04cb4a97f445f5..9c5dec247815594f2ac49dfa7d3a89ddf0f89759 100644 (file)
@@ -115,7 +115,7 @@ check_io_state ()
 int
 os_anontmp ()
 {
-  char temp_path[MAXPATHLEN];
+  char temp_path[MAX_PATH+1];
   unsigned path_size = GetTempPath (sizeof (temp_path), temp_path);
   int using_cwd = 0;