wrappers: Print an understandable error if the total command line ends up too long
This can happen if the input command line is barely under the limit, but ends up exceeding it due to the extra arguments that the wrapper adds. One could hope that _tspawnvp would set errno to a helpful error code, to identify the issue when printing the error with _tperror(), but in practice, it doesn't.
This commit is contained in:
1 parent
3847488786
commit
089c625e66
1 file changed
+11
-2
@@ -94,10 +94,19 @@ static inline int _tspawnvp_escape(int mode, const TCHAR *filename, const TCHAR
|
||||
while (argv[num_args])
|
||||
num_args++;
|
||||
const TCHAR **escaped_argv = malloc((num_args + 1) * sizeof(*escaped_argv));
|
||||
for (int i = 0; argv[i]; i++)
|
||||
int total = 0;
|
||||
for (int i = 0; argv[i]; i++) {
|
||||
escaped_argv[i] = escape(argv[i]);
|
||||
total += 1 + _tcslen(escaped_argv[i]);
|
||||
}
|
||||
escaped_argv[num_args] = NULL;
|
||||
return _tspawnvp(mode, filename, escaped_argv);
|
||||
int ret = _tspawnvp(mode, filename, escaped_argv);
|
||||
if (ret == -1 && total >= 32767) {
|
||||
int err = errno;
|
||||
fprintf(stderr, "command line too long; %d characters\n", total);
|
||||
errno = err;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
static inline int _tcsicmp(const TCHAR *a, const TCHAR *b) {
|
||||
|
||||
Reference in new issue
Block a user