From 3c94e6137531bd0a358d969acf87693271b24b15 Mon Sep 17 00:00:00 2001 From: "Ying-Chun Liu (PaulLiu)" Date: Fri, 14 Mar 2014 00:25:10 +0800 Subject: [PATCH] Add fseek between intermixed read/write. --- src/wavtool-pl.c | 3 ++- src/wfd.c | 3 +++ src/wfh.c | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/wavtool-pl.c b/src/wavtool-pl.c index 6a5bfea..6b11980 100644 --- a/src/wavtool-pl.c +++ b/src/wavtool-pl.c @@ -184,6 +184,7 @@ int main (int argc, char *argv[]) { char *outwavhdrfilename,*outwavdatfilename; int len; + int result=0; if (parseArgs(argc,argv)!=0) { printusage(); @@ -206,7 +207,7 @@ int main (int argc, char *argv[]) { } len = wfd_append(outwavdatfilename,wavtool_args.inputfilename,wavtool_args.offset,wavtool_args.length,wavtool_args.ovr,wavtool_args.p,wavtool_args.v); - wfh_putlength(outwavhdrfilename,len); + result = wfh_putlength(outwavhdrfilename,len); return 0; } diff --git a/src/wfd.c b/src/wfd.c index 9f524be..e4bfe49 100644 --- a/src/wfd.c +++ b/src/wfd.c @@ -208,6 +208,7 @@ int wfd_append(const char *outputfilename, const char *inputfilename, } } } + fseek(outfile,0,SEEK_CUR); ovr=0.0; ovrFrames=0; } @@ -258,11 +259,13 @@ int wfd_append(const char *outputfilename, const char *inputfilename, r = wfd_mix(sum,d); fputc( (char)(r & (0x00ff)), outfile); fputc( (char)((r>>8) & 0x00ff), outfile); + fseek(outfile,0,SEEK_CUR); ovrFrames--; } else { wfd_append_normal: fputc( (char)(sum & (0x00ff)), outfile); fputc( (char)((sum>>8) & 0x00ff), outfile); + fseek(outfile,0,SEEK_CUR); } currentFrame++; } diff --git a/src/wfh.c b/src/wfh.c index 17351cd..59097ff 100644 --- a/src/wfh.c +++ b/src/wfh.c @@ -198,7 +198,15 @@ int wfh_putlength(const char *filename, int length) { } /* put file size - 8 here */ + if (fseek(file1,4,SEEK_SET)!=0) { + fclose(file1); + return ret; + } wfh_writeint(file1, 4+4+4+ 4+4+2+2+4+4+2+2+4+4+ length -8 ,4); + if (fseek(file1,8,SEEK_SET)!=0) { + fclose(file1); + return ret; + } if (fread(com1,1,4,file1) != 4) { fclose(file1); @@ -236,7 +244,12 @@ int wfh_putlength(const char *filename, int length) { return ret; } + if (fseek(file1,40,SEEK_SET)!=0) { + fclose(file1); + return ret; + } wfh_writeint(file1,length,4); + fclose(file1); ret=0; return ret; -- 2.11.0