Blame view

integers.h 2.16 KB
chris committed
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
/*
 * integers.h:
 * This header file ensures that we have u_int<n>_t types of the proper width,
 * using a rather convoluted set of conditionals generated by configure. This
 * is an almighty pain in the arse, and is completely irrelevant on most
 * systems which already define this stuff.
 *
 * $Id$
 *
 */

#ifndef __INTEGERS_H_ /* include guard */
#define __INTEGERS_H_

#include <sys/types.h>
#include "config.h"

#if SIZEOF_U_INT8_T != 1 || SIZEOF_U_INT16_T != 2 || SIZEOF_U_INT32_T != 4

#   if defined(HAVE_C99_INTS)
        
        /* 
         * Use the C99 standard-width integers, defined in some appropriate
         * header file.
         */

#       if defined(HAVE_STDINT_H)
#           include <stdint.h>
#       elif defined(HAVE_SYS_INTTYPES_H)
#           include <sys/inttypes.h>
#       endif

        /* Don't replace existing u_int<n>_t types. */
#       if SIZEOF_U_INT8_T != 1
            typedef uint8_t u_int8_t;
#       endif

#       if SIZEOF_U_INT16_T != 2
            typedef uint16_t u_int16_t;
#       endif

#       if SIZEOF_U_INT32_T != 4
            typedef uint32_t u_int32_t;
#       endif

#   elif (SIZEOF_UNSIGNED_SHORT_INT == 2 || SIZEOF_UNSIGNED_INT == 2)    \
          && (SIZEOF_UNSIGNED_INT == 4 || SIZEOF_UNSIGNED_LONG_INT == 4)
    
        /*
         * Use an appropriately-sized basic type.
         */
    
#       if SIZEOF_U_INT8_T != 1
            typedef unsigned char u_int8_t;         /* By definition. */
#       endif

#       if SIZEOF_U_INT16_T != 2
#           if SIZEOF_UNSIGNED_SHORT_INT == 2
                typedef unsigned short int u_int16_t;
#           elif SIZEOF_UNSIGNED_INT == 2
                typedef unsigned int u_int16_t;     /* Not likely. */
#           endif
#       endif

#       if SIZEOF_U_INT32_T != 4
#           if SIZEOF_UNSIGNED_INT == 4
                typedef unsigned int u_int32_t;
#           elif SIZEOF_UNSIGNED_LONG_INT == 4
                typedef unsigned long int u_int32_t;
#           endif
#       endif

        /* Whew. */

#   else
#       error "Your C compiler seems to lack 16 and 32 bit unsigned integer types"
#   endif

#endif /* No existing u_int<n>_t types. */

#endif /* __INTEGERS_H_ */