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
This commit is contained in:
Sean Bright
2017-04-21 13:04:44 -04:00
parent 8df729517e
commit f5b67871df
19 changed files with 198 additions and 70 deletions

View File

@@ -422,8 +422,16 @@ static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext)
int res;
if ((res = fread(msdata, 1, MSGSM_FRAME_SIZE, s->f)) != MSGSM_FRAME_SIZE) {
if (res && (res != 1))
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), MSGSM_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;
}
/* Convert from MS format to two real GSM frames */
@@ -511,7 +519,7 @@ static int wav_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
int i;
fseek(fs->f, 0, SEEK_END);
for (i=0; i< (offset - max) / MSGSM_FRAME_SIZE; i++) {
if (!fwrite(msgsm_silence, 1, MSGSM_FRAME_SIZE, fs->f)) {
if (fwrite(msgsm_silence, 1, MSGSM_FRAME_SIZE, fs->f) != MSGSM_FRAME_SIZE) {
ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno));
}
}