Changeset 0850e54 for src


Ignore:
Timestamp:
Dec 15, 2018, 11:49:41 AM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/crepe, fix/ffmpeg5, master
Children:
40bdc14
Parents:
7107ed9
Message:

[io] ensure fwrite are successful in sink_vorbis

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/sink_vorbis.c

    r7107ed9 r0850e54  
    110110
    111111  s->fid = fopen((const char *)s->path, "wb");
    112   if (!s->fid) return AUBIO_FAIL;
     112  if (!s->fid) {
     113    AUBIO_ERR("sink_vorbis: Error opening file %s (%s)\n",
     114        s->path, strerror(errno));
     115    return AUBIO_FAIL;
     116  }
    113117
    114118  vorbis_info_init(&s->vi);
     
    134138  {
    135139    int ret = 0;
     140    size_t wrote;
    136141    ogg_packet header;
    137142    ogg_packet header_comm;
     
    150155      ret = ogg_stream_flush(&s->os, &s->og);
    151156      if (ret==0) break;
    152       fwrite(s->og.header, 1, s->og.header_len, s->fid);
    153       fwrite(s->og.body,   1, s->og.body_len,   s->fid);
     157      wrote = fwrite(s->og.header, 1, s->og.header_len, s->fid);
     158      ret = (wrote == (unsigned)s->og.header_len);
     159      wrote = fwrite(s->og.body,   1, s->og.body_len,   s->fid);
     160      ret &= (wrote == (unsigned)s->og.body_len);
     161      if (ret == 0) {
     162        AUBIO_ERR("sink_vorbis: failed writing \'%s\' to disk (%s)\n",
     163            s->path, strerror(errno));
     164        return AUBIO_FAIL;
     165      }
    154166    }
    155167  }
     
    195207void aubio_sink_vorbis_write(aubio_sink_vorbis_t *s)
    196208{
     209  int result;
     210  size_t wrote;
    197211  // pre-analysis
    198212  while (vorbis_analysis_blockout(&s->vd, &s->vb) == 1) {
     
    206220
    207221      while (1) {
    208         int result = ogg_stream_pageout (&s->os, &s->og);
     222        result = ogg_stream_pageout (&s->os, &s->og);
    209223        if (result == 0) break;
    210         fwrite(s->og.header, 1, s->og.header_len, s->fid);
    211         fwrite(s->og.body,   1, s->og.body_len,   s->fid);
     224        wrote = fwrite(s->og.header, 1, s->og.header_len, s->fid);
     225        result = (wrote == (unsigned)s->og.header_len);
     226        wrote = fwrite(s->og.body, 1, s->og.body_len,     s->fid);
     227        result &= (wrote == (unsigned)s->og.body_len);
     228        if (result == 0) {
     229          AUBIO_WRN("sink_vorbis: failed writing \'%s\' to disk (%s)\n",
     230              s->path, strerror(errno));
     231        }
    212232        if (ogg_page_eos(&s->og)) break;
    213233      }
Note: See TracChangeset for help on using the changeset viewer.