vfs: check userland buffers before reading them.
[haiku.git] / src / libs / icon / flat_icon / LittleEndianBuffer.h
blobec32df17d5bd6b79485fd6537619ca2b2755d862
1 /*
2 * Copyright 2006-2007, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Stephan Aßmus <superstippi@gmx.de>
7 */
8 #ifndef LITTLE_ENDIAN_BUFFER_H
9 #define LITTLE_ENDIAN_BUFFER_H
12 #include <SupportDefs.h>
14 #include "IconBuild.h"
17 _BEGIN_ICON_NAMESPACE
20 class LittleEndianBuffer {
21 public:
22 LittleEndianBuffer();
23 LittleEndianBuffer(size_t size);
24 LittleEndianBuffer(uint8* buffer,
25 size_t size);
26 ~LittleEndianBuffer();
28 bool Write(uint8 value);
29 bool Write(uint16 value);
30 bool Write(uint32 value);
31 bool Write(float value);
32 bool Write(double value);
34 bool Write(const LittleEndianBuffer& other);
35 bool Write(const uint8* buffer, size_t bytes);
37 bool Read(uint8& value);
38 bool Read(uint16& value);
39 bool Read(uint32& value);
40 bool Read(float& value);
41 bool Read(double& value);
42 bool Read(LittleEndianBuffer& other, size_t bytes);
44 void Skip(size_t bytes);
46 uint8* Buffer() const
47 { return fBuffer; }
48 size_t SizeUsed() const
49 { return fHandle - fBuffer; }
51 void Reset();
53 private:
54 void _SetSize(size_t size);
56 uint8* fBuffer;
57 uint8* fHandle;
58 uint8* fBufferEnd;
59 size_t fSize;
60 bool fOwnsBuffer;
64 _END_ICON_NAMESPACE
67 #endif // LITTLE_ENDIAN_BUFFER_H