reorder calls to fluid_file_test

This commit is contained in:
derselbst 2019-02-03 14:28:31 +01:00
parent ff6377a3bd
commit 12dd1c7653
3 changed files with 21 additions and 18 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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;
}