time.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 1998-2001, 2003-2008, 2011, 2012, 2014-2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id$ */
/*! \file */
#include <config.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <syslog.h>
#include <time.h>
#include <isc/strerror.h>
/*
* All of the INSIST()s checks of nanoseconds < NS_PER_S are for
* consistency checking of the type. In lieu of magic numbers, it
* is the best we've got. The check is only performed on functions which
* need an initialized type.
*/
#ifndef ISC_FIX_TV_USEC
#define ISC_FIX_TV_USEC 1
#endif
/*%
*** Intervals
***/
static const isc_interval_t zero_interval = { 0, 0 };
#if ISC_FIX_TV_USEC
static inline void
do {
do {
}
/*
* Call syslog directly as was are called from the logging functions.
*/
if (fixed)
}
#endif
void
unsigned int seconds, unsigned int nanoseconds)
{
i->nanoseconds = nanoseconds;
}
isc_interval_iszero(const isc_interval_t *i) {
if (i->seconds == 0 && i->nanoseconds == 0)
return (ISC_TRUE);
return (ISC_FALSE);
}
/***
*** Absolute Times
***/
static const isc_time_t epoch = { 0, 0 };
void
t->nanoseconds = nanoseconds;
}
void
t->seconds = 0;
t->nanoseconds = 0;
}
isc_time_isepoch(const isc_time_t *t) {
if (t->seconds == 0 && t->nanoseconds == 0)
return (ISC_TRUE);
return (ISC_FALSE);
}
isc_time_now(isc_time_t *t) {
char strbuf[ISC_STRERRORSIZE];
return (ISC_R_UNEXPECTED);
}
/*
* Does POSIX guarantee the signedness of tv_sec and tv_usec? If not,
* then this test will generate warnings for platforms on which it is
* unsigned. In any event, the chances of any of these problems
* happening are pretty much zero, but since the libisc library ensures
* certain things to be true ...
*/
#if ISC_FIX_TV_USEC
fix_tv_usec(&tv);
return (ISC_R_UNEXPECTED);
#else
return (ISC_R_UNEXPECTED);
#endif
/*
* Ensure the tv_sec value fits in t->seconds.
*/
return (ISC_R_RANGE);
return (ISC_R_SUCCESS);
}
char strbuf[ISC_STRERRORSIZE];
return (ISC_R_UNEXPECTED);
}
/*
* Does POSIX guarantee the signedness of tv_sec and tv_usec? If not,
* then this test will generate warnings for platforms on which it is
* unsigned. In any event, the chances of any of these problems
* happening are pretty much zero, but since the libisc library ensures
* certain things to be true ...
*/
#if ISC_FIX_TV_USEC
fix_tv_usec(&tv);
return (ISC_R_UNEXPECTED);
#else
return (ISC_R_UNEXPECTED);
#endif
/*
* Ensure the resulting seconds value fits in the size of an
* unsigned int. (It is written this way as a slight optimization;
* note that even if both values == INT_MAX, then when added
* and getting another 1 added below the result is UINT_MAX.)
*/
return (ISC_R_RANGE);
if (t->nanoseconds >= NS_PER_S) {
t->seconds++;
t->nanoseconds -= NS_PER_S;
}
return (ISC_R_SUCCESS);
}
int
return (-1);
return (1);
return (-1);
return (1);
return (0);
}
{
/*
* Ensure the resulting seconds value fits in the size of an
* unsigned int. (It is written this way as a slight optimization;
* note that even if both values == INT_MAX, then when added
* and getting another 1 added below the result is UINT_MAX.)
*/
return (ISC_R_RANGE);
}
return (ISC_R_SUCCESS);
}
{
t->nanoseconds < i->nanoseconds))
return (ISC_R_RANGE);
if (t->nanoseconds >= i->nanoseconds)
else {
t->nanoseconds;
}
return (ISC_R_SUCCESS);
}
return (0);
/*
* Convert to microseconds.
*/
return (i3);
}
isc_time_seconds(const isc_time_t *t) {
return ((isc_uint32_t)t->seconds);
}
/*
* Ensure that the number of seconds represented by t->seconds
* can be represented by a time_t. Since t->seconds is an unsigned
* int and since time_t is mostly opaque, this is trickier than
* it seems. (This standardized opaqueness of time_t is *very*
* frustrating; time_t is not even limited to being an integral
* type.)
*
* The mission, then, is to avoid generating any kind of warning
* about "signed versus unsigned" while trying to determine if the
* the unsigned int t->seconds is out range for tv_sec, which is
* pretty much only true if time_t is a signed integer of the same
* size as the return value of isc_time_seconds.
*
* If the paradox in the if clause below is true, t->seconds is out
* of range for time_t.
*/
INSIST(sizeof(unsigned int) == sizeof(isc_uint32_t));
return (ISC_R_RANGE);
return (ISC_R_SUCCESS);
}
isc_time_nanoseconds(const isc_time_t *t) {
return ((isc_uint32_t)t->nanoseconds);
}
void
unsigned int flen;
if (flen != 0)
else {
}
}
void
unsigned int flen;
/*
* 5 spaces, 1 comma, 3 GMT, 2 %d, 4 %Y, 8 %H:%M:%S, 3+ %a, 3+ %b (29+)
*/
}
char *p;
if (p == NULL)
return (ISC_R_UNEXPECTED);
if (when == -1)
return (ISC_R_UNEXPECTED);
isc_time_set(t, when, 0);
return (ISC_R_SUCCESS);
}
void
unsigned int flen;
}
void
unsigned int flen;
t->nanoseconds / NS_PER_MS);
}
}