Changeset f5a97ed for src


Ignore:
Timestamp:
Dec 20, 2018, 5:31:05 PM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
Children:
ec3f25f9
Parents:
a2b7187
Message:

[sink_wavwrite] check fseek and fwrite return values

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/sink_wavwrite.c

    ra2b7187 rf5a97ed  
    289289  uint_t data_size = s->total_frames_written * s->bitspersample * s->channels / 8;
    290290  unsigned char buf[5];
     291  size_t written = 0, err = 0;
    291292  if (!s->fid) return AUBIO_FAIL;
    292293  // ChunkSize
    293   fseek(s->fid, 4, SEEK_SET);
    294   fwrite(write_little_endian(data_size + 36, buf, 4), 4, 1, s->fid);
     294  err += fseek(s->fid, 4, SEEK_SET);
     295  written += fwrite(write_little_endian(data_size + 36, buf, 4), 4, 1, s->fid);
    295296  // Subchunk2Size
    296   fseek(s->fid, 40, SEEK_SET);
    297   fwrite(write_little_endian(data_size, buf, 4), 4, 1, s->fid);
     297  err += fseek(s->fid, 40, SEEK_SET);
     298  written += fwrite(write_little_endian(data_size, buf, 4), 4, 1, s->fid);
     299  if (written != 2 || err != 0) {
     300    char errorstr[256];
     301    AUBIO_STRERROR(errno, errorstr, sizeof(errorstr));
     302    AUBIO_WRN("sink_wavwrite: updating header of %s failed, expected %d"
     303        " write but got only %d (%s)\n", s->path, 2, written, errorstr);
     304  }
    298305  // close file
    299306  if (fclose(s->fid)) {
    300     AUBIO_ERR("sink_wavwrite: Error closing file %s (%s)\n", s->path, strerror(errno));
     307    char errorstr[256];
     308    AUBIO_STRERROR(errno, errorstr, sizeof(errorstr));
     309    AUBIO_ERR("sink_wavwrite: Error closing file %s (%s)\n", s->path, errorstr);
    301310  }
    302311  s->fid = NULL;
Note: See TracChangeset for help on using the changeset viewer.