158 lines
5.3 KiB
C
158 lines
5.3 KiB
C
/*
|
|
* 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_PLATFORM_H
|
|
#define NTIMED_PLATFORM_H
|
|
//--------------------------------------------------------------------------//
|
|
#if defined(AROS) || defined(AOS3)
|
|
# define AMIGA_VERSION " 1.02 (10.07.2015)"
|
|
# ifndef AMIGA
|
|
# define AMIGA
|
|
# endif
|
|
#endif
|
|
//--------------------------------------------------------------------------//
|
|
#ifdef HAVE_LIBTZ
|
|
# define _TIME_H_
|
|
# define HAVE_TIME_T
|
|
# include <sys/time.h>
|
|
# include "tz.h"
|
|
#endif
|
|
#define HAVE_WAITSELECT
|
|
//--------------------------------------------------------------------------//
|
|
#ifdef AMIGA
|
|
# include <exec/io.h>
|
|
# include <exec/types.h>
|
|
# include <exec/memory.h>
|
|
# include <exec/devices.h>
|
|
# include <proto/intuition.h>
|
|
# include <resources/battclock.h>
|
|
# include <clib/battclock_protos.h>
|
|
# include <clib/utility_protos.h>
|
|
# include <clib/dos_protos.h>
|
|
#endif
|
|
//--------------------------------------------------------------------------//
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <math.h>
|
|
#include <string.h>
|
|
#include <sys/time.h>
|
|
#include <sys/types.h>
|
|
#include <sys/param.h>
|
|
#include <sys/ioctl.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
#include <netdb.h>
|
|
#include "mem.h"
|
|
//--------------------------------------------------------------------------//
|
|
#define OPEN_ERROR "Cannot open %s.\n"
|
|
#define OPEN_VER_ERROR "Cannot open %s (%ld.0)\n"
|
|
#define DOSLIB_NAME "dos.library"
|
|
#define DOSLIB_REV 37L
|
|
#define UTILLIB_NAME "utility.library"
|
|
#define UTILLIB_REV 37L
|
|
#define LOCALELIB_NAME "locale.library"
|
|
#define LOCALELIB_REV 37L
|
|
#define BSDLIB_NAME "bsdsocket.library"
|
|
#define BSDLIB_REV 03L
|
|
#define TIMER_NAME TIMERNAME
|
|
#define BATTCLOCK_NAME BATTCLOCKNAME
|
|
#ifdef TZVARIABLE
|
|
# define TZVARIABLE_NAME TZVARIABLE
|
|
#endif
|
|
//--------------------------------------------------------------------------//
|
|
#ifdef AOS3
|
|
# define REQ_ERROR "Requires Kickstart 2.04 (37.175) or later.\n"
|
|
# include "socket_amitcp.h"
|
|
# include <amitcp/socketbasetags.h>
|
|
#endif
|
|
#ifdef AROS
|
|
# define REQ_ERROR "Requires a newer version of AROS.\n"
|
|
# include <proto/socket.h>
|
|
# include <bsdsocket/socketbasetags.h>
|
|
# define APRT IPRT
|
|
#endif
|
|
//--------------------------------------------------------------------------//
|
|
#ifndef AMIGA
|
|
struct timeval {
|
|
ULONG tv_secs;
|
|
ULONG tv_micro;
|
|
};
|
|
#endif
|
|
//--------------------------------------------------------------------------//
|
|
#ifndef HAVE_POLL
|
|
#define POLLIN 0x0001
|
|
struct pollfd {
|
|
int fd;
|
|
short events;
|
|
short revents;
|
|
};
|
|
typedef unsigned int nfds_t;
|
|
int poll(struct pollfd *, nfds_t, int);
|
|
#endif
|
|
//--------------------------------------------------------------------------//
|
|
#ifdef AROS
|
|
# define settimeofday ntimed_settimeofday
|
|
# define gettimeofday ntimed_gettimeofday
|
|
int gettimeofday(struct timeval *tv, struct timezone *tz);
|
|
int settimeofday(const struct timeval *tv, const struct timezone *tz);
|
|
#endif
|
|
//--------------------------------------------------------------------------//
|
|
#ifdef AMIGA
|
|
# define Time_Amiga Time_Unix
|
|
# define Time_Amiga_Passive Time_Unix_Passive
|
|
# define Time_Amiga_Save amiga_save_time
|
|
# define SetSyncTime amiga_sync_time
|
|
#endif
|
|
//--------------------------------------------------------------------------//
|
|
#ifndef _ALIGNBYTES
|
|
# define _ALIGNBYTES (sizeof(register_t) - 1)
|
|
#endif
|
|
#ifndef ALIGN
|
|
# define ALIGN(p) (((uintptr_t)(p) + _ALIGNBYTES) & ~_ALIGNBYTES)
|
|
#endif
|
|
#ifndef SO_TIMESTAMPING
|
|
# define SO_TIMESTAMPING 37
|
|
#endif
|
|
#ifndef SO_TIMESTAMPNS
|
|
# define SO_TIMESTAMPNS 35
|
|
#endif
|
|
//--------------------------------------------------------------------------//
|
|
int amiga_open_libs();
|
|
void amiga_close_libs();
|
|
void amiga_init_offset();
|
|
void amiga_save_time();
|
|
void amiga_sync_time(int seconds);
|
|
void EnableDebug();
|
|
void EnableTraceDebug();
|
|
//--------------------------------------------------------------------------//
|
|
extern struct Library *BattClockBase;
|
|
extern struct Library *DOSBase;
|
|
extern struct Library *UtilityBase;
|
|
extern struct Library *LocaleBase;
|
|
extern struct Library *SocketBase;
|
|
//--------------------------------------------------------------------------//
|
|
#endif
|