diff options
author | Matthew Fredrickson <creslin@digium.com> | 2006-01-20 21:36:33 +0000 |
---|---|---|
committer | Matthew Fredrickson <creslin@digium.com> | 2006-01-20 21:36:33 +0000 |
commit | 52fe16259b23f5820b65486d82963e5b8b23851e (patch) | |
tree | a505f7710460e8e2a46fe2a7d8fac675705bf95e /formats/format_pcm_alaw.c | |
parent | 1946020208baa6214dfab9f41d6a031366bb7877 (diff) |
Fix for formats so they give better output on failure conditions. (#6141)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@8357 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'formats/format_pcm_alaw.c')
-rw-r--r-- | formats/format_pcm_alaw.c | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/formats/format_pcm_alaw.c b/formats/format_pcm_alaw.c index 13d7c174a..ffbb17a4f 100644 --- a/formats/format_pcm_alaw.c +++ b/formats/format_pcm_alaw.c @@ -252,6 +252,7 @@ static int pcm_write(struct ast_filestream *fs, struct ast_frame *f) static int pcm_seek(struct ast_filestream *fs, long sample_offset, int whence) { long cur, max, offset = 0; + int ret = -1; /* assume error */ cur = ftell(fs->f); fseek(fs->f, 0, SEEK_END); @@ -268,29 +269,34 @@ static int pcm_seek(struct ast_filestream *fs, long sample_offset, int whence) case SEEK_FORCECUR: offset = cur + sample_offset; break; + default: + ast_log(LOG_WARNING, "invalid whence %d, assuming SEEK_SET\n", whence); + offset = sample_offset; } - switch (whence) { - case SEEK_FORCECUR: - if (offset > max) { - size_t left = offset - max; - size_t res; - - while (left) { - res = fwrite(alaw_silence, sizeof(alaw_silence[0]), - (left > BUF_SIZE) ? BUF_SIZE : left, fs->f); - if (res == -1) - return res; - left -= res * sizeof(alaw_silence[0]); - } - return offset; + if (offset < 0) { + offset = 0; + ast_log(LOG_WARNING, "negative offset %ld, resetting to 0\n", offset); + } + if (whence == SEEK_FORCECUR && offset > max) { + size_t left = offset - max; + + while (left) { + size_t written = fwrite(alaw_silence, sizeof(alaw_silence[0]), + (left > BUF_SIZE) ? BUF_SIZE : left, fs->f); + if (written == -1) + break; /* error */ + left -= written * sizeof(alaw_silence[0]); } - /* fall through */ - default: - offset = (offset > max) ? max : offset; - offset = (offset < 0) ? 0 : offset; - return fseek(fs->f, offset, SEEK_SET); + ret = 0; /* success */ + } else { + if (offset > max) { + ast_log(LOG_WARNING, "offset too large %ld, truncating to %ld\n", offset, max); + offset = max; + } + ret = fseek(fs->f, offset, SEEK_SET); } + return ret; } static int pcm_trunc(struct ast_filestream *fs) |