#ifndef NTP_TYPES_H
#define NTP_TYPES_H
#include <sys/types.h>
#if defined(HAVE_INTTYPES_H)
# include <inttypes.h>
#endif
#if defined(HAVE_STDINT_H)
# include <stdint.h>
#endif
#ifdef HAVE_LIMITS_H
# include <limits.h>
#endif
#include "ntp_machine.h"
#ifndef TRUE
# define TRUE 1
#endif
#ifndef FALSE
# define FALSE 0
#endif
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#else
typedef int bool;
#endif
#ifdef mac
#undef mac
#endif
#ifndef UNUSED_ARG
#define UNUSED_ARG(arg) ((void)(arg))
#endif
#ifndef UNUSED_LOCAL
#define UNUSED_LOCAL(arg) ((void)(arg))
#endif
#define COUNTOF(arr) (sizeof(arr) / sizeof((arr)[0]))
#if defined(VMS)
#include <socket.h>
typedef unsigned int u_int;
#endif
#ifdef HAVE_UINT32_T
# ifndef HAVE_INT32
typedef int32_t int32;
# endif
# ifndef HAVE_U_INT32
typedef uint32_t u_int32;
# if defined(UINT32_MAX) && !defined(U_INT32_MAX)
# define U_INT32_MAX UINT32_MAX
# endif
# endif
#elif (SIZEOF_INT == 4)
# if !defined(HAVE_INT32) && !defined(int32)
typedef int int32;
# ifndef INT32_MIN
# define INT32_MIN INT_MIN
# endif
# ifndef INT32_MAX
# define INT32_MAX INT_MAX
# endif
# endif
# if !defined(HAVE_U_INT32) && !defined(u_int32)
typedef unsigned u_int32;
# if defined(UINT_MAX) && !defined(U_INT32_MAX)
# define U_INT32_MAX UINT_MAX
# endif
# endif
#else
# if (SIZEOF_LONG == 4)
# if !defined(HAVE_INT32) && !defined(int32)
typedef long int32;
# ifndef INT32_MIN
# define INT32_MIN LONG_MIN
# endif
# ifndef INT32_MAX
# define INT32_MAX LONG_MAX
# endif
# endif
# if !defined(HAVE_U_INT32) && !defined(u_int32)
typedef unsigned long u_int32;
# if defined(ULONG_MAX) && !defined(U_INT32_MAX)
# define U_INT32_MAX ULONG_MAX
# endif
# endif
# else
# include "Bletch: what's 32 bits on this machine?"
# endif
#endif
#ifndef U_INT32_MAX
# define U_INT32_MAX 0xffffffff
#endif
#if !defined(HAVE_INT64)
# define HAVE_INT64
# define HAVE_U_INT64
# ifdef INT64_MAX
typedef int64_t int64;
typedef uint64_t u_int64;
# elif SIZEOF_LONG == 8
typedef long int64;
typedef unsigned long u_int64;
# elif SIZEOF_LONG_LONG == 8
typedef long long int64;
typedef unsigned long long u_int64;
# else
# undef HAVE_INT64
# undef HAVE_U_INT64
# endif
#endif
#if SIZEOF_SHORT != 2
# error short is not 2 bytes -- what is 16 bit integer on this target?
#endif
typedef union {
# ifdef WORDS_BIGENDIAN
struct {
int16_t hh; uint16_t hl; uint16_t lh; uint16_t ll;
} w_s;
struct {
uint16_t hh; uint16_t hl; uint16_t lh; uint16_t ll;
} W_s;
struct {
int32 hi; u_int32 lo;
} d_s;
struct {
u_int32 hi; u_int32 lo;
} D_s;
# else
struct {
uint16_t ll; uint16_t lh; uint16_t hl; int16_t hh;
} w_s;
struct {
uint16_t ll; uint16_t lh; uint16_t hl; uint16_t hh;
} W_s;
struct {
u_int32 lo; int32 hi;
} d_s;
struct {
u_int32 lo; u_int32 hi;
} D_s;
# endif
# ifdef HAVE_INT64
int64 q_s;
u_int64 Q_s;
# endif
} vint64;
typedef uint8_t ntp_u_int8_t;
typedef uint16_t ntp_u_int16_t;
typedef uint32_t ntp_u_int32_t;
typedef struct ntp_uint64_t { u_int32 val[2]; } ntp_uint64_t;
typedef uint16_t associd_t;
#define ASSOCID_MAX USHRT_MAX
typedef u_int32 keyid_t;
#define KEYID_T_MAX (0xffffffff)
typedef u_int32 tstamp_t;
typedef union max_alignment_tag {
double d;
} max_alignment;
#define MAXALIGN sizeof(max_alignment)
#define ALIGN_UNITS(sz) (((sz) + MAXALIGN - 1) / MAXALIGN)
#define ALIGNED_SIZE(sz) (MAXALIGN * ALIGN_UNITS(sz))
#define INC_ALIGNED_PTR(b, m) ((void *)aligned_ptr((void *)(b), m))
static inline
max_alignment *
aligned_ptr(
max_alignment * base,
size_t minsize
)
{
return base + ALIGN_UNITS((minsize < 1) ? 1 : minsize);
}
#define NONEMPTY_TRANSLATION_UNIT extern void exit(int);
#ifndef SYS_WINNT
#define sock_timeval timeval
#endif
#ifndef SYS_WINNT
# define tty_open(f, a, m) open(f, a, m)
# define closeserial(fd) close(fd)
# define closesocket(fd) close(fd)
typedef int SOCKET;
# define INVALID_SOCKET (-1)
# define SOCKET_ERROR (-1)
# define socket_errno() (errno)
#else
# define socket_errno() (errno = WSAGetLastError())
#endif
#endif