1 /*
2  * MP3val - a program for MPEG audio file validation
3  * Copyright (C) 2005-2009 Alexey Kuznetsov (ring0) and Eugen Tikhonov (jetsys)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19 
20 #include "out.h"
21 #include "crossapi.h"
22 
23 static int iPrevSize=0;
24 
GetLastFrameSize()25 int GetLastFrameSize() {
26 	return iPrevSize;
27 }
28 
WriteToFile(int hFile,char * baseptr,int index,int bytes,int iFileSize)29 int WriteToFile(int hFile,char *baseptr,int index,int bytes,int iFileSize) {
30 	int tmp;
31 	int iBytesWritten,iBytesWrittenTotal=0;
32 
33 	if(bytes<0) {
34 		if(iPrevSize) CrossAPI_SetFilePointer(hFile,-iPrevSize,true);
35 		tmp=iPrevSize;
36 		iPrevSize=0;
37 		return tmp;
38 	}
39 
40 	if(iFileSize>=0) {
41 		if(index+bytes>iFileSize) bytes=iFileSize-index;
42 	}
43 
44 	while(iBytesWrittenTotal<bytes) {
45 		if(!CrossAPI_WriteFile(hFile,&baseptr[index+iBytesWrittenTotal],bytes-iBytesWrittenTotal,&iBytesWritten)) {
46 			return -1;
47 		}
48 		iBytesWrittenTotal+=iBytesWritten;
49 	}
50 
51 	iPrevSize=bytes;
52 
53 	return bytes;
54 }
55