mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00: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
4 changed files with 71 additions and 51 deletions
42
common.c
42
common.c
|
@ -1758,3 +1758,45 @@ void bugreport()
|
||||||
PACKAGE_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();
|
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
|
#endif
|
||||||
|
|
||||||
|
|
23
exec.c
23
exec.c
|
@ -503,7 +503,13 @@ static void launch_process( process_t *p )
|
||||||
{
|
{
|
||||||
size_t sz = 0;
|
size_t sz = 0;
|
||||||
char **p;
|
char **p;
|
||||||
|
|
||||||
|
string_buffer_t sz1;
|
||||||
|
string_buffer_t sz2;
|
||||||
|
|
||||||
|
sb_init( &sz1 );
|
||||||
|
sb_init( &sz2 );
|
||||||
|
|
||||||
for(p=argv; *p; p++)
|
for(p=argv; *p; p++)
|
||||||
{
|
{
|
||||||
sz += strlen(*p)+1;
|
sz += strlen(*p)+1;
|
||||||
|
@ -514,18 +520,25 @@ static void launch_process( process_t *p )
|
||||||
sz += strlen(*p)+1;
|
sz += strlen(*p)+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sb_format_size( &sz1, sz );
|
||||||
|
|
||||||
#ifdef ARG_MAX
|
#ifdef ARG_MAX
|
||||||
|
sb_format_size( &sz2, ARG_MAX );
|
||||||
|
|
||||||
debug( 0,
|
debug( 0,
|
||||||
L"The total size of the argument and environment lists (%d bytes) exceeds the system limit of %d bytes.",
|
L"The total size of the argument and environment lists (%ls) exceeds the system limit of %ls.",
|
||||||
sz,
|
(wchar_t *)sz1.buff,
|
||||||
ARG_MAX );
|
(wchar_t *)sz2.buff);
|
||||||
#else
|
#else
|
||||||
debug( 0,
|
debug( 0,
|
||||||
L"The total size of the argument and environment lists (%d bytes) exceeds the system limit.",
|
L"The total size of the argument and environment lists (%ls) exceeds the system limit.",
|
||||||
sz );
|
(wchar_t *)sz1.buff);
|
||||||
#endif
|
#endif
|
||||||
debug( 0,
|
debug( 0,
|
||||||
L"Please try running the command again with fewer arguments.");
|
L"Please try running the command again with fewer arguments.");
|
||||||
|
sb_destroy( &sz1 );
|
||||||
|
sb_destroy( &sz2 );
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
break;
|
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
|
\param is_cmd whether we are performing command completion
|
||||||
*/
|
*/
|
||||||
static void wildcard_completion_allocate( array_list_t *list,
|
static void wildcard_completion_allocate( array_list_t *list,
|
||||||
const wchar_t *fullname,
|
const wchar_t *fullname,
|
||||||
const wchar_t *completion,
|
const wchar_t *completion,
|
||||||
const wchar_t *wc,
|
const wchar_t *wc,
|
||||||
int is_cmd )
|
int is_cmd )
|
||||||
{
|
{
|
||||||
const wchar_t *desc;
|
const wchar_t *desc;
|
||||||
struct stat buf, lbuf;
|
struct stat buf, lbuf;
|
||||||
|
@ -653,16 +653,7 @@ static void wildcard_completion_allocate( array_list_t *list,
|
||||||
int stat_res, lstat_res;
|
int stat_res, lstat_res;
|
||||||
int stat_errno=0;
|
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;
|
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 )
|
if( !sb )
|
||||||
{
|
{
|
||||||
|
@ -728,42 +719,10 @@ static void wildcard_completion_allocate( array_list_t *list,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sb_append( sb, desc, L", ", (void *)0 );
|
sb_append( sb, desc, L", ", (void *)0 );
|
||||||
if( sz < 0 )
|
sb_format_size( sb, sz );
|
||||||
{
|
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wildcard_complete( completion, wc, (wchar_t *)sb->buff, 0, list, flags );
|
wildcard_complete( completion, wc, (wchar_t *)sb->buff, 0, list, flags );
|
||||||
|
|
||||||
if( free_completion )
|
if( free_completion )
|
||||||
free( (void *)completion );
|
free( (void *)completion );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue