diff --git a/src/midi/fluid_midi.c b/src/midi/fluid_midi.c index eb3d7e57..fb71a822 100644 --- a/src/midi/fluid_midi.c +++ b/src/midi/fluid_midi.c @@ -92,24 +92,23 @@ static int fluid_midi_file_get_division(fluid_midi_file *midifile); */ int fluid_is_midifile(const char *filename) { - FILE *fp = FLUID_FOPEN(filename, "rb"); + FILE *fp; uint32_t id; int retcode = FALSE; do { - if(fp == NULL) + if(!fluid_file_test(filename, G_FILE_TEST_IS_REGULAR)) { return retcode; } - // file exists and we have permission to open it - // now, test whether it's acutally a regular file or a symlink to such - if(!fluid_file_test(filename, G_FILE_TEST_IS_REGULAR)) + // file seems to exist and is a regular file or a symlink to such + if((fp = FLUID_FOPEN(filename, "rb")) == NULL) { - break; + return retcode; } - + if(FLUID_FREAD(&id, sizeof(id), 1, fp) != 1) { break; diff --git a/src/sfloader/fluid_sffile.c b/src/sfloader/fluid_sffile.c index 99da1a9a..b5a641b6 100644 --- a/src/sfloader/fluid_sffile.c +++ b/src/sfloader/fluid_sffile.c @@ -334,24 +334,23 @@ static int fluid_sffile_read_wav(SFData *sf, unsigned int start, unsigned int en */ int fluid_is_soundfont(const char *filename) { - FILE *fp = FLUID_FOPEN(filename, "rb"); + FILE *fp; uint32_t fcc; int retcode = FALSE; do { - if(fp == NULL) + if(!fluid_file_test(filename, G_FILE_TEST_IS_REGULAR)) { return retcode; } - // file exists and we have permission to open it - // now, test whether it's acutally a regular file or a symlink to such - if(!fluid_file_test(filename, G_FILE_TEST_IS_REGULAR)) + // file seems to exist and is a regular file or a symlink to such + if((fp = FLUID_FOPEN(filename, "rb")) == NULL) { - break; + return retcode; } - + if(FLUID_FREAD(&fcc, sizeof(fcc), 1, fp) != 1) { break; diff --git a/src/sfloader/fluid_sfont.c b/src/sfloader/fluid_sfont.c index 8de6ce07..d0ce264d 100644 --- a/src/sfloader/fluid_sfont.c +++ b/src/sfloader/fluid_sfont.c @@ -24,21 +24,26 @@ void *default_fopen(const char *path) { - FILE* handle = FLUID_FOPEN(path, "rb"); + FILE* handle; - if(handle == NULL) + if(!fluid_file_test(path, G_FILE_TEST_EXISTS)) { - FLUID_LOG(FLUID_ERR, "fluid_sfloader_load(): Specified file does not exists or insufficient permissions to open it! ('%s')", path); + FLUID_LOG(FLUID_ERR, "fluid_sfloader_load(): Unable to load non-existent file. ('%s')", path); return NULL; } if(!fluid_file_test(path, G_FILE_TEST_IS_REGULAR)) { - FLUID_FCLOSE(handle); FLUID_LOG(FLUID_ERR, "fluid_sfloader_load(): Refusing to load non-regular file! ('%s')", path); return NULL; } + if((handle = FLUID_FOPEN(path, "rb")) == NULL) + { + FLUID_LOG(FLUID_ERR, "fluid_sfloader_load(): Specified file does not exists or insufficient permissions to open it! ('%s')", path); + return NULL; + } + return handle; }