assembler: don't crash if label is undefined
[rofl0r-agsutils.git] / ByteArray.h
blobc8f5e2a8f631d0fd2c59978c704132fd409cbcc4
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,
33 struct ByteArray {
34 int type;
35 int flags;
36 enum ByteArray_Endianess endian;
37 enum ByteArray_Endianess sys_endian;
38 off_t pos;
39 off_t size;
40 struct {
41 MG mem;
42 int fd;
43 } source;
44 ssize_t (*readMultiByte)(struct ByteArray*, char*, size_t);
45 unsigned int (*readUnsignedInt)(struct ByteArray*);
46 signed int (*readInt)(struct ByteArray*);
47 unsigned short (*readUnsignedShort)(struct ByteArray*);
48 signed short (*readShort)(struct ByteArray*);
49 unsigned char (*readUnsignedByte)(struct ByteArray*);
50 signed char (*readByte)(struct ByteArray*);
51 off_t (*readBytes) (struct ByteArray* self, struct ByteArray *dest, off_t start, off_t len);
52 off_t (*bytesAvailable)(struct ByteArray*);
53 off_t (*writeByte) (struct ByteArray* self, signed char what);
54 off_t (*writeUnsignedByte) (struct ByteArray* self, unsigned char what);
55 off_t (*writeShort) (struct ByteArray* self, signed short what);
56 off_t (*writeUnsignedShort) (struct ByteArray* self, unsigned short what);
57 off_t (*writeInt) (struct ByteArray* self, signed int what);
58 off_t (*writeUnsignedInt) (struct ByteArray* self, unsigned int what);
59 off_t (*writeMem) (struct ByteArray* self, unsigned char* what, size_t len);
60 off_t (*writeUTFBytes) (struct ByteArray* self, char* what);
61 off_t (*writeBytes) (struct ByteArray* self, struct ByteArray* what);
62 off_t (*writeFloat) (struct ByteArray* self, float what);
63 int (*set_position_rel) (struct ByteArray* self, int rel);
64 int (*set_position) (struct ByteArray* self, off_t pos);
65 off_t (*get_position) (struct ByteArray* self);
68 void ByteArray_defaults(struct ByteArray* self);
69 void ByteArray_ctor(struct ByteArray* self);
70 struct ByteArray* ByteArray_new(void);
72 void ByteArray_set_endian(struct ByteArray* self, enum ByteArray_Endianess endian);
73 void ByteArray_set_flags(struct ByteArray *self, int flags);
74 enum ByteArray_Endianess ByteArray_get_endian(struct ByteArray* self);
76 int ByteArray_open_file(struct ByteArray* self, const char* filename);
77 void ByteArray_close_file(struct ByteArray *self);
78 int ByteArray_open_mem(struct ByteArray* self, char* data, size_t size);
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 int ByteArray_readUnsignedInt(struct ByteArray* self);
92 int ByteArray_readInt(struct ByteArray* self);
93 unsigned short ByteArray_readUnsignedShort(struct ByteArray* self);
94 short ByteArray_readShort(struct ByteArray* self);
95 unsigned char ByteArray_readUnsignedByte(struct ByteArray* self);
96 signed char ByteArray_readByte(struct ByteArray* self);
97 off_t ByteArray_readBytes(struct ByteArray* self, struct ByteArray *dest, off_t start, off_t len);
99 off_t ByteArray_writeByte(struct ByteArray* self, signed char what);
100 off_t ByteArray_writeUnsignedByte(struct ByteArray* self, unsigned char what);
101 off_t ByteArray_writeShort(struct ByteArray* self, signed short what);
102 off_t ByteArray_writeUnsignedShort(struct ByteArray* self, unsigned short what);
103 off_t ByteArray_writeInt(struct ByteArray* self, signed int what);
104 off_t ByteArray_writeUnsignedInt(struct ByteArray* self, unsigned int what);
105 off_t ByteArray_writeFloat(struct ByteArray* self, float what);
106 off_t ByteArray_writeMem(struct ByteArray* self, unsigned char* what, size_t len);
107 off_t ByteArray_writeUTFBytes(struct ByteArray* self, char* what);
108 off_t ByteArray_writeBytes(struct ByteArray* self, struct ByteArray* what);
110 unsigned char ByteArray_getUnsignedByte(struct ByteArray* self, off_t index);
111 void ByteArray_setUnsignedByte(struct ByteArray* self, off_t index, unsigned char what);
113 void ByteArray_dump_to_stream(struct ByteArray* self, FILE *out);
114 void ByteArray_dump_to_file(struct ByteArray* self, char* filename);
116 #ifdef __cplusplus
118 #endif
120 #pragma RcB2 DEP "ByteArray.c"
122 #endif