Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
check for "sfbk" in fluid_is_soundfont()
  • Loading branch information
derselbst committed Jan 6, 2018
1 parent fe37923 commit 4a61098
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/utils/fluid_sys.c
Expand Up @@ -342,25 +342,32 @@ fluid_is_midifile(const char *filename)
* @param filename Path to the file to check
* @return TRUE if it could be a SoundFont, FALSE otherwise
*
* The current implementation only checks for the "RIFF" header in the file.
* It is useful only to distinguish between SoundFont and MIDI files.
* @note The current implementation only checks for the "RIFF" and "sfbk" headers in
* the file. It is useful to distinguish between SoundFont and other (e.g. MIDI) files.
*/
int
fluid_is_soundfont(const char *filename)
{
FILE* fp = fopen(filename, "rb");
char id[4];
char riff_id[4], sfbk_id[4];

if (fp == NULL) {
return 0;
}
if (fread((void*) id, 1, 4, fp) != 4) {
fclose(fp);
return 0;
if((fread((void*) riff_id, 1, sizeof(riff_id), fp) != sizeof(riff_id)) ||
(fseek(fp, 4, SEEK_CUR) != 0) ||
(fread((void*) sfbk_id, 1, sizeof(sfbk_id), fp) != sizeof(sfbk_id)))
{
goto error_rec;
}

fclose(fp);

return strncmp(id, "RIFF", 4) == 0;
return (FLUID_STRNCMP(riff_id, "RIFF", sizeof(riff_id)) == 0) &&
(FLUID_STRNCMP(sfbk_id, "sfbk", sizeof(sfbk_id)) == 0);

error_rec:
fclose(fp);
return 0;
}

/**
Expand Down

0 comments on commit 4a61098

Please sign in to comment.