diff --git a/builtin.c b/builtin.c index dec4db22c..0bdab295d 100644 --- a/builtin.c +++ b/builtin.c @@ -283,14 +283,12 @@ static void builtin_print_help( const wchar_t *cmd, string_buffer_t *b ) */ pos = str; - for( i=0; i<4; i++ ) + for( i=0; (i<4) && pos && *pos; i++ ) { pos = wcschr( pos+1, L'\n' ); - if( !pos ) - break; } - if( pos ) + if( pos && *pos ) { /* diff --git a/event.h b/event.h index 9bd3f81bd..cb99c73f8 100644 --- a/event.h +++ b/event.h @@ -97,6 +97,9 @@ void event_remove( event_t *event ); /** Return all events which match the specified event class + This function is safe to call from a signal handler _ONLY_ if the + out parameter is null. + \param criterion Is the class of events to return. If the criterion has a non-null function_name, only events which trigger the specified function will return. \param out the list to add events to. May be 0, in which case no events will be added, but the result count will still be valid @@ -111,6 +114,9 @@ int event_get( event_t *criterion, array_list_t *out ); called. If event is a null-pointer, all pending events are dispatched. + This function is safe to call from a signal handler _ONLY_ if the + event parameter is for a signal. + \param event the specific event whose handlers should fire */ void event_fire( event_t *event ); diff --git a/io.h b/io.h index 69df7e376..c670afe05 100644 --- a/io.h +++ b/io.h @@ -68,7 +68,7 @@ io_data_t *io_remove( io_data_t *list, io_data_t *element ); io_data_t *io_duplicate( void *context, io_data_t *l ); /** - Return the last io redirection in ht e chain for the specified file descriptor. + Return the last io redirection in the chain for the specified file descriptor. */ io_data_t *io_get( io_data_t *io, int fd ); diff --git a/proc.c b/proc.c index 5476d9707..8a2f826a4 100644 --- a/proc.c +++ b/proc.c @@ -1033,7 +1033,10 @@ void job_continue (job_t *j, int cont) got_signal = 0; quit = job_is_stopped( j ) || job_is_completed( j ); } - while( got_signal && !quit ); + + while( got_signal && !quit ) + ; + if( !quit ) { @@ -1077,7 +1080,6 @@ void job_continue (job_t *j, int cont) } } - break; } diff --git a/signal.c b/signal.c index b5271e0a1..818ea3130 100644 --- a/signal.c +++ b/signal.c @@ -450,7 +450,8 @@ static void handle_winch( int sig, siginfo_t *info, void *context ) } /** - Respond to a winch signal by checking the terminal size + Respond to a hup signal by exiting, unless it is vcaught by a + shellscript function, in which case we do nothing. */ static void handle_hup( int sig, siginfo_t *info, void *context ) { diff --git a/util.c b/util.c index e1832730d..0da829d0c 100644 --- a/util.c +++ b/util.c @@ -1316,15 +1316,31 @@ void sb_destroy( string_buffer_t * b ) void sb_clear( string_buffer_t * b ) { - wchar_t c=0; - - CHECK( b, ); - - b->used=0; - b_append( b, &c, sizeof( wchar_t)); - b->used -= sizeof(wchar_t); + sb_truncate( b, 0 ); + assert( !wcslen( b->buff) ); } +void sb_truncate( string_buffer_t *b, int chars_left ) +{ + wchar_t *arr; + + CHECK( b, ); + + b->used = (chars_left)*sizeof( wchar_t); + arr = (wchar_t *)b->buff; + arr[chars_left] = 0; + +} + +ssize_t sb_length( string_buffer_t *b ) +{ + CHECK( b, -1 ); + return (b->used-1)/sizeof( wchar_t); + +} + + + void b_init( buffer_t *b) { diff --git a/util.h b/util.h index a84378e09..26d85748b 100644 --- a/util.h +++ b/util.h @@ -642,10 +642,23 @@ int sb_vprintf( string_buffer_t *buffer, const wchar_t *format, va_list va_orig void sb_destroy( string_buffer_t * ); /** - Truncate the buffer. This will not deallocate the memory used, it will only set the contents of the string to L"\\0". + Completely truncate the buffer. This will not deallocate the memory + used, it will only set the contents of the string to L"\\0". */ void sb_clear( string_buffer_t * ); +/** + Truncate the string to the specified number of characters. This + will not deallocate the memory used. +*/ +void sb_truncate( string_buffer_t *, int chars_left ); + +/** + Return the number of characters in the string +*/ +ssize_t sb_length( string_buffer_t * ); + + /* Buffer functions */