diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2001-06-13 20:36:52 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2001-06-13 20:36:52 +0000 |
commit | b72ac40fe7c573f7e86517448a469a0dd8bb370b (patch) | |
tree | 7f6a7d6269bd373ed96f3f840b13f8fbe86e5399 /file.c | |
parent | f0035ced5e74bf8da8727815f402449318c26b69 (diff) |
Version 0.1.9 from FTP
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@332 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'file.c')
-rwxr-xr-x | file.c | 57 |
1 files changed, 56 insertions, 1 deletions
@@ -146,7 +146,7 @@ int ast_stopstream(struct ast_channel *tmp) if (!tmp->stream) return 0; tmp->stream->fmt->close(tmp->stream); - if (ast_set_write_format(tmp, tmp->oldwriteformat)) + if (tmp->oldwriteformat && ast_set_write_format(tmp, tmp->oldwriteformat)) ast_log(LOG_WARNING, "Unable to restore format back to %d\n", tmp->oldwriteformat); return 0; } @@ -192,6 +192,45 @@ int ast_writestream(struct ast_filestream *fs, struct ast_frame *f) } } +static int copy(char *infile, char *outfile) +{ + int ifd; + int ofd; + int res; + int len; + char buf[4096]; + if ((ifd = open(infile, O_RDONLY)) < 0) { + ast_log(LOG_WARNING, "Unable to open %s in read-only mode\n", infile); + return -1; + } + if ((ofd = open(outfile, O_WRONLY | O_TRUNC | O_CREAT, 0600)) < 0) { + ast_log(LOG_WARNING, "Unable to open %s in write-only mode\n", outfile); + close(ifd); + return -1; + } + do { + len = read(ifd, buf, sizeof(buf)); + if (len < 0) { + ast_log(LOG_WARNING, "Read failed on %s: %s\n", infile, strerror(errno)); + close(ifd); + close(ofd); + unlink(outfile); + } + if (len) { + res = write(ofd, buf, len); + if (res != len) { + ast_log(LOG_WARNING, "Write failed on %s (%d of %d): %s\n", outfile, res, len, strerror(errno)); + close(ifd); + close(ofd); + unlink(outfile); + } + } + } while(len); + close(ifd); + close(ofd); + return 0; +} + static char *build_filename(char *filename, char *ext) { char *fn; @@ -210,6 +249,7 @@ static char *build_filename(char *filename, char *ext) #define ACTION_DELETE 2 #define ACTION_RENAME 3 #define ACTION_OPEN 4 +#define ACTION_COPY 5 static int ast_filehelper(char *filename, char *filename2, char *fmt, int action) { @@ -265,6 +305,16 @@ static int ast_filehelper(char *filename, char *filename2, char *fmt, int action } else ast_log(LOG_WARNING, "Out of memory\n"); break; + case ACTION_COPY: + nfn = build_filename(filename2, ext); + if (nfn) { + res = copy(fn, nfn); + if (res) + ast_log(LOG_WARNING, "copy(%s,%s) failed: %s\n", fn, nfn, strerror(errno)); + free(nfn); + } else + ast_log(LOG_WARNING, "Out of memory\n"); + break; case ACTION_OPEN: if ((ret < 0) && ((chan->writeformat & f->format))) { ret = open(fn, O_RDONLY); @@ -343,6 +393,11 @@ int ast_filerename(char *filename, char *filename2, char *fmt) return ast_filehelper(filename, filename2, fmt, ACTION_RENAME); } +int ast_filecopy(char *filename, char *filename2, char *fmt) +{ + return ast_filehelper(filename, filename2, fmt, ACTION_COPY); +} + int ast_streamfile(struct ast_channel *chan, char *filename, char *preflang) { /* This is a fairly complex routine. Essentially we should do |