diff --git a/configure.ac b/configure.ac index 786e9ef6e..bce63168b 100644 --- a/configure.ac +++ b/configure.ac @@ -732,7 +732,7 @@ fi AC_CHECK_FUNCS( wcsdup wcsndup wcslen wcscasecmp wcsncasecmp fwprintf ) AC_CHECK_FUNCS( futimes wcwidth wcswidth wcstok fputwc fgetwc ) AC_CHECK_FUNCS( wcstol wcslcat wcslcpy lrand48_r killpg gettext ) -AC_CHECK_FUNCS( dcgettext backtrace backtrace_symbols) +AC_CHECK_FUNCS( dcgettext backtrace backtrace_symbols sysconf ) # # The Makefile also needs to know if we have gettext, so it knows if diff --git a/exec.c b/exec.c index 5fa8b6152..a0ce5ae1f 100644 --- a/exec.c +++ b/exec.c @@ -507,6 +507,8 @@ static void launch_process( process_t *p ) string_buffer_t sz1; string_buffer_t sz2; + long arg_max = -1; + sb_init( &sz1 ); sb_init( &sz2 ); @@ -521,19 +523,26 @@ static void launch_process( process_t *p ) } sb_format_size( &sz1, sz ); + + arg_max = sysconf( _SC_ARG_MAX ); -#ifdef ARG_MAX - sb_format_size( &sz2, ARG_MAX ); + if( arg_max > 0 ) + { + + sb_format_size( &sz2, ARG_MAX ); + + debug( 0, + L"The total size of the argument and environment lists (%ls) exceeds the system limit of %ls.", + (wchar_t *)sz1.buff, + (wchar_t *)sz2.buff); + } + else + { + debug( 0, + L"The total size of the argument and environment lists (%ls) exceeds the system limit.", + (wchar_t *)sz1.buff); + } - debug( 0, - L"The total size of the argument and environment lists (%ls) exceeds the system limit of %ls.", - (wchar_t *)sz1.buff, - (wchar_t *)sz2.buff); -#else - debug( 0, - L"The total size of the argument and environment lists (%ls) exceeds the system limit.", - (wchar_t *)sz1.buff); -#endif debug( 0, L"Please try running the command again with fewer arguments."); sb_destroy( &sz1 ); diff --git a/fallback.c b/fallback.c index d686f58d8..af719cf51 100644 --- a/fallback.c +++ b/fallback.c @@ -1168,3 +1168,20 @@ char ** backtrace_symbols (void *const *buffer, int size) return 0; } #endif + +#ifndef HAVE_SYSCONF + +long sysconf(int name) +{ + if( name == _SC_ARG_MAX ) + { +#ifdef ARG_MAX + return ARG_MAX; +#endif + } + + return -1; + +} + +#endif diff --git a/fallback.h b/fallback.h index e6f8e3412..8f6289779 100644 --- a/fallback.h +++ b/fallback.h @@ -435,4 +435,11 @@ int getopt_long(int argc, #endif +#ifndef HAVE_SYSCONF + +#define _SC_ARG_MAX 1 +long sysconf(int name); + +#endif + #endif