summaryrefslogtreecommitdiffstats
path: root/source/history.c
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2015-07-31 10:21:32 +0200
committerDave Davenport <qball@gmpclient.org>2015-07-31 10:21:32 +0200
commit69c75971f38fa9be1c09df4a1dc0cd6003b857a9 (patch)
tree04583c857952f5b47c605aecc4511cb88aee29ba /source/history.c
parentfd8fbbf6c52ac2a9f64b741f6a339e9b9a1baa77 (diff)
Print error to stderr when fclose fails.
Diffstat (limited to 'source/history.c')
-rw-r--r--source/history.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/source/history.c b/source/history.c
index b86a0816..1423cbe0 100644
--- a/source/history.c
+++ b/source/history.c
@@ -31,6 +31,8 @@
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
+#include <glib.h>
+#include <glib/gstdio.h>
#include "rofi.h"
#include "history.h"
@@ -118,7 +120,7 @@ void history_set ( const char *filename, const char *entry )
unsigned int length = 0;
_element **list = NULL;
// Open file for reading and writing.
- FILE *fd = fopen ( filename, "a+" );
+ FILE *fd = g_fopen ( filename, "a+" );
if ( fd == NULL ) {
fprintf ( stderr, "Failed to open file: %s\n", strerror ( errno ) );
return;
@@ -170,8 +172,10 @@ void history_set ( const char *filename, const char *entry )
g_free ( list[iter] );
}
g_free ( list );
- // Close file.
- fclose ( fd );
+ // Close file, if fails let user know on stderr.
+ if ( fclose ( fd ) != 0 ) {
+ fprintf ( stderr, "Failed to close history file: %s\n", strerror ( errno ) );
+ }
}
void history_remove ( const char *filename, const char *entry )
@@ -184,7 +188,7 @@ void history_remove ( const char *filename, const char *entry )
unsigned int curr = 0;
unsigned int length = 0;
// Open file for reading and writing.
- FILE *fd = fopen ( filename, "a+" );
+ FILE *fd = g_fopen ( filename, "a+" );
if ( fd == NULL ) {
fprintf ( stderr, "Failed to open file: %s\n", strerror ( errno ) );
return;
@@ -229,8 +233,11 @@ void history_remove ( const char *filename, const char *entry )
if ( list != NULL ) {
g_free ( list );
}
- // Close file.
- fclose ( fd );
+
+ // Close file, if fails let user know on stderr.
+ if ( fclose ( fd ) != 0 ) {
+ fprintf ( stderr, "Failed to close history file: %s\n", strerror ( errno ) );
+ }
}
char ** history_get_list ( const char *filename, unsigned int *length )
@@ -243,7 +250,7 @@ char ** history_get_list ( const char *filename, unsigned int *length )
_element **list = NULL;
char **retv = NULL;
// Open file.
- FILE *fd = fopen ( filename, "r" );
+ FILE *fd = g_fopen ( filename, "r" );
if ( fd == NULL ) {
// File that does not exists is not an error, so ignore it.
// Everything else? panic.
@@ -267,6 +274,9 @@ char ** history_get_list ( const char *filename, unsigned int *length )
g_free ( list );
}
- fclose ( fd );
+ // Close file, if fails let user know on stderr.
+ if ( fclose ( fd ) != 0 ) {
+ fprintf ( stderr, "Failed to close history file: %s\n", strerror ( errno ) );
+ }
return retv;
}