hbmap: fix iterator truncation when size_t < 32bit
[rofl0r-agsutils.git] / ByteArray.h
blobb67f07bf4f29894e6ca040742d113c7b7ee9e715
1 /* (C) 2011 - 2012 rofl0r.
2 Permission for use by AGS is hereby granted. */
4 #ifndef BYTEARRAY_H
5 #define BYTEARRAY_H
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
11 #include <unistd.h>
12 #include <sys/stat.h>
13 #include <fcntl.h>
14 #include <string.h>
15 #include <stdio.h>
16 #include "MemGrow.h"
18 enum ByteArray_Endianess {
19 BAE_BIG,
20 BAE_LITTLE,
23 enum ByteArray_Type {
24 BAT_MEMSTREAM,
25 BAT_FILESTREAM,
28 enum ByteArray_Flags {
29 BAF_CANGROW = 1,
32 struct ByteArray {
33 int type;
34 int flags;
35 enum ByteArray_Endianess endian;
36 enum ByteArray_Endianess sys_endian;
37 off_t pos;
38 off_t size;
39 MG source_mem;
40 int source_fd;
41 const char *filename;
42 ssize_t (*readMultiByte)(struct ByteArray*, char*, size_t);
43 unsigned long long (*readUnsignedLongLong)(struct ByteArray*);
44 unsigned int (*readUnsignedInt)(struct ByteArray*);
45 signed int (*readInt)(struct ByteArray*);
46 unsigned short (*readUnsignedShort)(struct ByteArray*);
47 signed short (*readShort)(struct ByteArray*);
48 unsigned char (*readUnsignedByte)(struct ByteArray*);
49 signed char (*readByte)(struct ByteArray*);
50 off_t (*readBytes) (struct ByteArray* self, struct ByteArray *dest, off_t start, off_t len);
51 off_t (*bytesAvailable)(struct ByteArray*);
52 off_t (*writeByte) (struct ByteArray* self, signed char what);
53 off_t (*writeUnsignedByte) (struct ByteArray* self, unsigned char what);
54 off_t (*writeShort) (struct ByteArray* self, signed short what);
55 off_t (*writeUnsignedShort) (struct ByteArray* self, unsigned short what);
56 off_t (*writeInt) (struct ByteArray* self, signed int what);
57 off_t (*writeUnsignedInt) (struct ByteArray* self, unsigned int what);
58 off_t (*writeMem) (struct ByteArray* self, unsigned char* what, size_t len);
59 off_t (*writeUTFBytes) (struct ByteArray* self, char* what);
60 off_t (*writeBytes) (struct ByteArray* self, struct ByteArray* what);
61 off_t (*writeFloat) (struct ByteArray* self, float what);
62 int (*set_position_rel) (struct ByteArray* self, int rel);
63 int (*set_position) (struct ByteArray* self, off_t pos);
64 off_t (*get_position) (struct ByteArray* self);
67 void ByteArray_defaults(struct ByteArray* self);
68 void ByteArray_ctor(struct ByteArray* self);
69 struct ByteArray* ByteArray_new(void);
71 void ByteArray_set_endian(struct ByteArray* self, enum ByteArray_Endianess endian);
72 void ByteArray_set_flags(struct ByteArray *self, int flags);
73 enum ByteArray_Endianess ByteArray_get_endian(struct ByteArray* self);
75 int ByteArray_open_file(struct ByteArray* self, const char* filename);
76 void ByteArray_close_file(struct ByteArray *self);
77 int ByteArray_open_mem(struct ByteArray* self, char* data, size_t size);
78 void* ByteArray_get_mem(struct ByteArray* self, size_t offset, size_t byteswanted);
79 void ByteArray_clear(struct ByteArray* self);
80 void ByteArray_close(struct ByteArray* self);
82 void ByteArray_set_length(struct ByteArray* self, off_t len);
83 off_t ByteArray_get_length(struct ByteArray* self);
85 off_t ByteArray_get_position(struct ByteArray* self);
86 int ByteArray_set_position(struct ByteArray* self, off_t pos);
87 int ByteArray_set_position_rel(struct ByteArray* self, int rel);
88 off_t ByteArray_bytesAvailable(struct ByteArray* self);
90 ssize_t ByteArray_readMultiByte(struct ByteArray* self, char* buffer, size_t len);
91 unsigned long long ByteArray_readUnsignedLongLong(struct ByteArray* self);
92 unsigned int ByteArray_readUnsignedInt(struct ByteArray* self);
93 int ByteArray_readInt(struct ByteArray* self);
94 unsigned short ByteArray_readUnsignedShort(struct ByteArray* self);
95 short ByteArray_readShort(struct ByteArray* self);
96 unsigned char ByteArray_readUnsignedByte(struct ByteArray* self);
97 signed char ByteArray_readByte(struct ByteArray* self);
98 off_t ByteArray_readBytes(struct ByteArray* self, struct ByteArray *dest, off_t start, off_t len);
100 off_t ByteArray_writeByte(struct ByteArray* self, signed char what);
101 off_t ByteArray_writeUnsignedByte(struct ByteArray* self, unsigned char what);
102 off_t ByteArray_writeShort(struct ByteArray* self, signed short what);
103 off_t ByteArray_writeUnsignedShort(struct ByteArray* self, unsigned short what);
104 off_t ByteArray_writeInt(struct ByteArray* self, signed int what);
105 off_t ByteArray_writeUnsignedInt(struct ByteArray* self, unsigned int what);
106 off_t ByteArray_writeFloat(struct ByteArray* self, float what);
107 off_t ByteArray_writeMem(struct ByteArray* self, unsigned char* what, size_t len);
108 off_t ByteArray_writeUTFBytes(struct ByteArray* self, char* what);
109 off_t ByteArray_writeBytes(struct ByteArray* self, struct ByteArray* what);
111 unsigned char ByteArray_getUnsignedByte(struct ByteArray* self, off_t index);
112 void ByteArray_setUnsignedByte(struct ByteArray* self, off_t index, unsigned char what);
114 void ByteArray_dump_to_stream(struct ByteArray* self, FILE *out);
115 void ByteArray_dump_to_file(struct ByteArray* self, char* filename);
117 #ifdef __cplusplus
119 #endif
121 #pragma RcB2 DEP "ByteArray.c"
123 #endif