1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 2010-2019 EDuke32 developers and contributors
4 Copyright (C) 2019 Nuke.YKT
5 
6 This file is part of NBlood.
7 
8 NBlood is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License version 2
10 as published by the Free Software Foundation.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 
16 See the GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 */
22 //-------------------------------------------------------------------------
23 #include <stdlib.h>
24 #include <string.h>
25 #include "compat.h"
26 #include "common_game.h"
27 #include "iob.h"
28 
IOBuffer(int _nRemain,char * _pBuffer)29 IOBuffer::IOBuffer(int _nRemain, char *_pBuffer)
30 {
31     nRemain = _nRemain;
32     pBuffer =_pBuffer;
33 }
34 
Read(void * pData,int nSize)35 void IOBuffer::Read(void *pData, int nSize)
36 {
37     if (nSize <= nRemain)
38     {
39         memcpy(pData, pBuffer, nSize);
40         nRemain -= nSize;
41         pBuffer += nSize;
42     }
43     else
44     {
45         ThrowError("Read buffer overflow");
46     }
47 }
48 
Write(void * pData,int nSize)49 void IOBuffer::Write(void *pData, int nSize)
50 {
51     if (nSize <= nRemain)
52     {
53         memcpy(pBuffer, pData, nSize);
54         nRemain -= nSize;
55         pBuffer += nSize;
56     }
57     else
58     {
59         ThrowError("Write buffer overflow");
60     }
61 }
62 
Skip(int nSize)63 void IOBuffer::Skip(int nSize)
64 {
65     if (nSize <= nRemain)
66     {
67         nRemain -= nSize;
68         pBuffer += nSize;
69     }
70     else
71     {
72         ThrowError("Skip overflow");
73     }
74 }
75