~ubuntu-branches/ubuntu/karmic/gnustep-base/karmic

« back to all changes in this revision

Viewing changes to Headers/Foundation/NSByteOrder.h

  • Committer: Bazaar Package Importer
  • Author(s): Eric Heintzmann
  • Date: 2005-04-17 00:14:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050417001438-enf0y07c9tku85z1
Tags: 1.10.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* NSByteOrder functions for GNUStep
 
2
   Copyright (C) 1998 Free Software Foundation, Inc.
 
3
 
 
4
   Written by:  Richard Frith-Macdonald <richard@brainstorm.co.uk>
 
5
   Date: 1998
 
6
 
 
7
   This file is part of the GNUstep Base Library.
 
8
 
 
9
   This library is free software; you can redistribute it and/or
 
10
   modify it under the terms of the GNU Library General Public
 
11
   License as published by the Free Software Foundation; either
 
12
   version 2 of the License, or (at your option) any later version.
 
13
 
 
14
   This library is distributed in the hope that it will be useful,
 
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
   Library General Public License for more details.
 
18
 
 
19
   You should have received a copy of the GNU Library General Public
 
20
   License along with this library; if not, write to the Free
 
21
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
 
22
   */
 
23
 
 
24
#ifndef __NSByteOrder_h_GNUSTEP_BASE_INCLUDE
 
25
#define __NSByteOrder_h_GNUSTEP_BASE_INCLUDE
 
26
 
 
27
#include <GSConfig.h>
 
28
 
 
29
/*
 
30
 *      OPENSTEP type definitions for Byte ordering.
 
31
 */
 
32
typedef gsu32   NSSwappedFloat;
 
33
typedef gsu64   NSSwappedDouble;
 
34
 
 
35
typedef enum {
 
36
  NS_UnknownByteOrder,
 
37
  NS_LittleEndian,
 
38
  NS_BigEndian
 
39
} NSByteOrder;
 
40
 
 
41
/*
 
42
 *      Function prototypes.
 
43
 */
 
44
 
 
45
#if (__GNUC__ == 2) && (__GNUC_MINOR__ <= 6) && !defined(__attribute__)
 
46
#  define __attribute__(x)
 
47
#endif
 
48
 
 
49
/*
 
50
 *      First the GNUstep functions for byte swapping
 
51
 */
 
52
static inline gsu16
 
53
GSSwapI16(gsu16 in) __attribute__((unused));
 
54
static inline gsu32
 
55
GSSwapI32(gsu32 in) __attribute__((unused));
 
56
static inline gsu64
 
57
GSSwapI64(gsu64 in) __attribute__((unused));
 
58
static inline gsu128
 
59
GSSwapI128(gsu128 in) __attribute__((unused));
 
60
 
 
61
static inline gsu16
 
62
GSSwapBigI16ToHost(gsu16 in) __attribute__((unused));
 
63
static inline gsu32
 
64
GSSwapBigI32ToHost(gsu32 in) __attribute__((unused));
 
65
static inline gsu64
 
66
GSSwapBigI64ToHost(gsu64 in) __attribute__((unused));
 
67
static inline gsu128
 
68
GSSwapBigI128ToHost(gsu128 in) __attribute__((unused));
 
69
 
 
70
static inline gsu16
 
71
GSSwapHostI16ToBig(gsu16 in) __attribute__((unused));
 
72
static inline gsu32
 
73
GSSwapHostI32ToBig(gsu32 in) __attribute__((unused));
 
74
static inline gsu64
 
75
GSSwapHostI64ToBig(gsu64 in) __attribute__((unused));
 
76
static inline gsu128
 
77
GSSwapHostI128ToBig(gsu128 in) __attribute__((unused));
 
78
 
 
79
static inline gsu16
 
80
GSSwapLittleI16ToHost(gsu16 in) __attribute__((unused));
 
81
static inline gsu32
 
82
GSSwapLittleI32ToHost(gsu32 in) __attribute__((unused));
 
83
static inline gsu64
 
84
GSSwapLittleI64ToHost(gsu64 in) __attribute__((unused));
 
85
static inline gsu128
 
86
GSSwapLittleI128ToHost(gsu128 in) __attribute__((unused));
 
87
 
 
88
static inline gsu16
 
89
GSSwapHostI16ToLittle(gsu16 in) __attribute__((unused));
 
90
static inline gsu32
 
91
GSSwapHostI32ToLittle(gsu32 in) __attribute__((unused));
 
92
static inline gsu64
 
93
GSSwapHostI64ToLittle(gsu64 in) __attribute__((unused));
 
94
static inline gsu128
 
95
GSSwapHostI128ToLittle(gsu128 in) __attribute__((unused));
 
96
 
 
97
#if (__GNUC__ == 3) && (__GNUC_MINOR__ == 1)
 
98
/* gcc 3.1 with option -O2 generates bad (i386?) code when compiling
 
99
   the following inline functions inside a .m file.  A call to a
 
100
   dumb function seems to work. */
 
101
extern void _gcc3_1_hack(void);
 
102
#endif
 
103
 
 
104
static inline gsu16
 
105
GSSwapI16(gsu16 in)
 
106
{
 
107
  union swap {
 
108
    gsu16       num;
 
109
    gsu8        byt[2];
 
110
  } dst;
 
111
  union swap    *src = (union swap*)&in;
 
112
#if (__GNUC__ == 3) && (__GNUC_MINOR__ == 1)
 
113
  _gcc3_1_hack();
 
114
#endif
 
115
  dst.byt[0] = src->byt[1];
 
116
  dst.byt[1] = src->byt[0];
 
117
  return dst.num;
 
118
}
 
119
 
 
120
static inline gsu32
 
121
GSSwapI32(gsu32 in)
 
122
{
 
123
  union swap {
 
124
    gsu32       num;
 
125
    gsu8        byt[4];
 
126
  } dst;
 
127
  union swap    *src = (union swap*)&in;
 
128
#if (__GNUC__ == 3) && (__GNUC_MINOR__ == 1)
 
129
  _gcc3_1_hack();
 
130
#endif
 
131
  dst.byt[0] = src->byt[3];
 
132
  dst.byt[1] = src->byt[2];
 
133
  dst.byt[2] = src->byt[1];
 
134
  dst.byt[3] = src->byt[0];
 
135
  return dst.num;
 
136
}
 
137
 
 
138
static inline gsu64
 
139
GSSwapI64(gsu64 in)
 
140
{
 
141
  union swap {
 
142
    gsu64       num;
 
143
    gsu8        byt[8];
 
144
  } dst;
 
145
  union swap    *src = (union swap*)&in;
 
146
#if (__GNUC__ == 3) && (__GNUC_MINOR__ == 1)
 
147
  _gcc3_1_hack();
 
148
#endif
 
149
  dst.byt[0] = src->byt[7];
 
150
  dst.byt[1] = src->byt[6];
 
151
  dst.byt[2] = src->byt[5];
 
152
  dst.byt[3] = src->byt[4];
 
153
  dst.byt[4] = src->byt[3];
 
154
  dst.byt[5] = src->byt[2];
 
155
  dst.byt[6] = src->byt[1];
 
156
  dst.byt[7] = src->byt[0];
 
157
  return dst.num;
 
158
}
 
159
 
 
160
static inline gsu128
 
161
GSSwapI128(gsu128 in)
 
162
{
 
163
  union swap {
 
164
    gsu128      num;
 
165
    gsu8        byt[16];
 
166
  } dst;
 
167
  union swap    *src = (union swap*)&in;
 
168
#if (__GNUC__ == 3) && (__GNUC_MINOR__ == 1)
 
169
  _gcc3_1_hack();
 
170
#endif
 
171
  dst.byt[0] = src->byt[15];
 
172
  dst.byt[1] = src->byt[14];
 
173
  dst.byt[2] = src->byt[13];
 
174
  dst.byt[3] = src->byt[12];
 
175
  dst.byt[4] = src->byt[11];
 
176
  dst.byt[5] = src->byt[10];
 
177
  dst.byt[6] = src->byt[9];
 
178
  dst.byt[7] = src->byt[8];
 
179
  dst.byt[8] = src->byt[7];
 
180
  dst.byt[9] = src->byt[6];
 
181
  dst.byt[10] = src->byt[5];
 
182
  dst.byt[11] = src->byt[4];
 
183
  dst.byt[12] = src->byt[3];
 
184
  dst.byt[13] = src->byt[2];
 
185
  dst.byt[14] = src->byt[1];
 
186
  dst.byt[15] = src->byt[0];
 
187
  return dst.num;
 
188
}
 
189
 
 
190
/*
 
191
 *      Now the OpenStep functions
 
192
 */
 
193
static inline NSSwappedDouble
 
194
NSConvertHostDoubleToSwapped(double num) __attribute__((unused));
 
195
static inline NSSwappedFloat
 
196
NSConvertHostFloatToSwapped(float num) __attribute__((unused));
 
197
static inline double
 
198
NSConvertSwappedDoubleToHost(NSSwappedDouble num) __attribute__((unused));
 
199
static inline float
 
200
NSConvertSwappedFloatToHost(NSSwappedFloat num) __attribute__((unused));
 
201
static inline unsigned int
 
202
NSSwapInt(unsigned int in) __attribute__((unused));
 
203
static inline unsigned long long
 
204
NSSwapLongLong(unsigned long long in) __attribute__((unused));
 
205
static inline unsigned long
 
206
NSSwapLong(unsigned long in) __attribute__((unused));
 
207
static inline unsigned short
 
208
NSSwapShort(unsigned short in) __attribute__((unused));
 
209
static inline NSSwappedDouble
 
210
NSSwapDouble(NSSwappedDouble num) __attribute__((unused));
 
211
static inline NSSwappedFloat
 
212
NSSwapFloat(NSSwappedFloat num) __attribute__((unused));
 
213
static inline NSByteOrder
 
214
NSHostByteOrder(void) __attribute__((unused));
 
215
static inline double
 
216
NSSwapBigDoubleToHost(NSSwappedDouble num) __attribute__((unused));
 
217
static inline float
 
218
NSSwapBigFloatToHost(NSSwappedFloat num) __attribute__((unused));
 
219
static inline unsigned int
 
220
NSSwapBigIntToHost(unsigned int num) __attribute__((unused));
 
221
static inline unsigned long long
 
222
NSSwapBigLongLongToHost(unsigned long long num) __attribute__((unused));
 
223
static inline unsigned long
 
224
NSSwapBigLongToHost(unsigned long num) __attribute__((unused));
 
225
static inline unsigned short
 
226
NSSwapBigShortToHost(unsigned short num) __attribute__((unused));
 
227
static inline NSSwappedDouble
 
228
NSSwapHostDoubleToBig(double num) __attribute__((unused));
 
229
static inline NSSwappedFloat
 
230
NSSwapHostFloatToBig(float num) __attribute__((unused));
 
231
static inline unsigned int
 
232
NSSwapHostIntToBig(unsigned int num) __attribute__((unused));
 
233
static inline unsigned long long
 
234
NSSwapHostLongLongToBig(unsigned long long num) __attribute__((unused));
 
235
static inline unsigned long
 
236
NSSwapHostLongToBig(unsigned long num) __attribute__((unused));
 
237
static inline unsigned short
 
238
NSSwapHostShortToBig(unsigned short num) __attribute__((unused));
 
239
static inline double
 
240
NSSwapLittleDoubleToHost(NSSwappedDouble num) __attribute__((unused));
 
241
static inline float
 
242
NSSwapLittleFloatToHost(NSSwappedFloat num) __attribute__((unused));
 
243
static inline unsigned int
 
244
NSSwapLittleIntToHost(unsigned int num) __attribute__((unused));
 
245
static inline unsigned long long
 
246
NSSwapLittleLongLongToHost(unsigned long long num) __attribute__((unused));
 
247
static inline unsigned long
 
248
NSSwapLittleLongToHost(unsigned long num) __attribute__((unused));
 
249
static inline unsigned short
 
250
NSSwapLittleShortToHost(unsigned short num) __attribute__((unused));
 
251
static inline NSSwappedDouble
 
252
NSSwapHostDoubleToLittle(double num) __attribute__((unused));
 
253
static inline NSSwappedFloat
 
254
NSSwapHostFloatToLittle(float num) __attribute__((unused));
 
255
static inline unsigned int
 
256
NSSwapHostIntToLittle(unsigned int num) __attribute__((unused));
 
257
static inline unsigned long long
 
258
NSSwapHostLongLongToLittle(unsigned long long num) __attribute__((unused));
 
259
static inline unsigned long
 
260
NSSwapHostLongToLittle(unsigned long num) __attribute__((unused));
 
261
static inline unsigned short
 
262
NSSwapHostShortToLittle(unsigned short num) __attribute__((unused));
 
263
 
 
264
/*
 
265
 *      Basic byte swapping routines and type conversions
 
266
 */
 
267
static inline NSSwappedDouble
 
268
NSConvertHostDoubleToSwapped(double num)
 
269
{
 
270
  union dconv {
 
271
    double              number;
 
272
    NSSwappedDouble     sd;
 
273
  };
 
274
  return ((union dconv *)&num)->sd;
 
275
}
 
276
 
 
277
static inline NSSwappedFloat
 
278
NSConvertHostFloatToSwapped(float num)
 
279
{
 
280
  union fconv {
 
281
    float               number;
 
282
    NSSwappedFloat      sf;
 
283
  };
 
284
  return ((union fconv *)&num)->sf;
 
285
}
 
286
 
 
287
static inline double
 
288
NSConvertSwappedDoubleToHost(NSSwappedDouble num)
 
289
{
 
290
  union dconv {
 
291
    double              number;
 
292
    NSSwappedDouble     sd;
 
293
  };
 
294
  return ((union dconv *)&num)->number;
 
295
}
 
296
 
 
297
static inline float
 
298
NSConvertSwappedFloatToHost(NSSwappedFloat num)
 
299
{
 
300
  union fconv {
 
301
    float               number;
 
302
    NSSwappedFloat      sf;
 
303
  };
 
304
  return ((union fconv *)&num)->number;
 
305
}
 
306
 
 
307
static inline unsigned int
 
308
NSSwapInt(unsigned int in)
 
309
{
 
310
#if     GS_SIZEOF_INT == 2
 
311
  return GSSwapI16(in);
 
312
#else
 
313
#if     GS_SIZEOF_INT == 4
 
314
  return GSSwapI32(in);
 
315
#else
 
316
#if     GS_SIZEOF_INT == 8
 
317
  return GSSwapI64(in);
 
318
#else
 
319
  return GSSwapI128(in);
 
320
#endif
 
321
#endif
 
322
#endif
 
323
}
 
324
 
 
325
static inline unsigned long long
 
326
NSSwapLongLong(unsigned long long in)
 
327
{
 
328
#if     GS_SIZEOF_LONG_LONG == 2
 
329
  return GSSwapI16(in);
 
330
#else
 
331
#if     GS_SIZEOF_LONG_LONG == 4
 
332
  return GSSwapI32(in);
 
333
#else
 
334
#if     GS_SIZEOF_LONG_LONG == 8
 
335
  return GSSwapI64(in);
 
336
#else
 
337
  return GSSwapI128(in);
 
338
#endif
 
339
#endif
 
340
#endif
 
341
}
 
342
 
 
343
static inline unsigned long
 
344
NSSwapLong(unsigned long in)
 
345
{
 
346
#if     GS_SIZEOF_LONG == 2
 
347
  return GSSwapI16(in);
 
348
#else
 
349
#if     GS_SIZEOF_LONG == 4
 
350
  return GSSwapI32(in);
 
351
#else
 
352
#if     GS_SIZEOF_LONG == 8
 
353
  return GSSwapI64(in);
 
354
#else
 
355
  return GSSwapI128(in);
 
356
#endif
 
357
#endif
 
358
#endif
 
359
}
 
360
 
 
361
static inline unsigned short
 
362
NSSwapShort(unsigned short in)
 
363
{
 
364
#if     GS_SIZEOF_SHORT == 2
 
365
  return GSSwapI16(in);
 
366
#else
 
367
#if     GS_SIZEOF_SHORT == 4
 
368
  return GSSwapI32(in);
 
369
#else
 
370
#if     GS_SIZEOF_SHORT == 8
 
371
  return GSSwapI64(in);
 
372
#else
 
373
  return GSSwapI128(in);
 
374
#endif
 
375
#endif
 
376
#endif
 
377
}
 
378
 
 
379
static inline NSSwappedDouble
 
380
NSSwapDouble(NSSwappedDouble num)
 
381
{
 
382
  return GSSwapI64(num);
 
383
}
 
384
 
 
385
static inline NSSwappedFloat
 
386
NSSwapFloat(NSSwappedFloat num)
 
387
{
 
388
  return GSSwapI32(num);
 
389
}
 
390
 
 
391
#if     GS_WORDS_BIGENDIAN
 
392
 
 
393
static inline NSByteOrder
 
394
NSHostByteOrder(void)
 
395
{
 
396
  return NS_BigEndian;
 
397
}
 
398
 
 
399
/*
 
400
 *      Swap Big endian to host
 
401
 */
 
402
static inline gsu16
 
403
GSSwapBigI16ToHost(gsu16 in)
 
404
{
 
405
  return in;
 
406
}
 
407
static inline gsu32
 
408
GSSwapBigI32ToHost(gsu32 in)
 
409
{
 
410
  return in;
 
411
}
 
412
static inline gsu64
 
413
GSSwapBigI64ToHost(gsu64 in)
 
414
{
 
415
  return in;
 
416
}
 
417
static inline gsu128
 
418
GSSwapBigI128ToHost(gsu128 in)
 
419
{
 
420
  return in;
 
421
}
 
422
 
 
423
static inline double
 
424
NSSwapBigDoubleToHost(NSSwappedDouble num)
 
425
{
 
426
  return NSConvertSwappedDoubleToHost(num);
 
427
}
 
428
 
 
429
static inline float
 
430
NSSwapBigFloatToHost(NSSwappedFloat num)
 
431
{
 
432
  return NSConvertSwappedFloatToHost(num);
 
433
}
 
434
 
 
435
static inline unsigned int
 
436
NSSwapBigIntToHost(unsigned int num)
 
437
{
 
438
  return num;
 
439
}
 
440
 
 
441
static inline unsigned long long
 
442
NSSwapBigLongLongToHost(unsigned long long num)
 
443
{
 
444
  return num;
 
445
}
 
446
 
 
447
static inline unsigned long
 
448
NSSwapBigLongToHost(unsigned long num)
 
449
{
 
450
  return num;
 
451
}
 
452
 
 
453
static inline unsigned short
 
454
NSSwapBigShortToHost(unsigned short num)
 
455
{
 
456
  return num;
 
457
}
 
458
 
 
459
/*
 
460
 *      Swap Host to Big endian
 
461
 */
 
462
static inline gsu16
 
463
GSSwapHostI16ToBig(gsu16 in)
 
464
{
 
465
  return in;
 
466
}
 
467
static inline gsu32
 
468
GSSwapHostI32ToBig(gsu32 in)
 
469
{
 
470
  return in;
 
471
}
 
472
static inline gsu64
 
473
GSSwapHostI64ToBig(gsu64 in)
 
474
{
 
475
  return in;
 
476
}
 
477
static inline gsu128
 
478
GSSwapHostI128ToBig(gsu128 in)
 
479
{
 
480
  return in;
 
481
}
 
482
 
 
483
static inline NSSwappedDouble
 
484
NSSwapHostDoubleToBig(double num)
 
485
{
 
486
  return NSConvertHostDoubleToSwapped(num);
 
487
}
 
488
 
 
489
static inline NSSwappedFloat
 
490
NSSwapHostFloatToBig(float num)
 
491
{
 
492
  return NSConvertHostFloatToSwapped(num);
 
493
}
 
494
 
 
495
static inline unsigned int
 
496
NSSwapHostIntToBig(unsigned int num)
 
497
{
 
498
  return num;
 
499
}
 
500
 
 
501
static inline unsigned long long
 
502
NSSwapHostLongLongToBig(unsigned long long num)
 
503
{
 
504
  return num;
 
505
}
 
506
 
 
507
static inline unsigned long
 
508
NSSwapHostLongToBig(unsigned long num)
 
509
{
 
510
  return num;
 
511
}
 
512
 
 
513
static inline unsigned short
 
514
NSSwapHostShortToBig(unsigned short num)
 
515
{
 
516
  return num;
 
517
}
 
518
 
 
519
/*
 
520
 *      Swap Little endian to Host
 
521
 */
 
522
static inline gsu16
 
523
GSSwapLittleI16ToHost(gsu16 in)
 
524
{
 
525
  return GSSwapI16(in);
 
526
}
 
527
static inline gsu32
 
528
GSSwapLittleI32ToHost(gsu32 in)
 
529
{
 
530
  return GSSwapI32(in);
 
531
}
 
532
static inline gsu64
 
533
GSSwapLittleI64ToHost(gsu64 in)
 
534
{
 
535
  return GSSwapI64(in);
 
536
}
 
537
static inline gsu128
 
538
GSSwapLittleI128ToHost(gsu128 in)
 
539
{
 
540
  return GSSwapI128(in);
 
541
}
 
542
 
 
543
static inline double
 
544
NSSwapLittleDoubleToHost(NSSwappedDouble num)
 
545
{
 
546
  return NSConvertSwappedDoubleToHost(NSSwapDouble(num));
 
547
}
 
548
 
 
549
static inline float
 
550
NSSwapLittleFloatToHost(NSSwappedFloat num)
 
551
{
 
552
  return NSConvertSwappedFloatToHost(NSSwapFloat(num));
 
553
}
 
554
 
 
555
static inline unsigned int
 
556
NSSwapLittleIntToHost(unsigned int num)
 
557
{
 
558
  return NSSwapInt(num);
 
559
}
 
560
 
 
561
static inline unsigned long long
 
562
NSSwapLittleLongLongToHost(unsigned long long num)
 
563
{
 
564
  return NSSwapLongLong(num);
 
565
}
 
566
 
 
567
static inline unsigned long
 
568
NSSwapLittleLongToHost(unsigned long num)
 
569
{
 
570
  return NSSwapLong(num);
 
571
}
 
572
 
 
573
static inline unsigned short
 
574
NSSwapLittleShortToHost(unsigned short num)
 
575
{
 
576
  return NSSwapShort(num);
 
577
}
 
578
 
 
579
/*
 
580
 *      Swap Host to Little endian
 
581
 */
 
582
static inline gsu16
 
583
GSSwapHostI16ToLittle(gsu16 in)
 
584
{
 
585
  return GSSwapI16(in);
 
586
}
 
587
static inline gsu32
 
588
GSSwapHostI32ToLittle(gsu32 in)
 
589
{
 
590
  return GSSwapI32(in);
 
591
}
 
592
static inline gsu64
 
593
GSSwapHostI64ToLittle(gsu64 in)
 
594
{
 
595
  return GSSwapI64(in);
 
596
}
 
597
static inline gsu128
 
598
GSSwapHostI128ToLittle(gsu128 in)
 
599
{
 
600
  return GSSwapI128(in);
 
601
}
 
602
 
 
603
static inline NSSwappedDouble
 
604
NSSwapHostDoubleToLittle(double num)
 
605
{
 
606
  return NSSwapDouble(NSConvertHostDoubleToSwapped(num));
 
607
}
 
608
 
 
609
static inline NSSwappedFloat
 
610
NSSwapHostFloatToLittle(float num)
 
611
{
 
612
  return NSSwapFloat(NSConvertHostFloatToSwapped(num));
 
613
}
 
614
 
 
615
static inline unsigned int
 
616
NSSwapHostIntToLittle(unsigned int num)
 
617
{
 
618
  return NSSwapInt(num);
 
619
}
 
620
 
 
621
static inline unsigned long long
 
622
NSSwapHostLongLongToLittle(unsigned long long num)
 
623
{
 
624
  return NSSwapLongLong(num);
 
625
}
 
626
 
 
627
static inline unsigned long
 
628
NSSwapHostLongToLittle(unsigned long num)
 
629
{
 
630
  return NSSwapLong(num);
 
631
}
 
632
 
 
633
static inline unsigned short
 
634
NSSwapHostShortToLittle(unsigned short num)
 
635
{
 
636
  return NSSwapShort(num);
 
637
}
 
638
 
 
639
 
 
640
#else
 
641
 
 
642
static inline NSByteOrder
 
643
NSHostByteOrder(void)
 
644
{
 
645
  return NS_LittleEndian;
 
646
}
 
647
 
 
648
 
 
649
/*
 
650
 *      Swap Big endian to host
 
651
 */
 
652
static inline gsu16
 
653
GSSwapBigI16ToHost(gsu16 in)
 
654
{
 
655
  return GSSwapI16(in);
 
656
}
 
657
static inline gsu32
 
658
GSSwapBigI32ToHost(gsu32 in)
 
659
{
 
660
  return GSSwapI32(in);
 
661
}
 
662
static inline gsu64
 
663
GSSwapBigI64ToHost(gsu64 in)
 
664
{
 
665
  return GSSwapI64(in);
 
666
}
 
667
static inline gsu128
 
668
GSSwapBigI128ToHost(gsu128 in)
 
669
{
 
670
  return GSSwapI128(in);
 
671
}
 
672
static inline double
 
673
NSSwapBigDoubleToHost(NSSwappedDouble num)
 
674
{
 
675
  return NSConvertSwappedDoubleToHost(NSSwapDouble(num));
 
676
}
 
677
 
 
678
static inline float
 
679
NSSwapBigFloatToHost(NSSwappedFloat num)
 
680
{
 
681
  return NSConvertSwappedFloatToHost(NSSwapFloat(num));
 
682
}
 
683
 
 
684
static inline unsigned int
 
685
NSSwapBigIntToHost(unsigned int num)
 
686
{
 
687
  return NSSwapInt(num);
 
688
}
 
689
 
 
690
static inline unsigned long long
 
691
NSSwapBigLongLongToHost(unsigned long long num)
 
692
{
 
693
  return NSSwapLongLong(num);
 
694
}
 
695
 
 
696
static inline unsigned long
 
697
NSSwapBigLongToHost(unsigned long num)
 
698
{
 
699
  return NSSwapLong(num);
 
700
}
 
701
 
 
702
static inline unsigned short
 
703
NSSwapBigShortToHost(unsigned short num)
 
704
{
 
705
  return NSSwapShort(num);
 
706
}
 
707
 
 
708
/*
 
709
 *      Swap Host to Big endian
 
710
 */
 
711
static inline gsu16
 
712
GSSwapHostI16ToBig(gsu16 in)
 
713
{
 
714
  return GSSwapI16(in);
 
715
}
 
716
static inline gsu32
 
717
GSSwapHostI32ToBig(gsu32 in)
 
718
{
 
719
  return GSSwapI32(in);
 
720
}
 
721
static inline gsu64
 
722
GSSwapHostI64ToBig(gsu64 in)
 
723
{
 
724
  return GSSwapI64(in);
 
725
}
 
726
static inline gsu128
 
727
GSSwapHostI128ToBig(gsu128 in)
 
728
{
 
729
  return GSSwapI128(in);
 
730
}
 
731
static inline NSSwappedDouble
 
732
NSSwapHostDoubleToBig(double num)
 
733
{
 
734
  return NSSwapDouble(NSConvertHostDoubleToSwapped(num));
 
735
}
 
736
 
 
737
static inline NSSwappedFloat
 
738
NSSwapHostFloatToBig(float num)
 
739
{
 
740
  return NSSwapFloat(NSConvertHostFloatToSwapped(num));
 
741
}
 
742
 
 
743
static inline unsigned int
 
744
NSSwapHostIntToBig(unsigned int num)
 
745
{
 
746
  return NSSwapInt(num);
 
747
}
 
748
 
 
749
static inline unsigned long long
 
750
NSSwapHostLongLongToBig(unsigned long long num)
 
751
{
 
752
  return NSSwapLongLong(num);
 
753
}
 
754
 
 
755
static inline unsigned long
 
756
NSSwapHostLongToBig(unsigned long num)
 
757
{
 
758
  return NSSwapLong(num);
 
759
}
 
760
 
 
761
static inline unsigned short
 
762
NSSwapHostShortToBig(unsigned short num)
 
763
{
 
764
  return NSSwapShort(num);
 
765
}
 
766
 
 
767
/*
 
768
 *      Swap Little endian to Host
 
769
 */
 
770
static inline gsu16
 
771
GSSwapLittleI16ToHost(gsu16 in)
 
772
{
 
773
  return in;
 
774
}
 
775
static inline gsu32
 
776
GSSwapLittleI32ToHost(gsu32 in)
 
777
{
 
778
  return in;
 
779
}
 
780
static inline gsu64
 
781
GSSwapLittleI64ToHost(gsu64 in)
 
782
{
 
783
  return in;
 
784
}
 
785
static inline gsu128
 
786
GSSwapLittleI128ToHost(gsu128 in)
 
787
{
 
788
  return in;
 
789
}
 
790
 
 
791
static inline double
 
792
NSSwapLittleDoubleToHost(NSSwappedDouble num)
 
793
{
 
794
  return NSConvertSwappedDoubleToHost(num);
 
795
}
 
796
 
 
797
static inline float
 
798
NSSwapLittleFloatToHost(NSSwappedFloat num)
 
799
{
 
800
  return NSConvertSwappedFloatToHost(num);
 
801
}
 
802
 
 
803
static inline unsigned int
 
804
NSSwapLittleIntToHost(unsigned int num)
 
805
{
 
806
  return num;
 
807
}
 
808
 
 
809
static inline unsigned long long
 
810
NSSwapLittleLongLongToHost(unsigned long long num)
 
811
{
 
812
  return num;
 
813
}
 
814
 
 
815
static inline unsigned long
 
816
NSSwapLittleLongToHost(unsigned long num)
 
817
{
 
818
  return num;
 
819
}
 
820
 
 
821
static inline unsigned short
 
822
NSSwapLittleShortToHost(unsigned short num)
 
823
{
 
824
  return num;
 
825
}
 
826
 
 
827
/*
 
828
 *      Swap Host to Little endian
 
829
 */
 
830
static inline gsu16
 
831
GSSwapHostI16ToLittle(gsu16 in)
 
832
{
 
833
  return in;
 
834
}
 
835
static inline gsu32
 
836
GSSwapHostI32ToLittle(gsu32 in)
 
837
{
 
838
  return in;
 
839
}
 
840
static inline gsu64
 
841
GSSwapHostI64ToLittle(gsu64 in)
 
842
{
 
843
  return in;
 
844
}
 
845
static inline gsu128
 
846
GSSwapHostI128ToLittle(gsu128 in)
 
847
{
 
848
  return in;
 
849
}
 
850
 
 
851
static inline NSSwappedDouble
 
852
NSSwapHostDoubleToLittle(double num)
 
853
{
 
854
  return NSConvertHostDoubleToSwapped(num);
 
855
}
 
856
 
 
857
static inline NSSwappedFloat
 
858
NSSwapHostFloatToLittle(float num)
 
859
{
 
860
  return NSConvertHostFloatToSwapped(num);
 
861
}
 
862
 
 
863
static inline unsigned int
 
864
NSSwapHostIntToLittle(unsigned int num)
 
865
{
 
866
  return num;
 
867
}
 
868
 
 
869
static inline unsigned long long
 
870
NSSwapHostLongLongToLittle(unsigned long long num)
 
871
{
 
872
  return num;
 
873
}
 
874
 
 
875
static inline unsigned long
 
876
NSSwapHostLongToLittle(unsigned long num)
 
877
{
 
878
  return num;
 
879
}
 
880
 
 
881
static inline unsigned short
 
882
NSSwapHostShortToLittle(unsigned short num)
 
883
{
 
884
  return num;
 
885
}
 
886
 
 
887
#endif
 
888
 
 
889
 
 
890
#endif /* __NSByteOrder_h_GNUSTEP_BASE_INCLUDE */