400 lines
15 KiB
C
400 lines
15 KiB
C
/****************************************************************************
|
|
|
|
|
| (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc.
|
|
| All Rights Reserved.
|
|
|
|
|
| This program is free software; you can redistribute it and/or
|
|
| modify it under the terms of version 2 of the GNU General Public
|
|
| License as published by the Free Software Foundation.
|
|
|
|
|
| This program is distributed in the hope that it will be useful,
|
|
| but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| GNU General Public License for more details.
|
|
|
|
|
| You should have received a copy of the GNU General Public License
|
|
| along with this program; if not, contact Novell, Inc.
|
|
|
|
|
| To contact Novell about this file by physical or electronic mail,
|
|
| you may find current contact information at www.novell.com
|
|
|
|
|
|***************************************************************************
|
|
|
|
|
| NetWare Advance File Services (NSS) module
|
|
|
|
|
|---------------------------------------------------------------------------
|
|
|
|
|
| $Author: vandana $
|
|
| $Date: 2007-04-18 23:26:20 +0530 (Wed, 18 Apr 2007) $
|
|
|
|
|
| $RCSfile$
|
|
| $Revision: 1954 $
|
|
|
|
|
|---------------------------------------------------------------------------
|
|
| This module contains LIBRARY routines that manipulate UTC time.
|
|
|
|
|
| WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
|
|
|
|
|
| This header file should ONLY be used for NSS internal development.
|
|
| This includes Semantic Agents (SA) and Loadable Storage Services (LSS).
|
|
| Any other use may cause conflicts which NSS will NOT fix.
|
|
+-------------------------------------------------------------------------*/
|
|
#ifndef _UTC_H_
|
|
#define _UTC_H_
|
|
|
|
#if defined(__linux__) && defined(__KERNEL__)
|
|
//#pragma pack(push, 8)
|
|
#include "linux/time.h"
|
|
//#pragma pack(pop)
|
|
//#undef NULL
|
|
//#define NULL 0
|
|
#endif
|
|
|
|
|
|
#ifndef _OMNI_H_
|
|
# include <omni.h>
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* Time cache reset bits (bitmap)
|
|
*-------------------------------------------------------------------------*/
|
|
#define TIME_BEASTS 0x00000001
|
|
#define TIME_UTC2DOS 0x00000002
|
|
#define TIME_UTC2SEC 0x00000004
|
|
#define TIME_DOS2UTC 0x00000008
|
|
#define TIME_SEC2UTC 0x00000010
|
|
#define TIME_UTC2MSTIME 0x00000020
|
|
#define TIME_MSTIME2UTC 0x00000040
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* Time defines
|
|
*-------------------------------------------------------------------------*/
|
|
#define INVALID_DOS_TIME ((DOSTime_t)0) /* invalid value for DOS times*/
|
|
#define INVALID_UTC_TIME ((Time_t)0) /* invalid value for UTC times*/
|
|
#define YEAR_2000_IN_UTC (((30*365)+7)*24*60*60) /* Year 2000 in UTC time */
|
|
|
|
/* 3 Centuries, each with 24 leap days, plus 69 years and 17 leap days */
|
|
#define DAYS_FROM_1601_TO_1970 ((3*((100*365)+24))+((69*365)+17))
|
|
#define SECS_IN_A_DAY (24*60*60)
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* Macros for extracting the date and time portions from a dos time
|
|
*-------------------------------------------------------------------------*/
|
|
#define EXTRACT_DOS_DATE(time) (((time) >> 16) & 0xFFFF) /* Date portion */
|
|
#define EXTRACT_DOS_TIME(time) ((time) & 0xFFFF) /* Time portion */
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* Macro for making DOS time for date and time portions
|
|
*-------------------------------------------------------------------------*/
|
|
#define MAKE_DOS_TIME(date, time) (((date) << 16) | time)
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* This defines a structure that keep track of both UTC and DOS time.
|
|
*-------------------------------------------------------------------------*/
|
|
typedef struct Time_s
|
|
{
|
|
Time_t utc; /* Uninversal Time Coordinated (UTC)
|
|
* Time in seconds from January 1, 1970
|
|
*/
|
|
DOSTime_t dos; /* Time in DOS format, kept in local time
|
|
* set to INVALID_DOS_TIME if not valid
|
|
* (must be converted from UTC time).
|
|
*/
|
|
} Time_s;
|
|
|
|
/*---------------------------------------------------------------------------
|
|
* Get current UTC time
|
|
*---------------------------------------------------------------------------*/
|
|
/* extern Time_t GetUTCTime(void); using directy macro
|
|
This #ifdef cannot work unless we change the library
|
|
build process to build separate libs for MOAB and
|
|
GreenRiver. */
|
|
|
|
/* If it stops compiling you'll have to deal with this problem
|
|
|
|
#ifdef _NWMOAB_
|
|
extern volatile Time_t UTCTime;
|
|
# define GetUTCTime() (UTCTime)
|
|
#endif
|
|
#ifdef _NWGREENRIVER_
|
|
extern volatile struct Synchronized_Clock_T SynchronizedClock;
|
|
# define GetUTCTime() (*(Time_t *)&SynchronizedClock)
|
|
#endif
|
|
|
|
but until then the following code works ... */
|
|
|
|
|
|
extern volatile LONG UpTimeInSeconds;
|
|
#define GetUpTime() (*(Time_t *)&UpTimeInSeconds)
|
|
|
|
#define UpTimeToUTCTime( _upTime ) ( GetUTCTime() - GetUpTime() + _upTime )
|
|
|
|
extern void (*BEASTHASH_InvalidateDOSTimesPtr)(void);
|
|
extern BOOL IgnoreTimeZone;
|
|
extern NINT ResetTimeCache;
|
|
|
|
#if zNETWARE
|
|
extern volatile struct Synchronized_Clock_T SynchronizedClock;
|
|
#define GetUTCTime() (*(Time_t *)&SynchronizedClock)
|
|
#define NSS_TimeZoneOffset SynchronizedClock.timezoneOffset
|
|
#define NSS_DaylightOnOff SynchronizedClock.daylightOnOff
|
|
#define NSS_DaylightOffset SynchronizedClock.daylightOffset
|
|
#endif
|
|
|
|
#ifdef __linux__
|
|
#if defined(__KERNEL__)
|
|
//
|
|
// linux/kernel/time.c has the kernel time functions in it.
|
|
// date command uses environment variable TZ and if not set then /etc/localtime
|
|
//
|
|
#ifdef i386
|
|
extern volatile struct timezone sys_tz; // TZ info on Linux???
|
|
#endif
|
|
#define GetUTCTime() (*(Time_t *)&xtime.tv_sec)
|
|
#define NSS_TimeZoneOffset (sys_tz.tz_minuteswest*60)
|
|
#define NSS_DaylightOnOff 0
|
|
#define NSS_DaylightOffset 0
|
|
#else
|
|
extern Time_t GetUTCTime(void);
|
|
extern LONG NSS_TimeZoneOffset;
|
|
extern NINT NSS_DaylightOnOff;
|
|
extern LONG NSS_DaylightOffset;
|
|
#endif
|
|
#endif
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* This routine converts UTC time to local DOSTime format. If the
|
|
* conversion can't be performed it returns INVALID_DOS_TIME
|
|
*-------------------------------------------------------------------------*/
|
|
extern DOSTime_t UTC2dosTime(
|
|
Time_t utc);
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* This routine converts UTC time to seconds from 2000.
|
|
*-------------------------------------------------------------------------*/
|
|
extern Time_t UTC2Sec2000Time(
|
|
Time_t UTC);
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* This routine converts DOS time to UTC time format.
|
|
*-------------------------------------------------------------------------*/
|
|
extern Time_t DOS2utcTime(
|
|
DOSTime_t DOSTime);
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* This routine converts seconds from 2000 to UTC time format.
|
|
*-------------------------------------------------------------------------*/
|
|
extern Time_t Sec20002utcTime(
|
|
Time_t Time);
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* This routine converts UTC time format to a localized UTC time format.
|
|
* (adjusting for timezone and daylight savings time)
|
|
*-------------------------------------------------------------------------*/
|
|
extern Time_t UTC2LocalUtcTime(
|
|
Time_t utc);
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* This routine converts UTC time format to a localized UTC time format.
|
|
* (adjusting for timezone and daylight savings time)
|
|
*-------------------------------------------------------------------------*/
|
|
extern Time_t LocalUtc2UTCTime(
|
|
Time_t utc);
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* This routine converts UTC time format to MSTime_t format (100ns from 1601)
|
|
*-------------------------------------------------------------------------*/
|
|
extern MSTime_t UTC2msTime(
|
|
Time_t utc);
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* This routine converts MSTime_t format to UTC format
|
|
*-------------------------------------------------------------------------*/
|
|
extern Time_t MSTime2utcTime(
|
|
MSTime_t msTime);
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* This routine formats a DOSTime parameter to an ascii string in the
|
|
* format dd-mmm-yyyy hh:mm:ss.
|
|
*-------------------------------------------------------------------------*/
|
|
extern char *DOSDateTime2Str(
|
|
DOSTime_t dosTime,
|
|
char *str);
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* This routine formats a the date portion of a DOSTime to an ascii
|
|
* string in the format dd-mmm-yyyy.
|
|
*-------------------------------------------------------------------------*/
|
|
extern char *DOSDate2Str(
|
|
DOSTime_t dosTime,
|
|
char *str);
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* This routine formats a the time portion of a DOSTime to an ascii
|
|
* string in the format hh:mm:ss.
|
|
*-------------------------------------------------------------------------*/
|
|
extern char *DOSTime2Str(
|
|
DOSTime_t dosTime,
|
|
char *str);
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* This routine formats a UTC time to an ascii string in the format
|
|
* given by the localization configuration.
|
|
*-------------------------------------------------------------------------*/
|
|
extern char *UTCTime2Str(
|
|
Time_t utcTime,
|
|
char *str);
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* This routine formats a UTC time to an ascii string in the format
|
|
* "YYYYMMDDHHMMSS".
|
|
*-------------------------------------------------------------------------*/
|
|
extern char *UTCTime2UniversalStr(
|
|
Time_t utcTime,
|
|
char *str);
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* This routine converts a date_time string in the format
|
|
* (YYYYMMDDHHMMSS) to a Time_t (UTC) structure.
|
|
*-------------------------------------------------------------------------*/
|
|
extern Time_t UniversalStr2utcTime(
|
|
char *str);
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* This routine converts a date string in the format (dd-mmm-yyyy) to a
|
|
* DOSTime structure. The time portion or the structure is returned as 0.
|
|
*-------------------------------------------------------------------------*/
|
|
extern DOSTime_t Str2dosDate(
|
|
char *str);
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* This routine converts a time string in the format (hh:mm:ss) to a
|
|
* DOSTime structure. The date portion or the structure is returned as 0.
|
|
*-------------------------------------------------------------------------*/
|
|
extern DOSTime_t Str2dosTime(
|
|
char *str);
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* This routine converts a date_time string in the format
|
|
* (dd-mmm-yyyy_hh:mm:ss) to a DOSTime structure.
|
|
*-------------------------------------------------------------------------*/
|
|
extern DOSTime_t Str2dosDateTime(
|
|
char *str);
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* This routine converts a date_time string in the format
|
|
* (dd-mmm-yyyy_hh:mm:ss) to a Time_t (UTC) structure.
|
|
*-------------------------------------------------------------------------*/
|
|
extern Time_t Str2utcTime(
|
|
char *str);
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* Macro for checking if DOStime is defined and if not converting UTCtime
|
|
* to DOStime. The input parameter must be a (Time_s *)
|
|
*-------------------------------------------------------------------------*/
|
|
#define VALIDATE_TIME(utcTime, DOStime) \
|
|
{ \
|
|
if ((DOStime) == INVALID_DOS_TIME) \
|
|
(DOStime) = UTC2dosTime((utcTime)); \
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* sets current time into the given time structure. We always want to
|
|
* convert from UTC so set an invalid DOS time value. It will convert on
|
|
* use.
|
|
*-------------------------------------------------------------------------*/
|
|
#define SetCurrentTime(timeStruc) \
|
|
{ \
|
|
(timeStruc)->utc = GetUTCTime(); \
|
|
(timeStruc)->dos = INVALID_DOS_TIME; \
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* Sets both time formats to INVALID.
|
|
*-------------------------------------------------------------------------*/
|
|
#define SetInvalidTime(timeStruc) \
|
|
{ \
|
|
(timeStruc)->utc = INVALID_UTC_TIME; \
|
|
(timeStruc)->dos = INVALID_DOS_TIME; \
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------
|
|
* Returns time in 1 micro second units
|
|
* (1/1,000,000 of a second)
|
|
*-------------------------------------------------------------------------*/
|
|
extern QUAD microSecondTimer(void); /* On linux, use GetSuperHighResolutionTimer */
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
* Routines that will return the difference
|
|
* between microSeconds (seconds) as a string.
|
|
*---------------------------------------------------------------------------*/
|
|
extern char *microSecondsDiffToStr(
|
|
QUAD startingMicroSecond,
|
|
QUAD endingMicroSecond,
|
|
char *str);
|
|
|
|
char *secondsDiffToStr(
|
|
NINT startingSecond,
|
|
NINT endingSecond,
|
|
char *buf);
|
|
|
|
/*---------------------------------------------------------------------------
|
|
* Structures and global variables that are used to determine if the input
|
|
* UTC time is in the summer time
|
|
*---------------------------------------------------------------------------*/
|
|
typedef struct ChangeDate_s
|
|
{
|
|
NINT month; /* month since January -- [1-12] */
|
|
NINT day; /* days since Sunday -- [0-6] */
|
|
NINT which; /* if afterBeforeOrdina= ORDINAL, which ordinal
|
|
* week of month -- [kNone-kLast], otherwise,
|
|
* after or before which day in the month*/
|
|
NINT hour; /* hours since midnight -- [0-23] in seconds */
|
|
NINT date; /* date in the month */
|
|
NINT year; /* if not a rule, which year */
|
|
NINT afterBeforeOrdinal; /* mark whether the ordinal week is passed in, like
|
|
* "FIRST", or in the format of ">=5" or "<=25"
|
|
*/
|
|
BOOL isRule; /* only rules cause rescheduling for the next year*/
|
|
BOOL isOK; /* conversion is done correctly */
|
|
}ChangeDate_s;
|
|
|
|
extern ChangeDate_s DSTStartInfo;
|
|
extern ChangeDate_s DSTStopInfo;
|
|
extern NINT DSTOffset;
|
|
extern BOOL DSTValidation;
|
|
|
|
/*---------------------------------------------------------------------------
|
|
* decide if the input UTC time is in the summer time
|
|
*---------------------------------------------------------------------------*/
|
|
extern BOOL inDaylightSavingTime(
|
|
Time_t utcTime,
|
|
NINT systemDSTOnOff);
|
|
|
|
/*---------------------------------------------------------------------------
|
|
* Convert the set parameter we get from system.
|
|
*---------------------------------------------------------------------------*/
|
|
extern void getDSTChangeRules(
|
|
char *systemInfo,
|
|
ChangeDate_s *dateInfo);
|
|
|
|
/*---------------------------------------------------------------------------
|
|
* Validate the converted result of DSTStartInfo and DSTStopInfo
|
|
*---------------------------------------------------------------------------*/
|
|
void checkOrSetDSTConversionResults(
|
|
SNINT startIsOK, /* if 1, successfully get start information from system, 0 failed */
|
|
SNINT stopIsOK, /* if 1, successfully get stop information from system */
|
|
SNINT offset); /* -1, this value doesn't change; 0, failed to get it
|
|
from system; non-zero, successfully get DST time offset */
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* _UTC_H_ */
|