]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Per the man page, setvbuf() must be called before any other operation on an open...
authorSean Bright <sean@malleable.com>
Wed, 26 Jan 2011 01:24:58 +0000 (01:24 +0000)
committerSean Bright <sean@malleable.com>
Wed, 26 Jan 2011 01:24:58 +0000 (01:24 +0000)
We use setvbuf() to associate a buffer with a stream, but we have already written
to the open file.  This works (by chance) on Linux, but fails on other platforms,
such as OpenSolaris.

(closes issue #16610)
Reported by: bklang
Patches:
      setvbuf.patch uploaded by crjw (license 963)
Tested by: bklang, asgaroth, efutch

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.2@304096 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/file.c

index 20cda4929e9a29ccbf02057ae637a0e184d81780..57adf79a61e8e92241e69679e59e8076b62d437a 100644 (file)
@@ -1117,6 +1117,11 @@ struct ast_filestream *ast_writefile(const char *filename, const char *type, con
                if (fd > -1) {
                        errno = 0;
                        fs = get_filestream(f, bfile);
+                       if (fs) {
+                               if ((fs->write_buffer = ast_malloc(32768))) {
+                                       setvbuf(fs->f, fs->write_buffer, _IOFBF, 32768);
+                               }
+                       }
                        if (!fs || rewrite_wrapper(fs, comment)) {
                                ast_log(LOG_WARNING, "Unable to rewrite %s\n", fn);
                                close(fd);
@@ -1143,11 +1148,6 @@ struct ast_filestream *ast_writefile(const char *filename, const char *type, con
                        }
                        fs->vfs = NULL;
                        /* If truncated, we'll be at the beginning; if not truncated, then append */
-
-                       if ((fs->write_buffer = ast_malloc(32768))){
-                               setvbuf(fs->f, fs->write_buffer, _IOFBF, 32768);
-                       }
-
                        f->seek(fs, 0, SEEK_END);
                } else if (errno != EEXIST) {
                        ast_log(LOG_WARNING, "Unable to open file %s: %s\n", fn, strerror(errno));