diff options
author | Sean Bright <sean.bright@gmail.com> | 2017-04-21 13:04:44 -0400 |
---|---|---|
committer | Sean Bright <sean.bright@gmail.com> | 2017-04-25 16:24:37 -0500 |
commit | 1b50df78d069632e5607e2937461a33d7f568431 (patch) | |
tree | e9768588d01be3d2a2c1de11821fe59b138e5000 /formats/format_gsm.c | |
parent | f7ca69809a0c39be4cf42844c7d7d474e68d8305 (diff) |
cleanup: Fix fread() and fwrite() error handling
Cleaned up some of the incorrect uses of fread() and fwrite(), mostly in
the format modules. Neither of these functions will ever return a value
less than 0, which we were checking for in some cases.
I've introduced a fair amount of duplication in the format modules, but
I plan to change how format modules work internally in a subsequent
patch set, so this is simply a stop-gap.
Change-Id: I8ca1cd47c20b2c0b72088bd13b9046f6977aa872
Diffstat (limited to 'formats/format_gsm.c')
-rw-r--r-- | formats/format_gsm.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/formats/format_gsm.c b/formats/format_gsm.c index 54c4b8ffa..07aba9f19 100644 --- a/formats/format_gsm.c +++ b/formats/format_gsm.c @@ -57,10 +57,18 @@ static struct ast_frame *gsm_read(struct ast_filestream *s, int *whennext) { int res; - AST_FRAME_SET_BUFFER(&(s->fr), s->buf, AST_FRIENDLY_OFFSET, GSM_FRAME_SIZE) + AST_FRAME_SET_BUFFER(&(s->fr), s->buf, AST_FRIENDLY_OFFSET, GSM_FRAME_SIZE); if ((res = fread(s->fr.data.ptr, 1, GSM_FRAME_SIZE, s->f)) != GSM_FRAME_SIZE) { - if (res) - ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno)); + if (feof(s->f)) { + if (res) { + ast_log(LOG_WARNING, "Incomplete frame data at end of %s file " + "(expected %d bytes, read %d)\n", + ast_format_get_name(s->fr.subclass.format), GSM_FRAME_SIZE, res); + } + } else { + ast_log(LOG_ERROR, "Error while reading %s file: %s\n", + ast_format_get_name(s->fr.subclass.format), strerror(errno)); + } return NULL; } *whennext = s->fr.samples = GSM_SAMPLES; @@ -133,7 +141,7 @@ static int gsm_seek(struct ast_filestream *fs, off_t sample_offset, int whence) int i; fseeko(fs->f, 0, SEEK_END); for (i=0; i< (offset - max) / GSM_FRAME_SIZE; i++) { - if (!fwrite(gsm_silence, 1, GSM_FRAME_SIZE, fs->f)) { + if (fwrite(gsm_silence, 1, GSM_FRAME_SIZE, fs->f) != GSM_FRAME_SIZE) { ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); } } |