]> git.sur5r.net Git - openldap/blob - include/ac/bytes.h
Add support for sizeof(short) == 4 when sizeof(int) > 4.
[openldap] / include / ac / bytes.h
1 /* Generic bytes.h */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms are permitted only
8  * as authorized by the OpenLDAP Public License.  A copy of this
9  * license is available at http://www.OpenLDAP.org/license.html or
10  * in file LICENSE in the top-level directory of the distribution.
11  */
12
13 #ifndef _AC_BYTES_H
14 #define _AC_BYTES_H
15
16 /* cross compilers should define both AC_INT{2,4}_TYPE in CPPFLAGS */
17
18 #if !defined( AC_INT4_TYPE ) || !defined( AC_INT2_TYPE )
19         /* use autoconf defines to provide sized typedefs */
20 #       if SIZEOF_LONG == 4
21 #               define AC_INT4_TYPE long
22 #       elif SIZEOF_INT == 4
23 #               define AC_INT4_TYPE int
24 #       elif SIZEOF_SHORT == 4
25 #               define AC_INT4_TYPE short
26 #       else
27 #               error "AC_INT4_TYPE?"
28 #       endif
29
30 #       if SIZEOF_SHORT == 2
31 #               define AC_INT2_TYPE short
32 #       elif SIZEOF_INT == 2
33 #               define AC_INT2_TYPE int
34 #       elif SIZEOF_LONG == 2
35 #               define AC_INT2_TYPE long
36 #       else
37 #               error "AC_INT2_TYPE?"
38 #       endif
39 #endif
40     
41 typedef AC_INT4_TYPE ac_int4;
42 typedef signed AC_INT4_TYPE ac_sint4;
43 typedef unsigned AC_INT4_TYPE ac_uint4;
44
45 typedef AC_INT2_TYPE ac_int2;
46 typedef signed AC_INT2_TYPE ac_sint2;
47 typedef unsigned AC_INT2_TYPE ac_uint2;
48
49 #ifndef BYTE_ORDER
50 /* cross compilers should define BYTE_ORDER in CPPFLAGS */
51
52 /*
53  * Definitions for byte order, according to byte significance from low
54  * address to high.
55  */
56 #define LITTLE_ENDIAN   1234    /* LSB first: i386, vax */
57 #define BIG_ENDIAN  4321        /* MSB first: 68000, ibm, net */
58 #define PDP_ENDIAN  3412        /* LSB first in word, MSW first in long */
59
60 /* assume autoconf's AC_C_BIGENDIAN has been ran */
61 /* if it hasn't, we assume (maybe falsely) the order is LITTLE ENDIAN */
62 #       ifdef WORDS_BIGENDIAN
63 #               define BYTE_ORDER  BIG_ENDIAN
64 #       else
65 #               define BYTE_ORDER  LITTLE_ENDIAN
66 #       endif
67
68 #endif /* BYTE_ORDER */
69
70 #endif /* _AC_BYTES_H */