From 5753d6395839ca11ea6c7e48474db5798ad5d7d7 Mon Sep 17 00:00:00 2001 From: axel Date: Sat, 13 Jan 2007 02:17:24 +1000 Subject: [PATCH] Check all file writes for errors when saving history file darcs-hash:20070112161724-ac50b-21721102c5844ba871668093cb7428dc793d2ba6.gz --- history.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/history.c b/history.c index 33b7f836a..652912fde 100644 --- a/history.c +++ b/history.c @@ -389,10 +389,10 @@ static item_t *item_get( history_mode_t *m, void *d ) /** Write the specified item to the specified file. */ -static void item_write( FILE *f, history_mode_t *m, void *v ) +static int item_write( FILE *f, history_mode_t *m, void *v ) { item_t *i = item_get( m, v ); - fwprintf( f, L"# %d\n%ls\n", i->timestamp, history_escape_newlines( i->data ) ); + return fwprintf( f, L"# %d\n%ls\n", i->timestamp, history_escape_newlines( i->data ) ); } /** @@ -649,6 +649,7 @@ static void history_save_mode( void *n, history_mode_t *m ) if( (out=wfopen( tmp_name, "w" ) ) ) { hash_table_t mine; + int ok = 1; hash_init( &mine, &hash_item_func, &hash_item_cmp ); @@ -665,12 +666,19 @@ static void history_save_mode( void *n, history_mode_t *m ) /* Re-save the old history */ - for( i=0; iitem); i++ ) + for( i=0; ok && (iitem)); i++ ) { void *ptr = al_get( &on_disk->item, i ); item_t *i = item_get( on_disk, ptr ); if( !hash_get( &mine, i ) ) - item_write( out, on_disk, ptr ); + { + if( item_write( out, on_disk, ptr ) == -1 ) + { + ok = 0; + break; + } + } + } hash_destroy( &mine ); @@ -678,15 +686,20 @@ static void history_save_mode( void *n, history_mode_t *m ) /* Add our own items last */ - for( i=0; iitem); i++ ) + for( i=0; ok && (iitem)); i++ ) { void *ptr = al_get( &m->item, i ); int is_new = item_is_new( m, ptr ); if( is_new ) - item_write( out, m, ptr ); + { + if( item_write( out, m, ptr ) == -1 ) + { + ok = 0; + } + } } - if( fclose( out ) ) + if( fclose( out ) || !ok ) { /* This message does not have high enough priority to