1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Print error to stderr when fclose fails.

This commit is contained in:
Dave Davenport 2015-07-31 10:21:32 +02:00
parent fd8fbbf6c5
commit 69c75971f3
6 changed files with 33 additions and 16 deletions

View file

@ -158,7 +158,9 @@ static char ** get_apps_external ( char **retv, unsigned int *length, unsigned i
( *length )++; ( *length )++;
} }
fclose ( inp ); if ( fclose ( inp ) != 0 ) {
fprintf ( stderr, "Failed to close stdout off executor script: '%s'\n", strerror ( errno ) );
}
} }
} }
retv[( *length ) ] = NULL; retv[( *length ) ] = NULL;

View file

@ -34,6 +34,7 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include "rofi.h" #include "rofi.h"
#include "dialogs/script.h" #include "dialogs/script.h"
#include "helper.h" #include "helper.h"
@ -64,7 +65,9 @@ static char **get_script_output ( const char *command, unsigned int *length )
( *length )++; ( *length )++;
} }
fclose ( inp ); if ( fclose ( inp ) != 0 ) {
fprintf ( stderr, "Failed to close stdout off executor script: '%s'\n", strerror ( errno ) );
}
} }
} }
return retv; return retv;

View file

@ -167,7 +167,9 @@ static char **read_hosts_file ( char ** retv, unsigned int *length )
index++; index++;
} while ( buffer[index] != '\0' && buffer[index] != '#' ); } while ( buffer[index] != '\0' && buffer[index] != '#' );
} }
fclose ( fd ); if ( fclose ( fd ) != 0 ) {
fprintf ( stderr, "Failed to close hosts file: '%s'\n", strerror ( errno ) );
}
} }
return retv; return retv;
@ -252,7 +254,9 @@ static char ** get_ssh ( unsigned int *length )
} }
} }
fclose ( fd ); if ( fclose ( fd ) != 0 ) {
fprintf ( stderr, "Failed to close ssh configuration file: '%s'\n", strerror ( errno ) );
}
} }
// TODO: check this is still fast enough. (takes 1ms on laptop.) // TODO: check this is still fast enough. (takes 1ms on laptop.)

View file

@ -28,7 +28,6 @@
#include <config.h> #include <config.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <glib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>

View file

@ -31,6 +31,8 @@
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <errno.h> #include <errno.h>
#include <glib.h>
#include <glib/gstdio.h>
#include "rofi.h" #include "rofi.h"
#include "history.h" #include "history.h"
@ -118,7 +120,7 @@ void history_set ( const char *filename, const char *entry )
unsigned int length = 0; unsigned int length = 0;
_element **list = NULL; _element **list = NULL;
// Open file for reading and writing. // Open file for reading and writing.
FILE *fd = fopen ( filename, "a+" ); FILE *fd = g_fopen ( filename, "a+" );
if ( fd == NULL ) { if ( fd == NULL ) {
fprintf ( stderr, "Failed to open file: %s\n", strerror ( errno ) ); fprintf ( stderr, "Failed to open file: %s\n", strerror ( errno ) );
return; return;
@ -170,8 +172,10 @@ void history_set ( const char *filename, const char *entry )
g_free ( list[iter] ); g_free ( list[iter] );
} }
g_free ( list ); g_free ( list );
// Close file. // Close file, if fails let user know on stderr.
fclose ( fd ); if ( fclose ( fd ) != 0 ) {
fprintf ( stderr, "Failed to close history file: %s\n", strerror ( errno ) );
}
} }
void history_remove ( const char *filename, const char *entry ) 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 curr = 0;
unsigned int length = 0; unsigned int length = 0;
// Open file for reading and writing. // Open file for reading and writing.
FILE *fd = fopen ( filename, "a+" ); FILE *fd = g_fopen ( filename, "a+" );
if ( fd == NULL ) { if ( fd == NULL ) {
fprintf ( stderr, "Failed to open file: %s\n", strerror ( errno ) ); fprintf ( stderr, "Failed to open file: %s\n", strerror ( errno ) );
return; return;
@ -229,8 +233,11 @@ void history_remove ( const char *filename, const char *entry )
if ( list != NULL ) { if ( list != NULL ) {
g_free ( list ); 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 ) 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; _element **list = NULL;
char **retv = NULL; char **retv = NULL;
// Open file. // Open file.
FILE *fd = fopen ( filename, "r" ); FILE *fd = g_fopen ( filename, "r" );
if ( fd == NULL ) { if ( fd == NULL ) {
// File that does not exists is not an error, so ignore it. // File that does not exists is not an error, so ignore it.
// Everything else? panic. // Everything else? panic.
@ -267,6 +274,9 @@ char ** history_get_list ( const char *filename, unsigned int *length )
g_free ( list ); 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; return retv;
} }

View file

@ -116,9 +116,8 @@ void i3_support_focus_window ( Window id )
int i3_support_initialize ( Display *display ) int i3_support_initialize ( Display *display )
{ {
// Free it, // If we where initialized, clean this first.
g_free ( i3_socket_path ); i3_support_free_internals ();
i3_socket_path = NULL;
// Get atom for I3_SOCKET_PATH // Get atom for I3_SOCKET_PATH
Atom i3_sp_atom = XInternAtom ( display, "I3_SOCKET_PATH", False ); Atom i3_sp_atom = XInternAtom ( display, "I3_SOCKET_PATH", False );