Changeset 2910
- Timestamp:
- Dec 27, 2006, 1:41:05 AM (19 years ago)
- Location:
- trunk/libc
- Files:
-
- 5 added
- 1 deleted
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libc/include/klibc/backend.h
r2906 r2910 1136 1136 1137 1137 /** 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 */ 1148 int __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 */ 1157 int __libc_Back_timeGet(struct timespec *pTime); 1158 1159 /** 1138 1160 * Gets the current high-resolution timestamp as nanoseconds. 1139 1161 * … … 1141 1163 */ 1142 1164 hrtime_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 */ 1173 int __libc_Back_timeSet(const struct timespec *pNewTime); 1143 1174 1144 1175 /** @} */ -
trunk/libc/include/klibc/time.h
r2909 r2910 60 60 extern struct _tzinfo __libc_gTZInfo; 61 61 extern int16_t const __libc_gaiYearDay[_YEARS+1]; 62 extern uint16_t const __libc_gauMonthDayLeap[ ];63 extern uint16_t const __libc_gauMonthDayNonLeap[ ];62 extern uint16_t const __libc_gauMonthDayLeap[12+1]; 63 extern uint16_t const __libc_gauMonthDayNonLeap[12+1]; 64 64 65 65 … … 72 72 time64_t __mktime64(struct tm *); 73 73 void _compute_dst_table(void); 74 extern int __libc_days2year_slow(time_t *pcDays); 74 75 75 76 … … 79 80 * @returns 1 if it's a leap year, 0 if it's a normal year. 80 81 * @param y The year. 82 * @internal 81 83 */ 82 84 static __inline__ int _leap_year(unsigned y) … … 87 89 } 88 90 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 */ 100 static 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 */ 121 static 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 89 145 __END_DECLS 90 146 -
trunk/libc/include/sys/time.h
r1972 r2910 324 324 325 325 __BEGIN_DECLS 326 /** @todo int adjtime(const struct timeval *, struct timeval *); */ 326 int adjtime(const struct timeval *, struct timeval *); 327 327 int futimes(int, const struct timeval *); 328 328 int getitimer(int, struct itimerval *); -
trunk/libc/src/kNIX/Makefile.kmk
r2907 r2910 114 114 $(PATH_LIBC_SRC)/kNIX/os2/b_threadStartup.c \ 115 115 $(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 \ 116 118 $(PATH_LIBC_SRC)/kNIX/os2/b_timeHighResNano.c \ 119 $(PATH_LIBC_SRC)/kNIX/os2/b_timeSet.c \ 117 120 $(PATH_LIBC_SRC)/kNIX/os2/clock.c \ 118 121 $(PATH_LIBC_SRC)/kNIX/os2/core.c \ … … 164 167 $(PATH_LIBC_SRC)/kNIX/os2/umask.c \ 165 168 $(PATH_LIBC_SRC)/kNIX/os2/__chmod.c \ 166 $(PATH_LIBC_SRC)/kNIX/os2/__close.c \167 169 $(PATH_LIBC_SRC)/kNIX/os2/__dup.c \ 168 170 $(PATH_LIBC_SRC)/kNIX/os2/__dup2.c \ 169 $(PATH_LIBC_SRC)/kNIX/os2/__fcntl.c \170 $(PATH_LIBC_SRC)/kNIX/os2/__ftime.c \171 171 $(PATH_LIBC_SRC)/kNIX/os2/__imphandle.c \ 172 172 $(PATH_LIBC_SRC)/kNIX/os2/__init.c \ … … 178 178 $(PATH_LIBC_SRC)/kNIX/os2/__read_kbd.c \ 179 179 $(PATH_LIBC_SRC)/kNIX/os2/__select.c \ 180 $(PATH_LIBC_SRC)/kNIX/os2/__settime.c \181 180 $(PATH_LIBC_SRC)/kNIX/os2/__spawnve.c \ 182 181 $(PATH_LIBC_SRC)/kNIX/os2/386/appinit.s \ -
trunk/libc/src/kNIX/kNIX.h
r2909 r2910 56 56 #include <klibc/umalloc.h> 57 57 #include <klibc/thread.h> 58 #include <klibc/time.h> 58 59 #include <klibc/backend.h> 59 60 -
trunk/libc/src/kNIX/os2/b_time.c
r2732 r2910 2 2 /** @file 3 3 * 4 * LIBC SYS Backend - times helpers.4 * kNIX - Time helpers, OS/2. 5 5 * 6 * Copyright (c) 2005 knut st. osmundsen <bird@anduin.net>6 * Copyright (c) 2005-2006 knut st. osmundsen <bird-srcspam@anduin.net> 7 7 * 8 8 * 9 * This file is part of k Build.9 * This file is part of kLIBC. 10 10 * 11 * k Buildis free software; you can redistribute it and/or modify12 * it under the terms of the GNU General Public License as published by13 * the Free Software Foundation; either version 2 of the License, or11 * 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 14 * (at your option) any later version. 15 15 * 16 * k Buildis distributed in the hope that it will be useful,16 * kLIBC is distributed in the hope that it will be useful, 17 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 18 * 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. 20 20 * 21 * You should have received a copy of the GNU General Public License22 * along with k Build; if not, write to the Free Software21 * 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 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 24 * 25 25 */ 26 26 27 28 27 /******************************************************************************* 29 28 * Header Files * 30 29 *******************************************************************************/ 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" 37 31 38 32 /** -
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 228 228 extern unsigned long __libc_back_ghevWait; 229 229 230 /** @name Time Helpers 231 * @{ */ 232 void __libc_back_timeUnix2FileTime(time_t Time, PFTIME pTime, PFDATE pDate); 233 /** @} */ 234 230 235 __END_DECLS 231 236 -
trunk/libc/src/libc/time/Makefile.kmk
r2909 r2910 34 34 libc_libc_time_TEMPLATE = libcsub 35 35 libc_libc_time_SOURCES = \ 36 $(PATH_LIBC_SRC)/libc/time/adjtime.c \ 36 37 $(PATH_LIBC_SRC)/libc/time/asctime.c \ 37 38 $(PATH_LIBC_SRC)/libc/time/ctime.c \ … … 49 50 $(PATH_LIBC_SRC)/libc/time/timedata.c \ 50 51 $(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 52 54 53 55 # configure the variants. */ -
trunk/libc/src/libc/time/ftime.c
r2909 r2910 4 4 * kLIBC - ftime(). 5 5 * 6 * Copyright (c) 1993-1996 by Eberhard Mattes7 6 * Copyright (c) 2006 knut st. osmundsen <bird-srcspam@anduin.net> 8 7 * … … 28 27 #include "libc-alias.h" 29 28 #include <sys/timeb.h> 30 #include <time.h>31 29 #include <klibc/time.h> 32 #include < emx/syscalls.h> /// @todo fixme!30 #include <klibc/backend.h> 33 31 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_TIME 34 32 #include <klibc/logstrict.h> 35 33 36 void _STD(ftime)(struct timeb *ptr) 34 35 void _STD(ftime)(struct timeb *pTimeBuf) 37 36 { 38 LIBCLOG_ENTER("p tr=%p\n", (void *)ptr);37 LIBCLOG_ENTER("pTimeBuf=%p\n", (void *)pTimeBuf); 39 38 39 /* Call tzset if required. */ 40 40 if (!__libc_gfTZInfoOk) 41 41 tzset(); 42 42 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); 48 46 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); 51 55 } 52 56 -
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 */ 2 26 3 27 #include "libc-alias.h" 4 #include <sys/timeb.h>5 #include <time.h>6 28 #include <sys/time.h> 29 #include <errno.h> 7 30 #include <klibc/time.h> 8 #include < emx/syscalls.h>31 #include <klibc/backend.h> 9 32 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_TIME 10 33 #include <klibc/logstrict.h> 11 34 12 int _STD(gettimeofday)(struct timeval * tp, struct timezone *tzp)35 int _STD(gettimeofday)(struct timeval *pTime, struct timezone *pTZ) 13 36 { 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); 18 38 39 /* call tzset if required. */ 19 40 if (!__libc_gfTZInfoOk) 20 41 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) 25 45 { 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; 33 57 } 34 58 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 } 35 65 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); 43 74 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); 46 77 } 47 78 -
trunk/libc/src/libc/time/gmtloc.c
r2909 r2910 270 270 return sw->shift != 0; 271 271 } 272 else if (is_dst == 0) 272 273 if (is_dst == 0) 273 274 { 274 275 /* Our caller says that *P is specified as standard time. … … 283 284 return sw->shift != 0; 284 285 } 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 */ 326 325 } 327 326 … … 352 351 return sw->shift != 0; 353 352 } 354 else if (is_dst == 0) 353 354 if (is_dst == 0) 355 355 { 356 356 /* Our caller says that *P is specified as standard time. … … 364 364 return sw->shift != 0; 365 365 } 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 */ 2 26 3 27 #include "libc-alias.h" 4 #include <time.h>5 28 #include <sys/time.h> 6 29 #include <errno.h> 7 #include <klibc/time.h> 8 #include <emx/syscalls.h> /** @todo fixme! */ 30 #include <klibc/backend.h> 9 31 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_TIME 10 32 #include <klibc/logstrict.h> 11 33 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 */ 42 int _STD(settimeofday)(const struct timeval *pNewTime, const struct timezone *pNewTZ) 13 43 { 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); 19 47 20 if ( tzp != NULL)48 if (pNewTime) 21 49 { 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 } 24 70 } 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); 35 78 } 79 -
trunk/libc/src/libc/time/timetabs.c
r2909 r2910 31 31 #include "libc-alias.h" 32 32 #include <klibc/time.h> 33 #include <limits.h>34 33 35 34 … … 58 57 25567, 25933, 26298, 26663, 27028, 27394, 27759, 28124, 28489, 28855, /* 2040 - 2049 */ 59 58 29220, 29585, 29950, 30316, 30681, 31046, 31411, 31777, 32142, 32507, /* 2050 - 2059 */ 60 SHRT_MAX59 0x7fff 61 60 }; 62 61 … … 65 64 * The day number is relative to 01-Jan, of day 01 for January through December. 66 65 */ 67 uint16_t const __libc_gauMonthDayNonLeap[ ] =66 uint16_t const __libc_gauMonthDayNonLeap[12+1] = 68 67 { 69 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, USHRT_MAX68 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 0xffff 70 69 }; 71 70 … … 74 73 * The day number is relative to 01-Jan, of day 01 for January through December. 75 74 */ 76 uint16_t const __libc_gauMonthDayLeap[ ] =75 uint16_t const __libc_gauMonthDayLeap[12+1] = 77 76 { 78 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, USHRT_MAX77 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 0xffff 79 78 }; 80 79
Note:
See TracChangeset
for help on using the changeset viewer.