mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-29 21:43:55 +08:00
Second part of improved execve errors - this patch makes the memory limits nicely formated (e.g. 128kB instead of 136549 bytes).
darcs-hash:20071015095108-75c98-51c2ea6ab6edba5d1885eb5938f039054da775e2.gz
This commit is contained in:
parent
4163040e56
commit
dd02e96712
42
common.c
42
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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
6
common.h
6
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
|
||||
|
||||
|
|
23
exec.c
23
exec.c
|
@ -504,6 +504,12 @@ 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;
|
||||
|
|
51
wildcard.c
51
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 );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user