src/wav.c : Truncate the file on close for RDWR mode where the file ends up shorter than when it was opened.

This commit is contained in:
Erik de Castro Lopo 2008-12-14 20:22:09 +11:00
parent e9a1817530
commit 7f6c38405a
2 changed files with 18 additions and 0 deletions

View File

@ -4,6 +4,10 @@
Add test for RDWR mode where the file ends up shorter than when it was
opened.
* src/wav.c
Truncate the file on close for RDWR mode where the file ends up shorter
than when it was opened.
2008-11-30 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* M4/add_cflags.m4

View File

@ -1215,6 +1215,20 @@ wav_close (SF_PRIVATE *psf)
if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR)
{ wav_write_tailer (psf) ;
if (psf->mode == SFM_RDWR)
{ sf_count_t current = psf_ftell (psf) ;
/*
** If the mode is RDWR and the current position is less than the
** filelength, truncate the file.
*/
if (current < psf->filelength)
{ psf_ftruncate (psf, current) ;
psf->filelength = current ;
} ;
} ;
psf->write_header (psf, SF_TRUE) ;
} ;