static char* fluid_file_read_full(fluid_file fp, size_t* length) { size_t buflen; char* buffer; size_t n; /* Work out the length of the file in advance */ if (FLUID_FSEEK(fp, 0, SEEK_END) != 0) { FLUID_LOG(FLUID_ERR, "File load: Could not seek within file"); return NULL; } buflen = ftell(fp); if (FLUID_FSEEK(fp, 0, SEEK_SET) != 0) { FLUID_LOG(FLUID_ERR, "File load: Could not seek within file"); return NULL; } FLUID_LOG(FLUID_DBG, "File load: Allocating %d bytes", buflen); buffer = FLUID_MALLOC(buflen); if (buffer == NULL) { FLUID_LOG(FLUID_PANIC, "Out of memory"); return NULL; } n = FLUID_FREAD(buffer, 1, buflen, fp); if (n != buflen) { FLUID_LOG(FLUID_ERR, "Only read %d bytes; expected %d", n, buflen); FLUID_FREE(buffer); return NULL; }; *length = n; return buffer; }
/* * fluid_midi_file_read */ int fluid_midi_file_read(fluid_midi_file* mf, void* buf, int len) { int num = FLUID_FREAD(buf, 1, len, mf->fp); mf->trackpos += num; #if DEBUG if (num != len) { FLUID_LOG(FLUID_DBG, "Coulnd't read the requested number of bytes"); } #endif return (num != len)? FLUID_FAILED : FLUID_OK; }
/* * Get the next byte in a MIDI file. */ int fluid_midi_file_getc(fluid_midi_file* mf) { unsigned char c; int n; if (mf->c >= 0) { c = mf->c; mf->c = -1; } else { n = FLUID_FREAD(&c, 1, 1, mf->fp); mf->trackpos++; } return (int) c; }
size_t read_file(void *fh, void *ptr, size_t size){ // printf("READ %d\n",size); return FLUID_FREAD(ptr, 1, size, (fluid_file)fh); }