From a925e59653b37cc8bdd83eb2404df262488d0e92 Mon Sep 17 00:00:00 2001 From: Qball Cow Date: Tue, 13 May 2014 22:11:42 +0200 Subject: [PATCH] Small fixes --- source/history.c | 23 +++++++++++++---------- source/ssh-dialog.c | 7 +++++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/source/history.c b/source/history.c index 5eda4773..03ccf989 100644 --- a/source/history.c +++ b/source/history.c @@ -153,12 +153,13 @@ void history_set ( const char *filename, const char *entry ) // Rewind. fseek(fd, 0L, SEEK_SET); // Clear file. - ftruncate(fileno(fd), 0); - - // Write list. - __history_write_element_list(fd, list, length); - - + if ( ftruncate(fileno(fd), 0) == 0) + { + // Write list. + __history_write_element_list(fd, list, length); + }else { + fprintf(stderr, "Failed to truncate file: %s\n", strerror(errno)); + } // Free the list. for(unsigned int iter = 0; iter < length; iter++) { @@ -207,10 +208,12 @@ void history_remove ( const char *filename, const char *entry ) // Rewind. fseek(fd, 0L, SEEK_SET); // Clear list. - ftruncate(fileno(fd), 0); - - // Write list. - __history_write_element_list(fd, list, length); + if(ftruncate(fileno(fd), 0) == 0) { + // Write list. + __history_write_element_list(fd, list, length); + } else { + fprintf(stderr, "Failed to open file: %s\n", strerror(errno)); + } } // Free the list. diff --git a/source/ssh-dialog.c b/source/ssh-dialog.c index f23670a4..30f81f27 100644 --- a/source/ssh-dialog.c +++ b/source/ssh-dialog.c @@ -151,9 +151,12 @@ static char ** get_ssh ( ) num_favorites = index; } + + FILE *fd = NULL; const char *hd = getenv ( "HOME" ); - asprintf ( &path, "%s/%s", hd, ".ssh/config" ); - FILE *fd = fopen ( path, "r" ); + if(asprintf ( &path, "%s/%s", hd, ".ssh/config" )>= 0){ + fd = fopen ( path, "r" ); + } if ( fd != NULL ) {