Blender  V2.93
Stream.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 /* simple memory stream functions with buffer overflow check */
22 
23 #pragma once
24 
25 struct Stream {
26  unsigned char *mem; /* location in memory */
27  unsigned int size; /* size */
28  unsigned int pos; /* current position */
29  bool failed; /* error occurred when seeking */
30  Stream(unsigned char *m, unsigned int s) : mem(m), size(s), pos(0), failed(false)
31  {
32  }
33  unsigned int seek(unsigned int p);
34  void set_failed(const char *msg);
35 };
36 
37 unsigned int mem_read(Stream &mem, unsigned long long &i);
38 unsigned int mem_read(Stream &mem, unsigned int &i);
39 unsigned int mem_read(Stream &mem, unsigned short &i);
40 unsigned int mem_read(Stream &mem, unsigned char &i);
41 unsigned int mem_read(Stream &mem, unsigned char *i, unsigned int cnt);
unsigned int mem_read(Stream &mem, unsigned long long &i)
Definition: Stream.cpp:56
Definition: Stream.h:25
bool failed
Definition: Stream.h:29
void set_failed(const char *msg)
Definition: Stream.cpp:111
unsigned int seek(unsigned int p)
Definition: Stream.cpp:44
unsigned int size
Definition: Stream.h:27
unsigned int pos
Definition: Stream.h:28
Stream(unsigned char *m, unsigned int s)
Definition: Stream.h:30
unsigned char * mem
Definition: Stream.h:26