[Asterisk-Dev] behaviour of ast_writefile (file.c) and wav_rewrite (format_wav.c)

Todd goldfita at rose-hulman.edu
Thu Jan 13 12:28:09 MST 2005


Hi all,

(I'm working with an asterisk that's a few months old - sorry if this is
out of date.)

A while back I needed to resume a recording from an application.  I called
ast_writefile with the O_APPEND flag thinking that would do the trick. 
That, unfortunately, caused the header to be written to the middle of the
file because append treats all writes as relative to where the end of the
file used to be.  So I opened up format_wav.c and wrapped

if(comment!=NULL) {
    ...
}

around

if (write_header(fd)) {
    free(tmp);
    return NULL;
}

in wav_rewrite.  (I'm only using wav files.)  Now, if I set comment to
NULL in ast_writefile, the header is no longer written where it shouldn't
be, but  the file gets truncated.  I thought maybe the trunc function
wasn't working relative to where the end of the file was in append mode,
but I'm not sure.  Finally, I commented the following in ast_writefile:

/* set the O_TRUNC flag if and only if there is no O_APPEND specified */
//if (!(flags & O_APPEND))
//  myflags = O_TRUNC;
fd = open(fn, /*flags |*/ myflags, mode);

I had to do this so it wasn't forced into O_TRUNC or O_APPEND mode.  And I
can just set flags to 0.  Now it works, but I'd like to do it without the
kludge and without making any code changes.

thanks in advance

-Todd




More information about the asterisk-dev mailing list