Initial integration of timezone database

This commit is contained in:
llsth 2015-05-01 00:44:54 +02:00
parent e90dc21d5e
commit 9a2f08fca2
7 changed files with 178 additions and 35 deletions

View File

@ -81,6 +81,7 @@ typedef uint32_t register_t;
#endif
#ifdef __GNUC__
# define HAVE_ASCTIME
typedef uint16_t in_port_t;
typedef unsigned int sa_family_t;
#endif

8
configure vendored
View File

@ -173,12 +173,12 @@ if $VALID ; then
echo ''
if [ -n "$1" ] && [ $1 = "AMIGA" ] ; then
echo 'CC = gcc'
echo "CFLAGS = -O2 -DAOS3 -DWITHTEST -Wall -Werror"
echo "LDLIBS = -lm"
echo "CFLAGS = -O2 -DAOS3 -DWITHTEST -I. -Wall -Werror"
echo "LDLIBS = -Llib/aos3 -ltz -lm"
elif [ -n "$1" ] && [ $1 = "AROS" ] ; then
echo 'CC = gcc'
echo "CFLAGS = -O2 -DAROS -DWITHTEST -Wall -Werror"
echo "LDLIBS = -lm"
echo "CFLAGS = -O2 -DAROS -DWITHTEST -I. -Wall -Werror"
echo "LDLIBS = -Llib/aros-i386 -ltz -lm"
else
echo "CFLAGS = -O2 -Wall -DWITHTEST -Werror"
echo "LDLIBS = -lm"

BIN
lib/aos3/libtz.a Normal file

Binary file not shown.

BIN
lib/aros-i386/libtz.a Normal file

Binary file not shown.

100
lib/tz.h Normal file
View File

@ -0,0 +1,100 @@
/* $NetBSD: time.h,v 1.40 2010/12/16 18:36:47 christos Exp $ */
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
* (c) UNIX System Laboratories, Inc.
* All or some portions of this file are derived from material licensed
* to the University of California by American Telephone and Telegraph
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, Inc.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
*
* @(#)time.h 8.3 (Berkeley) 1/21/94
*/
/**
* @file tz.h
* @brief
* Parts of this file was retrieved from:
* ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-release-6/src/include/time.h
*/
extern char *tzname[2];
struct tz_tm {
int tm_sec; /* seconds after the minute [0-61] */
int tm_min; /* minutes after the hour [0-59] */
int tm_hour; /* hours since midnight [0-23] */
int tm_mday; /* day of the month [1-31] */
int tm_mon; /* months since January [0-11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday [0-6] */
int tm_yday; /* days since January 1 [0-365] */
int tm_isdst; /* Daylight Savings Time flag */
long tm_gmtoff; /* offset from UTC in seconds */
char *tm_zone; /* timezone abbreviation */
};
typedef long tz_time_t;
typedef struct state *timezone_t;
void tz_tzset(void);
void tz_free(const timezone_t);
timezone_t tz_alloc(const char *);
tz_time_t tz_time(tz_time_t *);
tz_time_t tz_mktime_z(const timezone_t, struct tz_tm *);
tz_time_t tz_mktime(struct tz_tm *);
struct tz_tm *tz_localtime_rz(const timezone_t, const tz_time_t *, struct tz_tm *);
struct tz_tm *tz_localtime_r(const tz_time_t *, struct tz_tm *);
struct tz_tm *tz_localtime(const tz_time_t *);
struct tz_tm *tz_gmtime_r(const tz_time_t *, struct tz_tm *);
struct tz_tm *tz_gmtime(const tz_time_t *);
char *tz_ctime_r(const tz_time_t *, char *);
char *tz_ctime(const tz_time_t *);
char *asctime_r(const struct tz_tm *, char *);
double tz_difftime(tz_time_t, tz_time_t);
#ifndef HAVE_ASCTIME
char *asctime(const struct tz_tm *);
#endif
tz_time_t time(tz_time_t *x);
#ifdef HAVENOSYSTIME
#include <clib/timer_protos.h>
tz_time_t time(tz_time_t *x)
{
struct timeval tv;
GetSysTime(&tv);
if (x) {
*x = (time_t)tv.tv_secs;
}
return (time_t)tv.tv_secs;
}
#endif

View File

@ -34,11 +34,11 @@
#endif
#ifdef AMIGA
# include <proto/dos.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
#ifdef AROS
@ -75,6 +75,8 @@
# define UTILLIB_REV 33L
# define LOCALELIB_NAME "locale.library"
# define LOCALELIB_REV 33L
# define DOSLIB_NAME "dos.library"
# define DOSLIB_REV 36L
# define TIMER_NAME TIMERNAME
# define BATTCLOCK_NAME BATTCLOCKNAME
#endif
@ -88,6 +90,8 @@
# define UTILLIB_REV 33L
# define LOCALELIB_NAME (CONST_STRPTR)"locale.library"
# define LOCALELIB_REV 33L
# define DOSLIB_NAME (CONST_STRPTR)"dos.library"
# define DOSLIB_REV 36L
# define TIMER_NAME (CONST_STRPTR)TIMERNAME
# define BATTCLOCK_NAME (CONST_STRPTR)BATTCLOCKNAME
# define APRT IPRT

View File

@ -24,24 +24,24 @@
*
*/
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "ntimed.h"
#include "ntimed_platform.h"
#include "ntimed.h"
#include "lib/tz.h"
#include <stdio.h>
#include <time.h>
#ifdef Debug
#undef Debug
#endif
#include <exec/io.h>
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/devices.h>
#include <devices/timer.h>
#include <proto/timer.h>
#include <proto/battclock.h>
#include <clib/alib_protos.h>
#include <clib/exec_protos.h>
#include <clib/timer_protos.h>
#include <clib/locale_protos.h>
#include <clib/utility_protos.h>
#include <clib/battclock_protos.h>
@ -52,39 +52,42 @@
// 2922 is the number of days between 1.1.1970 and 1.1.1978 (2 leap years and 6 normal)
#define AMIGAOFFSET 2922 * 24 * 60 * 60
int gmtoffset = 0;
int create_timer();
int delete_timer();
void adjust_timeval(struct timeval *tv, double offset);
struct Library *BattClockBase;
struct Library *DOSBase = NULL;
struct Library *UtilityBase = NULL;
struct Library *LocaleBase = NULL;
struct Library *SocketBase = NULL;
struct Locale *locale = NULL;
struct Device *TimerBase = NULL;
struct timerequest *request = NULL;
struct timeval sync_time;
int validtime = 0;
int limited_sync = 0;
long offset = 0;
void amiga_open_libs()
{
if(!(LocaleBase = (struct Library *)OpenLibrary(LOCALELIB_NAME, LOCALELIB_REV))) {
if(!(DOSBase = OpenLibrary(DOSLIB_NAME, DOSLIB_REV))) {
Put(NULL, OCX_DIAG, "Cannot open dos library.\n");
exit(10);
}
if(!(LocaleBase = OpenLibrary(LOCALELIB_NAME, LOCALELIB_REV))) {
Put(NULL, OCX_DIAG, "Cannot open locale library.\n");
exit(10);
}
locale = OpenLocale(NULL);
gmtoffset = (int)locale->loc_GMTOffset * 60;
if(!(locale = OpenLocale(NULL))) {
Put(NULL, OCX_DIAG, "Cannot open current locale.\n");
exit(10);
}
// TODO: use tzlib.a
// get tm header and invoke:
// time_t now = time(NULL);
// struct tm lcl = *localtime(&now)
// And use gmt filed from tm header if != 0
if(!(UtilityBase = (struct Library *)OpenLibrary(UTILLIB_NAME, UTILLIB_REV))) {
if(!(UtilityBase = OpenLibrary(UTILLIB_NAME, UTILLIB_REV))) {
Put(NULL, OCX_DIAG, "Cannot open utility library.\n");
exit(10);
}
@ -108,6 +111,20 @@ void amiga_open_libs()
Put(NULL, OCX_DIAG, "Cannot open timer device.\n");
exit(10);
}
#ifdef USETZDATABASE
if (getenv("TZ")) {
tz_time_t rawtime;
time(&rawtime);
struct tz_tm *localtm = tz_localtime(&rawtime);
offset = -localtm->tm_gmtoff + AMIGAOFFSET;
Put(NULL, OCX_DEBUG, "Using TZ GMT offset %i seconds\n", localtm->tm_gmtoff);
} else
#endif
{
offset = -locale->loc_GMTOffset * 60 + AMIGAOFFSET;
Put(NULL, OCX_DEBUG, "Using locale GMT offset %i minutes\n", locale->loc_GMTOffset );
}
}
void amiga_close_libs()
@ -131,6 +148,11 @@ void amiga_close_libs()
UtilityBase = NULL;
}
if (DOSBase != NULL) {
CloseLibrary(DOSBase);
DOSBase = NULL;
}
#ifdef AROS
if (SocketBase != NULL) {
CloseLibrary(SocketBase);
@ -139,6 +161,8 @@ void amiga_close_libs()
#endif
}
/**********************************************************************/
int create_timer()
{
LONG error;
@ -160,6 +184,8 @@ int create_timer()
return 1;
}
TimerBase = (struct Device*)request->tr_node.io_Device;
return 0;
}
@ -182,25 +208,42 @@ int delete_timer()
/**********************************************************************/
#ifdef USETZDATABASE
tz_time_t time(tz_time_t *x)
{
struct timeval tv;
GetSysTime(&tv);
if (x) {
*x = (time_t)tv.tv_secs + AMIGAOFFSET;
}
return (time_t)tv.tv_secs + AMIGAOFFSET;
}
#endif
/**********************************************************************/
int gettimeofday(struct timeval *tv, struct timezone *tz)
{
#ifdef USESYSTIME
GetSysTime(tv);
tv_secs = (long)tv_secs + offset;
#else
request->tr_node.io_Command = TR_GETSYSTIME;
DoIO((struct IORequest*)request);
tv->tv_secs = (int)request->tr_time.tv_secs - gmtoffset + AMIGAOFFSET;
tv->tv_secs = (long)request->tr_time.tv_secs + offset;
tv->tv_micro = request->tr_time.tv_micro;
#endif
return 0;
}
int settimeofday(const struct timeval *tv, const struct timezone *tz)
{
request->tr_node.io_Command = TR_SETSYSTIME;
request->tr_time.tv_secs = (int)tv->tv_secs + gmtoffset - AMIGAOFFSET;
request->tr_time.tv_secs = (long)tv->tv_secs - offset;
request->tr_time.tv_micro = tv->tv_micro;
DoIO((struct IORequest*)request);
validtime = 1;
return 0;
}
@ -210,16 +253,11 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
void amiga_save_time(void)
{
struct timeval tv;
if(!validtime)
return;
ResetBattClock();
gettimeofday(&tv, NULL);
WriteBattClock(tv.tv_secs + gmtoffset - AMIGAOFFSET);
WriteBattClock((long)tv.tv_secs - offset);
}
/**********************************************************************/
void amiga_sync_time(int seconds)