From d361fc7ec72fe7a962d20ce70e26572298290211 Mon Sep 17 00:00:00 2001 From: llsth Date: Tue, 17 Mar 2015 10:02:28 +0100 Subject: [PATCH] Refactored compiler and platform logic --- agetaddrinfo.c | 2 +- agetaddrinfo.h | 1 - combine_delta.c | 1 - compiler.h | 96 ++++++++++++++++++++++++++++++++++++++++++++++ configure | 5 ++- main.c | 1 - main_client.c | 1 - main_poll_server.c | 1 - ntimed.h | 2 +- ntimed_platform.h | 69 +++++++++++++++++++++++++++++++++ time_stuff.c | 1 - udp.c | 2 - 12 files changed, 170 insertions(+), 12 deletions(-) create mode 100644 compiler.h create mode 100644 ntimed_platform.h diff --git a/agetaddrinfo.c b/agetaddrinfo.c index dcec001..bf016c8 100644 --- a/agetaddrinfo.c +++ b/agetaddrinfo.c @@ -77,7 +77,7 @@ #include #include -#include "atimed.h" +#include "ntimed.h" #include "agetaddrinfo.h" #if defined(STDC_HEADERS) || defined(HAVE_STRING_H) diff --git a/agetaddrinfo.h b/agetaddrinfo.h index cf0b27d..5427bcd 100644 --- a/agetaddrinfo.h +++ b/agetaddrinfo.h @@ -31,7 +31,6 @@ #include #include -#include "atimed.h" /********************************************************************/ /* diff --git a/combine_delta.c b/combine_delta.c index c0f9d28..9351572 100644 --- a/combine_delta.c +++ b/combine_delta.c @@ -48,7 +48,6 @@ #include #include "ntimed.h" -#include "atimed.h" struct cd_stat { double x; diff --git a/compiler.h b/compiler.h new file mode 100644 index 0000000..74ff50f --- /dev/null +++ b/compiler.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2015 Carsten Larsen + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef NTIMED_COMPILER_H +#define NTIMED_COMPILER_H + +/* + * See alse: + * http://codewiz.org/projects/amiga/Headers/CompilerSpecific.h + * + */ + +#ifdef __VBCC__ +#include +#include +#define nan(p) NAN +#define __inline +#define __printflike(a, b) +#define round(x) x > 0.0 ? floor(x + 0.5) : ceil(x - 0.5) +typedef uint32_t register_t; +#endif + +#ifdef __GNUC__ + +#ifdef AOS3 +/* + * GCC 2.95.3 + */ +#include +#include +#include +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; +typedef uint32_t uintptr_t; + +static inline double +round(double x) +{ + return x > 0.0 ? floor(x + 0.5) : ceil(x - 0.5); +} + +#define nan(p) 0./0. +#endif + +#ifdef AROS +#include +typedef uint32_t register_t; +#endif +#endif + +#ifndef _ALIGNBYTES +#define _ALIGNBYTES (sizeof(register_t) - 1) +#define ALIGN(p) (((uintptr_t)(p) + _ALIGNBYTES) & ~_ALIGNBYTES) +#endif + +#ifdef __GNUC__ +typedef unsigned int sa_family_t; +typedef unsigned int socklen_t; +typedef uint16_t in_port_t; +#endif + +// General socket address holding structure, big enough to hold either +// struct sockaddr_in or struct sockaddr_in6 data: +struct sockaddr_storage { + sa_family_t ss_family; // address family + + // all this is padding, implementation specific, ignore it: + char __ss_pad1[128 - sizeof(sa_family_t)]; +}; + +#endif diff --git a/configure b/configure index 825f54d..e5c2e35 100644 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (c) 2014 Carsten Larsen +# Copyright (c) 2015 Carsten Larsen # Copyright (c) 2014 Poul-Henning Kamp # All rights reserved. # @@ -41,9 +41,10 @@ set -e # NB: These SHALL always be included with #include "..." HDRS=' - atimed.h + compiler.h ntimed.h ntimed_endian.h + ntimed_platform.h ntimed_queue.h ntimed_tricks.h ntp.h diff --git a/main.c b/main.c index e9cb618..9750699 100644 --- a/main.c +++ b/main.c @@ -30,7 +30,6 @@ #include -#include "atimed.h" #include "ntimed.h" #include "ntp.h" diff --git a/main_client.c b/main_client.c index 2778a17..c3b1169 100644 --- a/main_client.c +++ b/main_client.c @@ -38,7 +38,6 @@ #include #include "tz.h" -#include "atimed.h" #include "ntimed.h" #include "ntp.h" #include "udp.h" diff --git a/main_poll_server.c b/main_poll_server.c index baaa699..8f04a40 100644 --- a/main_poll_server.c +++ b/main_poll_server.c @@ -35,7 +35,6 @@ #include #include -#include "atimed.h" #include "ntimed.h" #include "ntp.h" #include "udp.h" diff --git a/ntimed.h b/ntimed.h index b3bdc43..253053c 100644 --- a/ntimed.h +++ b/ntimed.h @@ -32,7 +32,7 @@ #endif #define NTIMED_H_INCLUDED -#include "atimed.h" +#include "compiler.h" #include #include "ntimed_queue.h" diff --git a/ntimed_platform.h b/ntimed_platform.h new file mode 100644 index 0000000..fbdbdbc --- /dev/null +++ b/ntimed_platform.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2015 Carsten Larsen + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef NTIMED_PLATFROM_H +#define NTIMED_PLATFROM_H + +#if defined(AROS) || defined(AOS3) +#ifndef AMIGA +#define AMIGA +#endif +#endif + +#define ARGSFORMAT "P=PARAM/K,T=TRACEFILE/K,Z=TIMEZONE/K,SERVERS/M,SYNC/S,SAVE/S,QUIET/S" + +#ifdef AOS3 +#define ARGPTR STRPTR +#define ARGS_FORMAT ARGSFORMAT +#define BSDLIB_NAME "bsdsocket.library" +#define BSDLIB_REV 04L +#define UTILLIB_NAME "utility.library" +#define UTILLIB_REV 33L +#define TIMER_NAME TIMERNAME +#define BATTCLOCK_NAME BATTCLOCKNAME +#endif + +#ifdef AROS +#define ARGPTR CONST_STRPTR +#define ARGS_FORMAT (CONST_STRPTR)ARGSFORMAT +#define BSDLIB_NAME (CONST_STRPTR)"bsdsocket.library" +#define BSDLIB_REV 04L +#define UTILLIB_NAME (CONST_STRPTR)"utility.library" +#define UTILLIB_REV 33L +#define TIMER_NAME (CONST_STRPTR)TIMERNAME +#define BATTCLOCK_NAME (CONST_STRPTR)BATTCLOCKNAME +#define APRT IPRT +#endif + +void amiga_save_time(void); +void create_wait_timer(void); +void delete_wait_timer(void); + +#define Time_Amiga_Save amiga_save_time +#define CreateWaitTimer create_wait_timer +#define DeleteWaitTimer delete_wait_timer + +#endif diff --git a/time_stuff.c b/time_stuff.c index 901d50c..29daa35 100644 --- a/time_stuff.c +++ b/time_stuff.c @@ -36,7 +36,6 @@ #include #include "ntimed.h" -#include "atimed.h" #define NANO_FRAC 18446744074ULL // 2^64 / 1e9 diff --git a/udp.c b/udp.c index fd647a6..b915b97 100644 --- a/udp.c +++ b/udp.c @@ -41,8 +41,6 @@ #include "ntimed.h" #include "udp.h" - -#include "atimed.h" #include "apoll.h" struct udp_socket {