Changeset 2910


Ignore:
Timestamp:
Dec 27, 2006, 1:41:05 AM (19 years ago)
Author:
bird
Message:

The time cleanup is mostly done. (Added adjtime while at it.)

Location:
trunk/libc
Files:
5 added
1 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/libc/include/klibc/backend.h

    r2906 r2910  
    11361136
    11371137/**
     1138 * Set and/or get the time adjustment delta.
     1139 *
     1140 * @returns 0 on success.
     1141 * @returns Negated errno on failure.
     1142 *
     1143 * @param   pi64Delta       The new delta. (optional)
     1144 * @param   pi64OldDelta    The old delta. (optional)
     1145 *
     1146 * @remark  On some hosts this is implemented by using __libc_Back_timeSet().
     1147 */
     1148int __libc_Back_timeAdjust(int64_t const *pi64Delta, int64_t *pi64OldDelta);
     1149
     1150/**
     1151 * Gets the system time.
     1152 *
     1153 * @returns 0 on success.
     1154 * @returns Negative error code (errno.h) on failure.
     1155 * @param   pTime       Where to store the current system time (UCT).
     1156 */
     1157int __libc_Back_timeGet(struct timespec *pTime);
     1158
     1159/**
    11381160 * Gets the current high-resolution timestamp as nanoseconds.
    11391161 *
     
    11411163 */
    11421164hrtime_t __libc_Back_timeHighResNano(void);
     1165
     1166/**
     1167 * Sets the system time.
     1168 *
     1169 * @returns 0 on success.
     1170 * @returns Negative error code (errno.h) on failure.
     1171 * @param   pNewTime    The new time given as UCT.
     1172 */
     1173int __libc_Back_timeSet(const struct timespec *pNewTime);
    11431174
    11441175/** @} */
  • trunk/libc/include/klibc/time.h

    r2909 r2910  
    6060extern struct _tzinfo   __libc_gTZInfo;
    6161extern int16_t const    __libc_gaiYearDay[_YEARS+1];
    62 extern uint16_t const   __libc_gauMonthDayLeap[];
    63 extern uint16_t const   __libc_gauMonthDayNonLeap[];
     62extern uint16_t const   __libc_gauMonthDayLeap[12+1];
     63extern uint16_t const   __libc_gauMonthDayNonLeap[12+1];
    6464
    6565
     
    7272time64_t __mktime64(struct tm *);
    7373void _compute_dst_table(void);
     74extern int __libc_days2year_slow(time_t *pcDays);
    7475
    7576
     
    7980 * @returns 1 if it's a leap year, 0 if it's a normal year.
    8081 * @param   y   The year.
     82 * @internal
    8183 */
    8284static __inline__ int _leap_year(unsigned y)
     
    8789}
    8890
     91/**
     92 * Converts from days into the year to month.
     93 *
     94 * @returns The month of the year. (1 = January)
     95 * @param   pcDays  IN: The number of days into the year. (0-based)
     96 *                  OUT: The number of days into the month. (0-based)
     97 * @param   iYear   The year.
     98 * @internal
     99 */
     100static unsigned __inline__ __libc_dayofyear2month(time_t *pcDays, int iYear)
     101{
     102    uint16_t const *pauMonthDay = _leap_year(iYear) ? __libc_gauMonthDayLeap : __libc_gauMonthDayNonLeap;
     103    const time_t cDays = *pcDays;
     104    unsigned iMonth;
     105    for (iMonth = cDays <= pauMonthDay[6] ? 0 : 6;
     106         cDays >= pauMonthDay[iMonth + 1];
     107         iMonth++)
     108        /* nothing */;
     109    *pcDays = cDays - pauMonthDay[iMonth];
     110    return iMonth;
     111}
     112
     113/**
     114 * Converts from days from epoch to years.
     115 *
     116 * @returns Year number.
     117 * @param   pcDays  IN: the day count relative to epoch.
     118 *                  OUT: the day count relative to the start of the year.
     119 * @internal
     120 */
     121static int __inline__ __libc_days2year(time_t *pcDays)
     122{
     123    /* Perform a binary search to locate the year (i) which *pSeconds falls in. */
     124    const time_t cDays = *pcDays;
     125    int iFirst = 0;
     126    int iLast = _YEARS;
     127    int i;
     128    for (;;)
     129    {
     130        i = (iFirst + iLast) / 2;
     131        if (i < 0 || i >= _YEARS)
     132            return __libc_days2year_slow(pcDays);
     133        if (__libc_gaiYearDay[i] > cDays)
     134            iLast = i - 1;
     135        else if (__libc_gaiYearDay[i + 1] <= cDays)
     136            iFirst = i + 1;
     137        else
     138        {
     139            *pcDays = cDays - __libc_gaiYearDay[i];
     140            return i + 1900;
     141        }
     142    }
     143}
     144
    89145__END_DECLS
    90146
  • trunk/libc/include/sys/time.h

    r1972 r2910  
    324324
    325325__BEGIN_DECLS
    326 /** @todo int   adjtime(const struct timeval *, struct timeval *); */
     326int     adjtime(const struct timeval *, struct timeval *);
    327327int     futimes(int, const struct timeval *);
    328328int     getitimer(int, struct itimerval *);
  • trunk/libc/src/kNIX/Makefile.kmk

    r2907 r2910  
    114114    $(PATH_LIBC_SRC)/kNIX/os2/b_threadStartup.c \
    115115    $(PATH_LIBC_SRC)/kNIX/os2/b_time.c \
     116    $(PATH_LIBC_SRC)/kNIX/os2/b_timeAdjust.c \
     117    $(PATH_LIBC_SRC)/kNIX/os2/b_timeGet.c \
    116118    $(PATH_LIBC_SRC)/kNIX/os2/b_timeHighResNano.c \
     119    $(PATH_LIBC_SRC)/kNIX/os2/b_timeSet.c \
    117120    $(PATH_LIBC_SRC)/kNIX/os2/clock.c \
    118121    $(PATH_LIBC_SRC)/kNIX/os2/core.c \
     
    164167    $(PATH_LIBC_SRC)/kNIX/os2/umask.c \
    165168    $(PATH_LIBC_SRC)/kNIX/os2/__chmod.c \
    166     $(PATH_LIBC_SRC)/kNIX/os2/__close.c \
    167169    $(PATH_LIBC_SRC)/kNIX/os2/__dup.c \
    168170    $(PATH_LIBC_SRC)/kNIX/os2/__dup2.c \
    169     $(PATH_LIBC_SRC)/kNIX/os2/__fcntl.c \
    170     $(PATH_LIBC_SRC)/kNIX/os2/__ftime.c \
    171171    $(PATH_LIBC_SRC)/kNIX/os2/__imphandle.c \
    172172    $(PATH_LIBC_SRC)/kNIX/os2/__init.c \
     
    178178    $(PATH_LIBC_SRC)/kNIX/os2/__read_kbd.c \
    179179    $(PATH_LIBC_SRC)/kNIX/os2/__select.c \
    180     $(PATH_LIBC_SRC)/kNIX/os2/__settime.c \
    181180    $(PATH_LIBC_SRC)/kNIX/os2/__spawnve.c \
    182181    $(PATH_LIBC_SRC)/kNIX/os2/386/appinit.s \
  • trunk/libc/src/kNIX/kNIX.h

    r2909 r2910  
    5656#include <klibc/umalloc.h>
    5757#include <klibc/thread.h>
     58#include <klibc/time.h>
    5859#include <klibc/backend.h>
    5960
  • trunk/libc/src/kNIX/os2/b_time.c

    r2732 r2910  
    22/** @file
    33 *
    4  * LIBC SYS Backend - times helpers.
     4 * kNIX - Time helpers, OS/2.
    55 *
    6  * Copyright (c) 2005 knut st. osmundsen <bird@anduin.net>
     6 * Copyright (c) 2005-2006 knut st. osmundsen <bird-srcspam@anduin.net>
    77 *
    88 *
    9  * This file is part of kBuild.
     9 * This file is part of kLIBC.
    1010 *
    11  * kBuild is free software; you can redistribute it and/or modify
    12  * it under the terms of the GNU General Public License as published by
    13  * the Free Software Foundation; either version 2 of the License, or
     11 * kLIBC is free software; you can redistribute it and/or modify
     12 * it under the terms of the GNU Lesser General Public License as published
     13 * by the Free Software Foundation; either version 2 of the License, or
    1414 * (at your option) any later version.
    1515 *
    16  * kBuild is distributed in the hope that it will be useful,
     16 * kLIBC is distributed in the hope that it will be useful,
    1717 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1818 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19  * GNU General Public License for more details.
     19 * GNU Lesser General Public License for more details.
    2020 *
    21  * You should have received a copy of the GNU General Public License
    22  * along with kBuild; if not, write to the Free Software
     21 * You should have received a copy of the GNU Lesser General Public License
     22 * along with kLIBC; if not, write to the Free Software
    2323 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2424 *
    2525 */
    2626
    27 
    2827/*******************************************************************************
    2928*   Header Files                                                               *
    3029*******************************************************************************/
    31 #include "libc-alias.h"
    32 #define INCL_FSMACROS
    33 #include <os2emx.h>
    34 #include "b_time.h"
    35 #include <time.h>
    36 
     30#include "kNIX.h"
    3731
    3832/**
  • trunk/libc/src/kNIX/os2/b_time.h

    r2732 r2910  
    1 /* $Id$ */
    2 /** @file
    3  *
    4  * LIBC SYS Backend - time helpers.
    5  *
    6  * Copyright (c) 2005 knut st. osmundsen <bird@anduin.net>
    7  *
    8  *
    9  * This file is part of kBuild.
    10  *
    11  * kBuild is free software; you can redistribute it and/or modify
    12  * it under the terms of the GNU General Public License as published by
    13  * the Free Software Foundation; either version 2 of the License, or
    14  * (at your option) any later version.
    15  *
    16  * kBuild is distributed in the hope that it will be useful,
    17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19  * GNU General Public License for more details.
    20  *
    21  * You should have received a copy of the GNU General Public License
    22  * along with kBuild; if not, write to the Free Software
    23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24  *
    25  */
    26 
    27 #ifndef __b_time_h__
    28 #define __b_time_h__
    29 
    30 #include <time.h>
    31 
    32 /**
    33  * Converts local unix time to file time.
    34  *
    35  * @param   Time    Local unix time (secs).
    36  * @param   pTime   Where to store the time.
    37  * @param   pDate   Where to store the date.
    38  */
    39 void __libc_back_timeUnix2FileTime(time_t Time, PFTIME pTime, PFDATE pDate);
    40 
    41 #endif
     1#error dead
  • trunk/libc/src/kNIX/os2/kNIX-os2.h

    r2905 r2910  
    228228extern unsigned long __libc_back_ghevWait;
    229229
     230/** @name Time Helpers
     231 * @{ */
     232void __libc_back_timeUnix2FileTime(time_t Time, PFTIME pTime, PFDATE pDate);
     233/** @} */
     234
    230235__END_DECLS
    231236
  • trunk/libc/src/libc/time/Makefile.kmk

    r2909 r2910  
    3434libc_libc_time_TEMPLATE = libcsub
    3535libc_libc_time_SOURCES = \
     36    $(PATH_LIBC_SRC)/libc/time/adjtime.c \
    3637    $(PATH_LIBC_SRC)/libc/time/asctime.c \
    3738    $(PATH_LIBC_SRC)/libc/time/ctime.c \
     
    4950    $(PATH_LIBC_SRC)/libc/time/timedata.c \
    5051    $(PATH_LIBC_SRC)/libc/time/timetabs.c \
    51     $(PATH_LIBC_SRC)/libc/time/tzset.c
     52    $(PATH_LIBC_SRC)/libc/time/tzset.c \
     53    $(PATH_LIBC_SRC)/libc/time/__libc_days2year_slow.c
    5254
    5355# configure the variants. */
  • trunk/libc/src/libc/time/ftime.c

    r2909 r2910  
    44 * kLIBC - ftime().
    55 *
    6  * Copyright (c) 1993-1996 by Eberhard Mattes
    76 * Copyright (c) 2006 knut st. osmundsen <bird-srcspam@anduin.net>
    87 *
     
    2827#include "libc-alias.h"
    2928#include <sys/timeb.h>
    30 #include <time.h>
    3129#include <klibc/time.h>
    32 #include <emx/syscalls.h> /// @todo fixme!
     30#include <klibc/backend.h>
    3331#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_TIME
    3432#include <klibc/logstrict.h>
    3533
    36 void _STD(ftime)(struct timeb *ptr)
     34
     35void _STD(ftime)(struct timeb *pTimeBuf)
    3736{
    38     LIBCLOG_ENTER("ptr=%p\n", (void *)ptr);
     37    LIBCLOG_ENTER("pTimeBuf=%p\n", (void *)pTimeBuf);
    3938
     39    /* Call tzset if required. */
    4040    if (!__libc_gfTZInfoOk)
    4141        tzset();
    4242
    43     __ftime(ptr);
    44     time_t t_loc;
    45     t_loc = ptr->time;
    46     ptr->dstflag = _loc2gmt(&ptr->time, -1);
    47     ptr->timezone = __libc_gTZInfo.tz / 60;
     43    /* Get the current time (UCT). */
     44    struct timespec TimeSpec = {0, 0};
     45    __libc_Back_timeGet(&TimeSpec);
    4846
    49     LIBCLOG_RETURN_MSG_VOID("ptr=%p:{.time=%ld, .millitm=%u, .timezone=%d, .dstflag=%d}\n",
    50                             (void *)ptr, (long)ptr->time, ptr->millitm, ptr->timezone, ptr->dstflag);
     47    /* Convert the timespec to the timeb output struct. */
     48    pTimeBuf->time = TimeSpec.tv_sec;
     49    pTimeBuf->millitm = TimeSpec.tv_nsec / 1000000;
     50    pTimeBuf->timezone = __libc_gTZInfo.tz / 60;
     51    pTimeBuf->dstflag = _gmt2loc(&TimeSpec.tv_sec);
     52
     53    LIBCLOG_RETURN_MSG_VOID("ret void - pTimeBuf=%p:{.time=%lld, .millitm=%u, .timezone=%d, .dstflag=%d}\n",
     54                            (void *)pTimeBuf, (long long)pTimeBuf->time, pTimeBuf->millitm, pTimeBuf->timezone, pTimeBuf->dstflag);
    5155}
    5256
  • trunk/libc/src/libc/time/gettimeofday.c

    r2909 r2910  
    1 /* gettimeo.c (emx+gcc) -- Copyright (c) 1993-1996 by Eberhard Mattes */
     1/* $Id: $ */
     2/** @file
     3 *
     4 * kLIBC - gettimeofday().
     5 *
     6 * Copyright (c) 2006 knut st. osmundsen <bird-srcspam@anduin.net>
     7 *
     8 *
     9 * This file is part of kLIBC.
     10 *
     11 * kLIBC is free software; you can redistribute it and/or modify
     12 * it under the terms of the GNU Lesser General Public License as published
     13 * by the Free Software Foundation; either version 2 of the License, or
     14 * (at your option) any later version.
     15 *
     16 * kLIBC is distributed in the hope that it will be useful,
     17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19 * GNU Lesser General Public License for more details.
     20 *
     21 * You should have received a copy of the GNU Lesser General Public License
     22 * along with kLIBC; if not, write to the Free Software
     23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     24 *
     25 */
    226
    327#include "libc-alias.h"
    4 #include <sys/timeb.h>
    5 #include <time.h>
    628#include <sys/time.h>
     29#include <errno.h>
    730#include <klibc/time.h>
    8 #include <emx/syscalls.h>
     31#include <klibc/backend.h>
    932#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_TIME
    1033#include <klibc/logstrict.h>
    1134
    12 int _STD(gettimeofday)(struct timeval *tp, struct timezone *tzp)
     35int _STD(gettimeofday)(struct timeval *pTime, struct timezone *pTZ)
    1336{
    14     LIBCLOG_ENTER("tp=%p tzp=%p\n", (void *)tp, (void *)tzp);
    15     struct timeb tb;
    16     time_t t_loc;
    17     int dst;
     37    LIBCLOG_ENTER("pTime=%p pTZ=%p\n", (void *)pTime, (void *)pTZ);
    1838
     39    /* call tzset if required. */
    1940    if (!__libc_gfTZInfoOk)
    2041        tzset();
    21     __ftime(&tb);
    22     t_loc = tb.time;
    23     dst = _loc2gmt(&tb.time, -1);
    24     if (tp != NULL)
     42
     43    /* get the time if requested. */
     44    if (pTime)
    2545    {
    26         tp->tv_sec = tb.time;
    27         tp->tv_usec = tb.millitm * 1000;
    28     }
    29     if (tzp != NULL)
    30     {
    31         tzp->tz_minuteswest = __libc_gTZInfo.tz / 60;
    32         tzp->tz_dsttime = dst;
     46        struct timespec TimeSpec;
     47        int rc = __libc_Back_timeGet(&TimeSpec);
     48        if (rc)
     49        {
     50            errno = rc;
     51            LIBCLOG_ERROR_RETURN_INT(-1);
     52        }
     53
     54        /* convert */
     55        pTime->tv_usec = TimeSpec.tv_nsec / 1000;
     56        pTime->tv_sec = TimeSpec.tv_sec;
    3357    }
    3458
     59    /* construct the timezone info if requested */
     60    if (pTZ)
     61    {
     62        pTZ->tz_minuteswest = __libc_gTZInfo.tz / 60;
     63        pTZ->tz_dsttime = __libc_gTZInfo.dst; /** @todo Figure out tz_dsttime! */
     64    }
    3565
    36     if (tp && tzp)
    37         LIBCLOG_RETURN_MSG(0, "ret 0 - tp=%p:{.tv_sec=%ld, .tv_usec=%ld} tzp=%p:{.tz_minuteswest=%d, .tz_dsttime=%d}\n",
    38                            (void *)tp, tp->tv_sec, tp->tv_usec,
    39                            (void *)tzp, tzp->tz_minuteswest, tzp->tz_dsttime);
    40     else if (tp)
    41         LIBCLOG_RETURN_MSG(0, "ret 0 - tp=%p:{.tv_sec=%ld, .tv_usec=%ld}\n",
    42                            (void *)tp, tp->tv_sec, tp->tv_usec);
     66    /* done */
     67    if (pTime && pTZ)
     68        LIBCLOG_RETURN_MSG(0, "ret 0 - pTime=%p:{.tv_sec=%ld, .tv_usec=%ld} pTZ=%p:{.tz_minuteswest=%d, .tz_dsttime=%d}\n",
     69                           (void *)pTime, pTime->tv_sec, pTime->tv_usec,
     70                           (void *)pTZ, pTZ->tz_minuteswest, pTZ->tz_dsttime);
     71    else if (pTime)
     72        LIBCLOG_RETURN_MSG(0, "ret 0 - pTime=%p:{.tv_sec=%ld, .tv_usec=%ld}\n",
     73                           (void *)pTime, pTime->tv_sec, pTime->tv_usec);
    4374    else
    44         LIBCLOG_RETURN_MSG(0, "ret 0 - tzp=%p:{.tz_minuteswest=%d, .tz_dsttime=%d}\n",
    45                            (void *)tzp, tzp->tz_minuteswest, tzp->tz_dsttime);
     75        LIBCLOG_RETURN_MSG(0, "ret 0 - pTZ=%p:{.tz_minuteswest=%d, .tz_dsttime=%d}\n",
     76                           (void *)pTZ, pTZ->tz_minuteswest, pTZ->tz_dsttime);
    4677}
    4778
  • trunk/libc/src/libc/time/gmtloc.c

    r2909 r2910  
    270270        return sw->shift != 0;
    271271    }
    272     else if (is_dst == 0)
     272
     273    if (is_dst == 0)
    273274    {
    274275        /* Our caller says that *P is specified as standard time.
     
    283284        return sw->shift != 0;
    284285    }
    285     else
    286     {
    287         /* Our caller does not know whether *P is specified as DST or
    288            standard time.  Try to find out.  First try DST. */
    289 
    290         count = 0;
    291         if (ADD_OK(*p, __libc_gTZInfo.tz - __libc_gTZInfo.shift))
    292         {
    293             x = *p + __libc_gTZInfo.tz - __libc_gTZInfo.shift;
    294             sw = find_switch(x);
    295             if (sw->shift != 0)
    296             {
    297                 *p = x;
    298                 return 1;         /* DST */
    299             }
    300             ++count;
    301         }
    302 
    303         if (ADD_OK(*p, __libc_gTZInfo.tz))
    304         {
    305             x = *p + __libc_gTZInfo.tz;
    306             sw = find_switch(x);
    307             if (sw->shift == 0)
    308             {
    309                 *p = x;
    310                 return 0;         /* Not DST */
    311             }
    312             ++count;
    313         }
    314 
    315         if (count != 2)
    316             return -1;            /* Overflow */
    317 
    318         /* Assume that DST does not apply in the gap.  This makes moving
    319            into the gap from below work, but breaks moving into the gap
    320            from above.  The advantage of this choice is that ftime()
    321            works correctly in the gap if the clock is not adjusted. */
    322 
    323         *p += __libc_gTZInfo.tz;
    324         return 0;                 /* Not DST */
    325     }
     286
     287    /* Our caller does not know whether *P is specified as DST or
     288       standard time.  Try to find out.  First try DST. */
     289
     290    count = 0;
     291    if (ADD_OK(*p, __libc_gTZInfo.tz - __libc_gTZInfo.shift))
     292    {
     293        x = *p + __libc_gTZInfo.tz - __libc_gTZInfo.shift;
     294        sw = find_switch(x);
     295        if (sw->shift != 0)
     296        {
     297            *p = x;
     298            return 1;         /* DST */
     299        }
     300        ++count;
     301    }
     302
     303    if (ADD_OK(*p, __libc_gTZInfo.tz))
     304    {
     305        x = *p + __libc_gTZInfo.tz;
     306        sw = find_switch(x);
     307        if (sw->shift == 0)
     308        {
     309            *p = x;
     310            return 0;         /* Not DST */
     311        }
     312        ++count;
     313    }
     314
     315    if (count != 2)
     316        return -1;            /* Overflow */
     317
     318    /* Assume that DST does not apply in the gap.  This makes moving
     319       into the gap from below work, but breaks moving into the gap
     320       from above.  The advantage of this choice is that ftime()
     321       works correctly in the gap if the clock is not adjusted. */
     322
     323    *p += __libc_gTZInfo.tz;
     324    return 0;                 /* Not DST */
    326325}
    327326
     
    352351        return sw->shift != 0;
    353352    }
    354     else if (is_dst == 0)
     353
     354    if (is_dst == 0)
    355355    {
    356356        /* Our caller says that *P is specified as standard time.
     
    364364        return sw->shift != 0;
    365365    }
    366     else
    367     {
    368         /* Our caller does not know whether *P is specified as DST or
    369            standard time.  Try to find out.  First try DST. */
    370         count = 0;
    371         x = *p + __libc_gTZInfo.tz - __libc_gTZInfo.shift;
    372         if (!(__libc_gTZInfo.tz - __libc_gTZInfo.shift > 0 ? x < *p : x > *p))
    373         {
    374             sw = find_switch(x);
    375             if (sw->shift != 0)
    376             {
    377                 *p = x;
    378                 return 1;         /* DST */
    379             }
    380             ++count;
    381         }
    382 
    383         x = *p + __libc_gTZInfo.tz;
    384         if (!(__libc_gTZInfo.tz > 0 ? x < *p : x > *p))
    385         {
    386             sw = find_switch(x);
    387             if (sw->shift == 0)
    388             {
    389                 *p = x;
    390                 return 0;         /* Not DST */
    391             }
    392             ++count;
    393         }
    394 
    395         if (count != 2)
    396             return -1;            /* Overflow */
    397 
    398         /* Assume that DST does not apply in the gap.  This makes moving
    399            into the gap from below work, but breaks moving into the gap
    400            from above.  The advantage of this choice is that ftime()
    401            works correctly in the gap if the clock is not adjusted. */
    402         *p += __libc_gTZInfo.tz;
    403         return 0;                 /* Not DST */
    404     }
    405 }
    406 
     366
     367    /* Our caller does not know whether *P is specified as DST or
     368       standard time.  Try to find out.  First try DST. */
     369    count = 0;
     370    x = *p + __libc_gTZInfo.tz - __libc_gTZInfo.shift;
     371    if (!(__libc_gTZInfo.tz - __libc_gTZInfo.shift > 0 ? x < *p : x > *p))
     372    {
     373        sw = find_switch(x);
     374        if (sw->shift != 0)
     375        {
     376            *p = x;
     377            return 1;         /* DST */
     378        }
     379        ++count;
     380    }
     381
     382    x = *p + __libc_gTZInfo.tz;
     383    if (!(__libc_gTZInfo.tz > 0 ? x < *p : x > *p))
     384    {
     385        sw = find_switch(x);
     386        if (sw->shift == 0)
     387        {
     388            *p = x;
     389            return 0;         /* Not DST */
     390        }
     391        ++count;
     392    }
     393
     394    if (count != 2)
     395        return -1;            /* Overflow */
     396
     397    /* Assume that DST does not apply in the gap.  This makes moving
     398       into the gap from below work, but breaks moving into the gap
     399       from above.  The advantage of this choice is that ftime()
     400       works correctly in the gap if the clock is not adjusted. */
     401    *p += __libc_gTZInfo.tz;
     402    return 0;                 /* Not DST */
     403}
     404
  • trunk/libc/src/libc/time/settimeofday.c

    r2909 r2910  
    1 /* settimeo.c (emx+gcc) -- Copyright (c) 1995-1996 by Eberhard Mattes */
     1/* $Id: $ */
     2/** @file
     3 *
     4 * kLIBC - settimeofday().
     5 *
     6 * Copyright (c) 2006 knut st. osmundsen <bird-srcspam@anduin.net>
     7 *
     8 *
     9 * This file is part of kLIBC.
     10 *
     11 * kLIBC is free software; you can redistribute it and/or modify
     12 * it under the terms of the GNU Lesser General Public License as published
     13 * by the Free Software Foundation; either version 2 of the License, or
     14 * (at your option) any later version.
     15 *
     16 * kLIBC is distributed in the hope that it will be useful,
     17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19 * GNU Lesser General Public License for more details.
     20 *
     21 * You should have received a copy of the GNU Lesser General Public License
     22 * along with kLIBC; if not, write to the Free Software
     23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     24 *
     25 */
    226
    327#include "libc-alias.h"
    4 #include <time.h>
    528#include <sys/time.h>
    629#include <errno.h>
    7 #include <klibc/time.h>
    8 #include <emx/syscalls.h> /** @todo fixme! */
     30#include <klibc/backend.h>
    931#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_TIME
    1032#include <klibc/logstrict.h>
    1133
    12 int _STD(settimeofday)(const struct timeval *tp, const struct timezone *tzp)
     34
     35/**
     36 * Set the time of day and/or modify the kernel timezone.
     37 *
     38 * @remark  Unlike the BSD implementation, this call will never fail with permission
     39 *          denied when both parameters are NULL.
     40 * @remark  Changing the time zone is not yet implemented.
     41 */
     42int _STD(settimeofday)(const struct timeval *pNewTime, const struct timezone *pNewTZ)
    1343{
    14     LIBCLOG_ENTER("tp=%p:{.tv_sec=%lld, .tv_usec=%ld} tzp=%p:{.tz_minuteswest=%d, .tz_dsttime=%d}\n",
    15                   (void *)tp, tp ? (long long)tp->tv_sec : -1, tp ? (long)tp->tv_usec : -1,
    16                   (void *)tzp, tzp ? tzp->tz_minuteswest : -1, tzp ? tzp->tz_dsttime : -1);
    17     struct timeval local;
    18     time_t t;
     44    LIBCLOG_ENTER("pNewTime=%p:{.tv_sec=%lld, .tv_usec=%ld} pNewTZ=%p:{.tz_minuteswest=%d, .tz_dsttime=%d}\n",
     45                  (void *)pNewTime, pNewTime ? (long long)pNewTime->tv_sec : -1, pNewTime ? (long)pNewTime->tv_usec : -1,
     46                  (void *)pNewTZ, pNewTZ ? pNewTZ->tz_minuteswest : -1, pNewTZ ? pNewTZ->tz_dsttime : -1);
    1947
    20     if (tzp != NULL)
     48    if (pNewTime)
    2149    {
    22         errno = EINVAL;
    23         LIBCLOG_ERROR_RETURN(-1, "ret -1 - tzp is NULL!\n");
     50        /* Convert to timespec and normalize the input (specs?). */
     51        struct timespec TimeSpec;
     52        TimeSpec.tv_sec = pNewTime->tv_sec;
     53        TimeSpec.tv_nsec = pNewTime->tv_usec * 1000;
     54        while (TimeSpec.tv_nsec < 0)
     55        {
     56            TimeSpec.tv_nsec += 1000000000;
     57            TimeSpec.tv_sec--;
     58        }
     59        while (TimeSpec.tv_nsec > 1000000000)
     60        {
     61            TimeSpec.tv_nsec -=  1000000000;
     62            TimeSpec.tv_sec++;
     63        }
     64        int rc = __libc_Back_timeSet(&TimeSpec);
     65        if (rc)
     66        {
     67            errno = -rc;
     68            LIBCLOG_ERROR_RETURN_INT(-1);
     69        }
    2470    }
    25     if (!__libc_gfTZInfoOk)
    26         tzset();
    27     t = tp->tv_sec;
    28     _gmt2loc(&t);
    29     local.tv_sec = t;
    30     local.tv_usec = tp->tv_usec;
    31     int rc = __settime(&local);
    32     if (!rc)
    33         LIBCLOG_RETURN_INT(rc);
    34     LIBCLOG_ERROR_RETURN_INT(rc);
     71
     72    if (pNewTZ)
     73    {
     74        /** @todo implement pNewTZ */
     75    }
     76
     77    LIBCLOG_RETURN_INT(0);
    3578}
     79
  • trunk/libc/src/libc/time/timetabs.c

    r2909 r2910  
    3131#include "libc-alias.h"
    3232#include <klibc/time.h>
    33 #include <limits.h>
    3433
    3534
     
    5857    25567, 25933, 26298, 26663, 27028, 27394, 27759, 28124, 28489, 28855,  /* 2040 - 2049 */
    5958    29220, 29585, 29950, 30316, 30681, 31046, 31411, 31777, 32142, 32507,  /* 2050 - 2059 */
    60     SHRT_MAX
     59    0x7fff
    6160};
    6261
     
    6564 * The day number is relative to 01-Jan, of day 01 for January through December.
    6665 */
    67 uint16_t const __libc_gauMonthDayNonLeap[] =
     66uint16_t const __libc_gauMonthDayNonLeap[12+1] =
    6867{
    69     0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, USHRT_MAX
     68    0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 0xffff
    7069};
    7170
     
    7473 * The day number is relative to 01-Jan, of day 01 for January through December.
    7574 */
    76 uint16_t const __libc_gauMonthDayLeap[] =
     75uint16_t const __libc_gauMonthDayLeap[12+1] =
    7776{
    78     0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, USHRT_MAX
     77    0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 0xffff
    7978};
    8079
Note: See TracChangeset for help on using the changeset viewer.