diff --git a/common.c b/common.c index a138ae2f1..13ec163c2 100644 --- a/common.c +++ b/common.c @@ -1758,3 +1758,45 @@ void bugreport() PACKAGE_BUGREPORT ); } + +void sb_format_size( string_buffer_t *sb, + long long sz ) +{ + wchar_t *sz_name[]= + { + L"kB", L"MB", L"GB", L"TB", L"PB", L"EB", L"ZB", L"YB", 0 + } + ; + + if( sz < 0 ) + { + sb_append( sb, L"unknown" ); + } + else if( sz < 1 ) + { + sb_append( sb, _( L"empty" ) ); + } + else if( sz < 1024 ) + { + sb_printf( sb, L"%lldB", sz ); + } + else + { + int i; + + for( i=0; sz_name[i]; i++ ) + { + if( sz < (1024*1024) || !sz_name[i+1] ) + { + int isz = sz/1024; + if( isz > 9 ) + sb_printf( sb, L"%d%ls", isz, sz_name[i] ); + else + sb_printf( sb, L"%.1f%ls", (double)sz/1024, sz_name[i] ); + break; + } + sz /= 1024; + + } + } +} diff --git a/common.h b/common.h index 41fc64d59..e12152019 100644 --- a/common.h +++ b/common.h @@ -434,5 +434,11 @@ int create_directory( wchar_t *d ); */ void bugreport(); +/** + Format the specified size (in bytes, kilobytes, etc.) into the specified stringbuffer. +*/ +void sb_format_size( string_buffer_t *sb, + long long sz ); + #endif diff --git a/exec.c b/exec.c index 8347ac80c..5fa8b6152 100644 --- a/exec.c +++ b/exec.c @@ -503,7 +503,13 @@ static void launch_process( process_t *p ) { size_t sz = 0; char **p; + + string_buffer_t sz1; + string_buffer_t sz2; + sb_init( &sz1 ); + sb_init( &sz2 ); + for(p=argv; *p; p++) { sz += strlen(*p)+1; @@ -514,18 +520,25 @@ static void launch_process( process_t *p ) sz += strlen(*p)+1; } + sb_format_size( &sz1, sz ); + #ifdef ARG_MAX + sb_format_size( &sz2, ARG_MAX ); + debug( 0, - L"The total size of the argument and environment lists (%d bytes) exceeds the system limit of %d bytes.", - sz, - ARG_MAX ); + 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 (%d bytes) exceeds the system limit.", - sz ); + 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 ); + sb_destroy( &sz2 ); + exit(1); break; diff --git a/wildcard.c b/wildcard.c index 60d6dd6b8..a2cf09b04 100644 --- a/wildcard.c +++ b/wildcard.c @@ -638,10 +638,10 @@ static const wchar_t *file_get_desc( const wchar_t *filename, \param is_cmd whether we are performing command completion */ static void wildcard_completion_allocate( array_list_t *list, - const wchar_t *fullname, - const wchar_t *completion, - const wchar_t *wc, - int is_cmd ) + const wchar_t *fullname, + const wchar_t *completion, + const wchar_t *wc, + int is_cmd ) { const wchar_t *desc; struct stat buf, lbuf; @@ -653,16 +653,7 @@ static void wildcard_completion_allocate( array_list_t *list, int stat_res, lstat_res; int stat_errno=0; - /* - This is a long long, not an off_t since we really need to know - exactly how large it is when using *printf() to output it. - */ long long sz; - wchar_t *sz_name[]= - { - L"kB", L"MB", L"GB", L"TB", L"PB", L"EB", L"ZB", L"YB", 0 - } - ; if( !sb ) { @@ -728,42 +719,10 @@ static void wildcard_completion_allocate( array_list_t *list, else { sb_append( sb, desc, L", ", (void *)0 ); - if( sz < 0 ) - { - sb_append( sb, L"unknown" ); - } - else if( sz < 1 ) - { - sb_append( sb, _( L"empty" ) ); - } - else if( sz < 1024 ) - { - sb_printf( sb, L"%lldB", sz ); - } - else - { - int i; - - for( i=0; sz_name[i]; i++ ) - { - if( sz < (1024*1024) || !sz_name[i+1] ) - { - int isz = sz/1024; - if( isz > 9 ) - sb_printf( sb, L"%d%ls", isz, sz_name[i] ); - else - sb_printf( sb, L"%.1f%ls", (double)sz/1024, sz_name[i] ); - - break; - } - sz /= 1024; - - } - } + sb_format_size( sb, sz ); } wildcard_complete( completion, wc, (wchar_t *)sb->buff, 0, list, flags ); - if( free_completion ) free( (void *)completion ); }