File: osmem.h

package info (click to toggle)
capi4hylafax 1%3A01.02.03-10sarge2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,856 kB
  • ctags: 2,966
  • sloc: cpp: 20,126; sh: 7,703; makefile: 215; perl: 36
file content (298 lines) | stat: -rw-r--r-- 8,273 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/*---------------------------------------------------------------------------*\

    Copyright (C) 2000 AVM GmbH. All rights reserved.

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY, without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, and WITHOUT
    ANY LIABILITY FOR ANY DAMAGES arising out of or in connection
    with the use or performance of this software. See the
    GNU General Public License for further details.

\*---------------------------------------------------------------------------*/

#ifndef _osmem_h
#define _osmem_h

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
#include "aString.h"

#define ISALIGNED(p)   (0 == (PtrToUlong (p) & 3))

/*===========================================================================*\
\*===========================================================================*/

void*   getPtr(tUByte *m);
tUInt64 get64 (tUByte *m);
tUInt32 get32 (tUByte *m);
tUInt16 get16 (tUByte *m);
tUByte  get8  (tUByte *m);

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/

tUInt64 getNBO64 (tUByte *m);       // Network Byte Order
tUInt32 getNBO32 (tUByte *m);
tUInt16 getNBO16 (tUByte *m);

tUInt64 getLE64 (tUByte *m);        // Little Endian
tUInt32 getLE32 (tUByte *m);
tUInt16 getLE16 (tUByte *m);

tUInt64 getBE64 (tUByte *m);        // Big Endian
tUInt32 getBE32 (tUByte *m);
tUInt16 getBE16 (tUByte *m);

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/

tUInt64 getNBO64 (tUInt64 v);
tUInt32 getNBO32 (tUInt32 v);
tUInt16 getNBO16 (tUInt16 v);

tUInt64 getLE64 (tUInt64 v);
tUInt32 getLE32 (tUInt32 v);
tUInt16 getLE16 (tUInt16 v);

tUInt64 getBE64 (tUInt64 v);
tUInt32 getBE32 (tUInt32 v);
tUInt16 getBE16 (tUInt16 v);


/*===========================================================================*\
\*===========================================================================*/

void setPtr (tUByte *m, void   *d);
void set64  (tUByte *m, tUInt64 d);
void set32  (tUByte *m, tUInt32 d);
void set16  (tUByte *m, tUInt16 d);
void set8   (tUByte *m, tUByte  d);

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/

void setNBO64 (tUByte *m, tUInt64 d);
void setNBO32 (tUByte *m, tUInt32 d);
void setNBO16 (tUByte *m, tUInt16 d);

void setLE64  (tUByte *m, tUInt64 d);
void setLE32  (tUByte *m, tUInt32 d);
void setLE16  (tUByte *m, tUInt16 d);

void setBE64  (tUByte *m, tUInt64 d);
void setBE32  (tUByte *m, tUInt32 d);
void setBE16  (tUByte *m, tUInt16 d);


/*===========================================================================*\
\*===========================================================================*/

inline void *getPtr (tUByte *m) {
    #ifdef C_PLATFORM_64
        return (void *)get64 (m);
    #else
        return (void *)get32 (m);
    #endif
}

inline tUInt64 get64 (tUByte *m) {
    tUInt64 value;
    s_memcpy (&value, m, sizeof (value));
    return value;
}

inline tUInt32 get32 (tUByte *m) {
    tUInt32 value;
    s_memcpy (&value, m, sizeof (value));
    return value;
}

inline tUInt16 get16 (tUByte *m) {
    tUInt16 value;
    s_memcpy (&value, m, sizeof (value));
    return value;
}

inline tUByte get8 (tUByte *m) {
    return *m;
}


/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/

inline tUInt64 getNBO64 (tUByte *m) {
    return getBE64 (m);
}

inline tUInt32 getNBO32 (tUByte *m) {
    return getBE32 (m);
}

inline tUInt16 getNBO16 (tUByte *m) {
    return getBE16 (m);
}


/*---------------------------------------------------------------------------*\
    Implementation for little endian computers
\*---------------------------------------------------------------------------*/

inline tUInt64 getLE64 (tUByte *m) {
    return (((tUInt64)getLE32 (m + sizeof (tUInt32))) << 32) | (tUInt32)getLE32 (m);
}

inline tUInt32 getLE32 (tUByte *m) {
    return (((tUInt32)getLE16 (m + sizeof (tUInt16))) << 16) | (tUInt32)getLE16 (m);
}

inline tUInt16 getLE16 (tUByte *m) {
    return (tUInt16)((((tUInt16)m[1]) << 8) | (tUInt16)m[0]);
}

inline tUInt64 getBE64 (tUByte *m) {
    return (((tUInt64)getBE32 (m)) << 32) | (tUInt32)getBE32 (m + sizeof (tUInt32));
}

inline tUInt32 getBE32 (tUByte *m) {
    return (((tUInt32)getBE16 (m)) << 16) | (tUInt32)getBE16 (m + sizeof (tUInt16));
}

inline tUInt16 getBE16 (tUByte *m) {
    return (tUInt16)((((tUInt16)m[0]) << 8) | (tUInt16)m[1]);
}


/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/

inline tUInt64 getNBO64 (tUInt64 v) {
    return getNBO64 ((tUByte *)&v);
}

inline tUInt32 getNBO32 (tUInt32 v) {
    return getNBO32 ((tUByte *)&v);
}

inline tUInt16 getNBO16 (tUInt16 v) {
    return getNBO16 ((tUByte *)&v);
}

inline tUInt64 getLE64 (tUInt64 v) {
    return getLE64 ((tUByte *)&v);
}

inline tUInt32 getLE32 (tUInt32 v) {
    return getLE32 ((tUByte *)&v);
}

inline tUInt16 getLE16 (tUInt16 v) {
    return getLE16 ((tUByte *)&v);
}

inline tUInt64 getBE64 (tUInt64 v) {
    return getBE64 ((tUByte *)&v);
}

inline tUInt32 getBE32 (tUInt32 v) {
    return getBE32 ((tUByte *)&v);
}

inline tUInt16 getBE16 (tUInt16 v) {
    return getBE16 ((tUByte *)&v);
}


/*===========================================================================*\
\*===========================================================================*/

inline void setPtr (tUByte *m, void *d)  {
    //assert (m != 0);
    #ifdef C_PLATFORM_64
        set64 (m, (tUInt64)d);
    #else
        set32 (m, (tUInt32)d);
    #endif
}

inline void set64 (tUByte *m, tUInt64 d)  {
    //assert (m != 0);
    s_memcpy (m, &d, sizeof (tUInt64));
}

inline void set32 (tUByte *m, tUInt32 d) {
    //assert (m != 0);
    s_memcpy (m, &d, sizeof (tUInt32));
}

inline void set16 (tUByte *m, tUInt16 d) {
    //assert (m != 0);
    s_memcpy (m, &d, sizeof (tUInt16));
}

inline void set8 (tUByte *m, tUByte d) {
    //assert (m != 0);
    *m = d;
}

/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/

inline void setNBO64 (tUByte *m, tUInt64 d) {
    setBE64 (m, d);
}

inline void setNBO32 (tUByte *m, tUInt32 d) {
    setBE32 (m, d);
}

inline void setNBO16 (tUByte *m, tUInt16 d) {
    setBE16 (m, d);
}


/*---------------------------------------------------------------------------*\
    Implementation for little endian computers
\*---------------------------------------------------------------------------*/

inline void setLE64  (tUByte *m, tUInt64 d) {
    setLE32 (m, (tUInt32)d);
    setLE32 (m + sizeof (tUInt32), (tUInt32)(d >> 32));
}

inline void setLE32  (tUByte *m, tUInt32 d) {
    setLE16 (m, (tUInt16)d);
    setLE16 (m + sizeof (tUInt16), (tUInt16)(d >> 16));
}

inline void setLE16  (tUByte *m, tUInt16 d) {
    m[0] = (tUByte)(d & 0xFF);
    m[1] = (tUByte)(d >> 8);
}

inline void setBE64  (tUByte *m, tUInt64 d) {
    setBE32 (m, (tUInt32)(d >> 16));
    setBE32 (m + sizeof (tUInt32), (tUInt32)d);
}

inline void setBE32  (tUByte *m, tUInt32 d) {
    setBE16 (m, (tUInt16)(d >> 16));
    setBE16 (m + sizeof (tUInt16), (tUInt16)d);
}

inline void setBE16  (tUByte *m, tUInt16 d) {
    m[0] = (tUByte)(d >> 8);
    m[1] = (tUByte)(d & 0xFF);
}


/*===========================================================================*\
\*===========================================================================*/

#endif