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:15 -0500 |
commit | f5b67871df566ddc0f0b6ad22d81a81d8ecce7d7 (patch) | |
tree | 3b45a52fa39a04fc670f1efee2ec1099a56733e7 /formats/format_g719.c | |
parent | 8df729517e32926ea33aa3a40d5abcbf39488e3a (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_g719.c')
-rw-r--r-- | formats/format_g719.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/formats/format_g719.c b/formats/format_g719.c index 8cc942717..572b88f5f 100644 --- a/formats/format_g719.c +++ b/formats/format_g719.c @@ -45,8 +45,16 @@ static struct ast_frame *g719read(struct ast_filestream *s, int *whennext) AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, BUF_SIZE); if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != s->fr.datalen) { - 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), s->fr.datalen, 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 = BYTES_TO_SAMPLES(res); |