summaryrefslogtreecommitdiffstats
path: root/main/make/make-3.82-arg-list-length.patch
blob: 1b59da79ebe63c2e54956bae7a74ea288851035d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
diff -u make-3.82-orig/job.c make-3.82/job.c
--- make-3.82-orig/job.c	2010-07-24 10:27:50.000000000 +0200
+++ make-3.82/job.c	2012-03-21 12:34:20.000000000 +0100
@@ -29,6 +29,11 @@
 
 #include <string.h>
 
+//#if defined (HAVE_LINUX_BINFMTS_H) && defined (HAVE_SYS_USER_H)
+#include <sys/user.h>
+#include <linux/binfmts.h>
+//#endif
+
 /* Default shell to use.  */
 #ifdef WINDOWS32
 #include <windows.h>
@@ -2795,6 +2800,7 @@
     unsigned int sflags_len = strlen (shellflags);
     char *command_ptr = NULL; /* used for batch_mode_shell mode */
     char *new_line;
+    char *args_ptr;
 
 # ifdef __EMX__ /* is this necessary? */
     if (!unixy_shell)
@@ -2865,8 +2871,17 @@
 	return new_argv;
       }
 
+#ifdef MAX_ARG_STRLEN
+    static char eval_line[] = "eval\\ \\\"set\\ x\\;\\ shift\\;\\ ";
+#define ARG_NUMBER_DIGITS 5
+#define EVAL_LEN (sizeof(eval_line)-1 + shell_len + 4                   \
+                  + (7 + ARG_NUMBER_DIGITS) * 2 * line_len / (MAX_ARG_STRLEN - 2))
+#else
+#define EVAL_LEN 0
+#endif
+
     new_line = alloca (shell_len + 1 + sflags_len + 1
-                             + (line_len*2) + 1);
+                       + (line_len*2) + 1 + EVAL_LEN);
     ap = new_line;
     memcpy (ap, shell, shell_len);
     ap += shell_len;
@@ -2875,6 +2890,30 @@
     ap += sflags_len;
     *(ap++) = ' ';
     command_ptr = ap;
+
+#if !defined (WINDOWS32) && defined (MAX_ARG_STRLEN)
+    if (unixy_shell && line_len > MAX_ARG_STRLEN)
+      {
+	unsigned j;
+	memcpy (ap, eval_line, sizeof (eval_line) - 1);
+	ap += sizeof (eval_line) - 1;
+	for (j = 1; j <= 2 * line_len / (MAX_ARG_STRLEN - 2); j++)
+	  ap += sprintf (ap, "\\$\\{%u\\}", j);
+	*ap++ = '\\';
+	*ap++ = '"';
+	*ap++ = ' ';
+	/* Copy only the first word of SHELL to $0.  */
+	for (p = shell; *p != '\0'; ++p)
+	  {
+	    if (isspace ((unsigned char)*p))
+	      break;
+	    *ap++ = *p;
+	  }
+	*ap++ = ' ';
+      }
+#endif
+    args_ptr = ap;
+
     for (p = line; *p != '\0'; ++p)
       {
 	if (restp != NULL && *p == '\n')
@@ -2922,6 +2961,14 @@
           }
 #endif
 	*ap++ = *p;
+
+#if !defined (WINDOWS32) && defined (MAX_ARG_STRLEN)
+	if (unixy_shell && line_len > MAX_ARG_STRLEN && (ap - args_ptr > MAX_ARG_STRLEN - 2))
+	  {
+	    *ap++ = ' ';
+	    args_ptr = ap;
+	  }
+#endif
       }
     if (ap == new_line + shell_len + sflags_len + 2)
       /* Line was empty.  */