2007-12-12 22:09:01 +01:00
|
|
|
/* Copyright (c) 2003, Roger Dingledine
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2015-01-02 20:27:39 +01:00
|
|
|
* Copyright (c) 2007-2015, The Tor Project, Inc. */
|
2003-08-11 22:40:21 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
2004-05-10 09:54:13 +02:00
|
|
|
/**
|
|
|
|
* \file torint.h
|
|
|
|
* \brief Header file to define uint32_t and friends
|
|
|
|
**/
|
2004-05-01 22:46:28 +02:00
|
|
|
|
2012-10-12 18:13:10 +02:00
|
|
|
#ifndef TOR_TORINT_H
|
|
|
|
#define TOR_TORINT_H
|
2003-08-11 22:40:21 +02:00
|
|
|
|
2003-08-11 23:16:13 +02:00
|
|
|
#include "orconfig.h"
|
|
|
|
|
2003-08-11 22:40:21 +02:00
|
|
|
#ifdef HAVE_STDINT_H
|
|
|
|
#include <stdint.h>
|
2003-08-11 22:50:30 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
2003-08-11 23:16:13 +02:00
|
|
|
#endif
|
2004-08-25 21:16:18 +02:00
|
|
|
#ifdef HAVE_LIMITS_H
|
|
|
|
#include <limits.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_LIMITS_H
|
|
|
|
#include <sys/limits.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_MACHINE_LIMITS_H
|
2006-03-29 07:14:12 +02:00
|
|
|
#if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__)
|
2004-08-25 21:16:18 +02:00
|
|
|
/* FreeBSD has a bug where it complains that this file is obsolete,
|
|
|
|
and I should migrate to using sys/limits. It complains even when
|
2006-03-29 07:14:12 +02:00
|
|
|
I include both.
|
|
|
|
__FreeBSD_kernel__ is defined by Debian GNU/kFreeBSD which
|
|
|
|
does the same thing (but doesn't defined __FreeBSD__).
|
|
|
|
*/
|
2004-08-25 21:16:18 +02:00
|
|
|
#include <machine/limits.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
2005-02-22 05:26:45 +01:00
|
|
|
#ifdef HAVE_INTTYPES_H
|
|
|
|
#include <inttypes.h>
|
|
|
|
#endif
|
2003-08-11 23:16:13 +02:00
|
|
|
|
2003-08-12 01:21:51 +02:00
|
|
|
#if (SIZEOF_INT8_T != 0)
|
|
|
|
#define HAVE_INT8_T
|
|
|
|
#endif
|
|
|
|
#if (SIZEOF_INT16_T != 0)
|
|
|
|
#define HAVE_INT16_T
|
|
|
|
#endif
|
|
|
|
#if (SIZEOF_INT32_T != 0)
|
|
|
|
#define HAVE_INT32_T
|
|
|
|
#endif
|
|
|
|
#if (SIZEOF_INT64_T != 0)
|
|
|
|
#define HAVE_INT64_T
|
|
|
|
#endif
|
|
|
|
#if (SIZEOF_UINT8_T != 0)
|
|
|
|
#define HAVE_UINT8_T
|
|
|
|
#endif
|
|
|
|
#if (SIZEOF_UINT16_T != 0)
|
|
|
|
#define HAVE_UINT16_T
|
|
|
|
#endif
|
|
|
|
#if (SIZEOF_UINT32_T != 0)
|
|
|
|
#define HAVE_UINT32_T
|
|
|
|
#endif
|
|
|
|
#if (SIZEOF_UINT64_T != 0)
|
|
|
|
#define HAVE_UINT64_T
|
|
|
|
#endif
|
2004-05-05 22:26:35 +02:00
|
|
|
#if (SIZEOF_INTPTR_T != 0)
|
|
|
|
#define HAVE_INTPTR_T
|
|
|
|
#endif
|
|
|
|
#if (SIZEOF_UINTPTR_T != 0)
|
|
|
|
#define HAVE_UINTPTR_T
|
|
|
|
#endif
|
2003-08-12 01:21:51 +02:00
|
|
|
|
2003-08-11 22:40:21 +02:00
|
|
|
#if (SIZEOF_CHAR == 1)
|
2003-08-11 23:16:13 +02:00
|
|
|
#ifndef HAVE_INT8_T
|
2003-08-11 22:40:21 +02:00
|
|
|
typedef signed char int8_t;
|
2003-08-11 23:16:13 +02:00
|
|
|
#define HAVE_INT8_T
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_UINT8_T
|
|
|
|
typedef unsigned char uint8_t;
|
|
|
|
#define HAVE_UINT8_T
|
2003-08-11 22:40:21 +02:00
|
|
|
#endif
|
2003-08-11 22:50:30 +02:00
|
|
|
#endif
|
2003-08-11 22:40:21 +02:00
|
|
|
|
2003-12-17 22:14:13 +01:00
|
|
|
#if (SIZEOF_SHORT == 2)
|
2003-08-11 22:50:30 +02:00
|
|
|
#ifndef HAVE_INT16_T
|
2003-08-11 22:40:21 +02:00
|
|
|
typedef signed short int16_t;
|
2003-08-11 23:16:13 +02:00
|
|
|
#define HAVE_INT16_T
|
2003-08-11 22:40:21 +02:00
|
|
|
#endif
|
2003-08-11 23:16:13 +02:00
|
|
|
#ifndef HAVE_UINT16_T
|
|
|
|
typedef unsigned short uint16_t;
|
|
|
|
#define HAVE_UINT16_T
|
2003-08-11 22:50:30 +02:00
|
|
|
#endif
|
2003-08-11 23:16:13 +02:00
|
|
|
#endif
|
|
|
|
|
2003-12-17 22:14:13 +01:00
|
|
|
#if (SIZEOF_INT == 2)
|
2003-08-11 23:16:13 +02:00
|
|
|
#ifndef HAVE_INT16_T
|
|
|
|
typedef signed int int16_t;
|
|
|
|
#define HAVE_INT16_T
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_UINT16_T
|
|
|
|
typedef unsigned int uint16_t;
|
|
|
|
#define HAVE_UINT16_T
|
|
|
|
#endif
|
|
|
|
#elif (SIZEOF_INT == 4)
|
2003-08-11 22:50:30 +02:00
|
|
|
#ifndef HAVE_INT32_T
|
2003-08-11 22:40:21 +02:00
|
|
|
typedef signed int int32_t;
|
2003-08-11 23:16:13 +02:00
|
|
|
#define HAVE_INT32_T
|
2003-08-11 22:40:21 +02:00
|
|
|
#endif
|
2003-08-11 23:16:13 +02:00
|
|
|
#ifndef HAVE_UINT32_T
|
|
|
|
typedef unsigned int uint32_t;
|
|
|
|
#define HAVE_UINT32_T
|
2003-08-11 22:50:30 +02:00
|
|
|
#endif
|
2011-08-16 01:38:15 +02:00
|
|
|
#ifndef UINT16_MAX
|
|
|
|
#define UINT16_MAX 0xffffu
|
|
|
|
#endif
|
|
|
|
#ifndef INT16_MAX
|
|
|
|
#define INT16_MAX 0x7fff
|
|
|
|
#endif
|
|
|
|
#ifndef INT16_MIN
|
|
|
|
#define INT16_MIN (-INT16_MAX-1)
|
|
|
|
#endif
|
2004-11-05 18:54:50 +01:00
|
|
|
#ifndef UINT32_MAX
|
|
|
|
#define UINT32_MAX 0xffffffffu
|
|
|
|
#endif
|
2007-02-28 17:56:07 +01:00
|
|
|
#ifndef INT32_MAX
|
2011-01-12 20:29:38 +01:00
|
|
|
#define INT32_MAX 0x7fffffff
|
2007-02-28 17:56:07 +01:00
|
|
|
#endif
|
2009-09-15 04:15:57 +02:00
|
|
|
#ifndef INT32_MIN
|
|
|
|
#define INT32_MIN (-2147483647-1)
|
|
|
|
#endif
|
2003-08-11 23:16:13 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (SIZEOF_LONG == 4)
|
|
|
|
#ifndef HAVE_INT32_T
|
|
|
|
typedef signed long int32_t;
|
|
|
|
#define HAVE_INT32_T
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_UINT32_T
|
|
|
|
typedef unsigned long uint32_t;
|
|
|
|
#define HAVE_UINT32_T
|
2004-11-05 18:54:50 +01:00
|
|
|
#ifndef UINT32_MAX
|
|
|
|
#define UINT32_MAX 0xfffffffful
|
|
|
|
#endif
|
2003-08-11 23:16:13 +02:00
|
|
|
#endif
|
|
|
|
#elif (SIZEOF_LONG == 8)
|
2003-08-11 22:50:30 +02:00
|
|
|
#ifndef HAVE_INT64_T
|
2003-08-11 22:40:21 +02:00
|
|
|
typedef signed long int64_t;
|
2003-08-11 23:16:13 +02:00
|
|
|
#define HAVE_INT64_T
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_UINT32_T
|
|
|
|
typedef unsigned long uint64_t;
|
|
|
|
#define HAVE_UINT32_T
|
|
|
|
#endif
|
2004-11-05 18:54:50 +01:00
|
|
|
#ifndef UINT64_MAX
|
|
|
|
#define UINT64_MAX 0xfffffffffffffffful
|
|
|
|
#endif
|
2003-08-11 23:16:13 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (SIZEOF_LONG_LONG == 8)
|
|
|
|
#ifndef HAVE_INT64_T
|
2003-08-11 22:40:21 +02:00
|
|
|
typedef signed long long int64_t;
|
2003-08-11 23:16:13 +02:00
|
|
|
#define HAVE_INT64_T
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_UINT64_T
|
|
|
|
typedef unsigned long long uint64_t;
|
|
|
|
#define HAVE_UINT64_T
|
|
|
|
#endif
|
2004-11-05 18:54:50 +01:00
|
|
|
#ifndef UINT64_MAX
|
|
|
|
#define UINT64_MAX 0xffffffffffffffffull
|
|
|
|
#endif
|
2006-07-18 04:01:32 +02:00
|
|
|
#ifndef INT64_MAX
|
|
|
|
#define INT64_MAX 0x7fffffffffffffffll
|
|
|
|
#endif
|
2003-08-11 23:16:13 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (SIZEOF___INT64 == 8)
|
|
|
|
#ifndef HAVE_INT64_T
|
2003-08-11 22:40:21 +02:00
|
|
|
typedef signed __int64 int64_t;
|
2003-08-11 23:16:13 +02:00
|
|
|
#define HAVE_INT64_T
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_UINT64_T
|
|
|
|
typedef unsigned __int64 uint64_t;
|
|
|
|
#define HAVE_UINT64_T
|
2003-08-11 22:40:21 +02:00
|
|
|
#endif
|
2004-11-05 18:54:50 +01:00
|
|
|
#ifndef UINT64_MAX
|
|
|
|
#define UINT64_MAX 0xffffffffffffffffui64
|
|
|
|
#endif
|
2006-07-18 04:01:32 +02:00
|
|
|
#ifndef INT64_MAX
|
|
|
|
#define INT64_MAX 0x7fffffffffffffffi64
|
|
|
|
#endif
|
2003-08-11 22:50:30 +02:00
|
|
|
#endif
|
2003-08-11 22:40:21 +02:00
|
|
|
|
2014-12-19 20:12:22 +01:00
|
|
|
#ifndef INT64_MIN
|
|
|
|
#define INT64_MIN ((- INT64_MAX) - 1)
|
|
|
|
#endif
|
|
|
|
|
2012-05-16 20:31:36 +02:00
|
|
|
#ifndef SIZE_MAX
|
|
|
|
#if SIZEOF_SIZE_T == 8
|
|
|
|
#define SIZE_MAX UINT64_MAX
|
|
|
|
#elif SIZEOF_SIZE_T == 4
|
|
|
|
#define SIZE_MAX UINT32_MAX
|
|
|
|
#else
|
|
|
|
#error "Can't define SIZE_MAX"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2008-02-22 04:26:35 +01:00
|
|
|
#ifndef HAVE_SSIZE_T
|
|
|
|
#if SIZEOF_SIZE_T == 8
|
|
|
|
typedef int64_t ssize_t;
|
|
|
|
#elif SIZEOF_SIZE_T == 4
|
|
|
|
typedef int32_t ssize_t;
|
|
|
|
#else
|
|
|
|
#error "Can't define ssize_t."
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2004-05-05 22:26:35 +02:00
|
|
|
#if (SIZEOF_VOID_P > 4 && SIZEOF_VOID_P <= 8)
|
|
|
|
#ifndef HAVE_INTPTR_T
|
|
|
|
typedef int64_t intptr_t;
|
2012-12-18 19:10:16 +01:00
|
|
|
#define SIZEOF_INTPTR_T 8
|
2004-05-05 22:26:35 +02:00
|
|
|
#endif
|
|
|
|
#ifndef HAVE_UINTPTR_T
|
|
|
|
typedef uint64_t uintptr_t;
|
2012-12-18 19:10:16 +01:00
|
|
|
#define SIZEOF_UINTPTR_T 8
|
2004-05-05 22:26:35 +02:00
|
|
|
#endif
|
|
|
|
#elif (SIZEOF_VOID_P > 2 && SIZEOF_VOID_P <= 4)
|
|
|
|
#ifndef HAVE_INTPTR_T
|
|
|
|
typedef int32_t intptr_t;
|
2012-12-18 19:10:16 +01:00
|
|
|
#define SIZEOF_INTPTR_T 4
|
2004-05-05 22:26:35 +02:00
|
|
|
#endif
|
|
|
|
#ifndef HAVE_UINTPTR_T
|
|
|
|
typedef uint32_t uintptr_t;
|
2012-12-18 19:10:16 +01:00
|
|
|
#define SIZEOF_UINTPTR_T 4
|
2004-05-05 22:26:35 +02:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#error "void * is either >8 bytes or <= 2. In either case, I am confused."
|
|
|
|
#endif
|
2003-08-11 23:16:13 +02:00
|
|
|
|
|
|
|
#ifndef HAVE_INT8_T
|
|
|
|
#error "Missing type int8_t"
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_UINT8_T
|
|
|
|
#error "Missing type uint8_t"
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_INT16_T
|
|
|
|
#error "Missing type int16_t"
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_UINT16_T
|
|
|
|
#error "Missing type uint16_t"
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_INT32_T
|
|
|
|
#error "Missing type int32_t"
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_UINT32_T
|
|
|
|
#error "Missing type uint32_t"
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_INT64_T
|
|
|
|
#error "Missing type int64_t"
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_UINT64_T
|
|
|
|
#error "Missing type uint64_t"
|
|
|
|
#endif
|
2003-08-11 22:40:21 +02:00
|
|
|
|
2006-10-02 23:00:20 +02:00
|
|
|
/* This assumes a sane (2's-complement) representation. But if you
|
|
|
|
* aren't 2's complement, and you don't define LONG_MAX, then you're so
|
|
|
|
* bizarre that I want nothing to do with you. */
|
|
|
|
#ifndef USING_TWOS_COMPLEMENT
|
|
|
|
#error "Seems that your platform doesn't use 2's complement arithmetic. Argh."
|
|
|
|
#endif
|
2004-08-25 21:16:18 +02:00
|
|
|
#ifndef LONG_MAX
|
|
|
|
#if (SIZEOF_LONG == 4)
|
|
|
|
#define LONG_MAX 0x7fffffffL
|
|
|
|
#elif (SIZEOF_LONG == 8)
|
|
|
|
#define LONG_MAX 0x7fffffffffffffffL
|
|
|
|
#else
|
|
|
|
#error "Can't define LONG_MAX"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2005-07-25 20:10:08 +02:00
|
|
|
#ifndef INT_MAX
|
|
|
|
#if (SIZEOF_INT == 4)
|
|
|
|
#define INT_MAX 0x7fffffffL
|
|
|
|
#elif (SIZEOF_INT == 8)
|
|
|
|
#define INT_MAX 0x7fffffffffffffffL
|
|
|
|
#else
|
|
|
|
#error "Can't define INT_MAX"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2004-08-25 21:16:18 +02:00
|
|
|
#ifndef UINT_MAX
|
|
|
|
#if (SIZEOF_INT == 2)
|
|
|
|
#define UINT_MAX 0xffffu
|
|
|
|
#elif (SIZEOF_INT == 4)
|
|
|
|
#define UINT_MAX 0xffffffffu
|
|
|
|
#elif (SIZEOF_INT == 8)
|
|
|
|
#define UINT_MAX 0xffffffffffffffffu
|
|
|
|
#else
|
|
|
|
#error "Can't define UINT_MAX"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2008-02-21 19:45:11 +01:00
|
|
|
#ifndef SHORT_MAX
|
|
|
|
#if (SIZEOF_SHORT == 2)
|
|
|
|
#define SHORT_MAX 0x7fff
|
|
|
|
#elif (SIZEOF_SHORT == 4)
|
|
|
|
#define SHORT_MAX 0x7fffffff
|
|
|
|
#else
|
|
|
|
#error "Can't define SHORT_MAX"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2005-03-03 07:37:54 +01:00
|
|
|
#ifndef TIME_MAX
|
2005-07-25 20:10:08 +02:00
|
|
|
|
|
|
|
#if (SIZEOF_TIME_T == SIZEOF_INT)
|
|
|
|
#define TIME_MAX ((time_t)INT_MAX)
|
|
|
|
#elif (SIZEOF_TIME_T == SIZEOF_LONG)
|
|
|
|
#define TIME_MAX ((time_t)LONG_MAX)
|
2009-01-22 17:28:12 +01:00
|
|
|
#elif (SIZEOF_TIME_T == 8)
|
|
|
|
#define TIME_MAX ((time_t)INT64_MAX)
|
2005-07-25 20:10:08 +02:00
|
|
|
#else
|
2016-01-29 15:18:59 +01:00
|
|
|
#error "Can't define TIME_MAX"
|
2005-07-25 20:10:08 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* ifndef(TIME_MAX) */
|
2005-03-03 07:37:54 +01:00
|
|
|
|
2015-12-07 07:55:38 +01:00
|
|
|
#ifndef TIME_MIN
|
|
|
|
|
|
|
|
#if (SIZEOF_TIME_T == SIZEOF_INT)
|
|
|
|
#define TIME_MIN ((time_t)INT_MIN)
|
|
|
|
#elif (SIZEOF_TIME_T == SIZEOF_LONG)
|
|
|
|
#define TIME_MIN ((time_t)LONG_MIN)
|
|
|
|
#elif (SIZEOF_TIME_T == 8)
|
|
|
|
#define TIME_MIN ((time_t)INT64_MIN)
|
|
|
|
#else
|
2016-01-29 15:18:59 +01:00
|
|
|
#error "Can't define TIME_MIN"
|
2015-12-07 07:55:38 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* ifndef(TIME_MIN) */
|
|
|
|
|
2014-09-09 18:08:03 +02:00
|
|
|
#ifndef SIZE_MAX
|
2006-11-14 02:07:52 +01:00
|
|
|
#if (SIZEOF_SIZE_T == 4)
|
2014-09-09 18:08:03 +02:00
|
|
|
#define SIZE_MAX UINT32_MAX
|
2006-11-14 02:07:52 +01:00
|
|
|
#elif (SIZEOF_SIZE_T == 8)
|
2014-09-09 18:08:03 +02:00
|
|
|
#define SIZE_MAX UINT64_MAX
|
2006-11-14 02:07:52 +01:00
|
|
|
#else
|
2014-09-09 18:08:03 +02:00
|
|
|
#error "Can't define SIZE_MAX"
|
2006-11-14 02:07:52 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2014-09-09 18:08:03 +02:00
|
|
|
#ifndef SSIZE_MAX
|
2008-11-05 20:29:17 +01:00
|
|
|
#if (SIZEOF_SIZE_T == 4)
|
2014-09-09 18:08:03 +02:00
|
|
|
#define SSIZE_MAX INT32_MAX
|
2008-11-05 20:29:17 +01:00
|
|
|
#elif (SIZEOF_SIZE_T == 8)
|
2014-09-09 18:08:03 +02:00
|
|
|
#define SSIZE_MAX INT64_MAX
|
2008-11-05 20:29:17 +01:00
|
|
|
#else
|
2014-09-09 18:08:03 +02:00
|
|
|
#error "Can't define SSIZE_MAX"
|
2008-11-05 20:29:17 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2011-04-28 04:14:28 +02:00
|
|
|
/** Any ssize_t larger than this amount is likely to be an underflow. */
|
2014-09-09 18:08:03 +02:00
|
|
|
#define SSIZE_T_CEILING ((ssize_t)(SSIZE_MAX-16))
|
2011-03-16 22:05:37 +01:00
|
|
|
/** Any size_t larger than this amount is likely to be an underflow. */
|
2014-09-09 18:08:03 +02:00
|
|
|
#define SIZE_T_CEILING ((size_t)(SSIZE_MAX-16))
|
2004-12-02 05:33:01 +01:00
|
|
|
|
2003-08-11 22:40:21 +02:00
|
|
|
#endif /* __TORINT_H */
|
2005-06-09 21:03:31 +02:00
|
|
|
|