pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: builtin_functions.c,v 1.582 2004/12/18 18:39:11 grubba Exp $ + || $Id: builtin_functions.c,v 1.583 2004/12/22 12:45:37 grubba Exp $   */      #include "global.h"   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"   #include "object.h"   #include "program.h"   #include "array.h"   #include "pike_error.h"
pike.git/src/builtin_functions.c:4403:    f_aggregate_mapping(20);   }   #endif      #if defined (HAVE_GMTIME) || defined (HAVE_LOCALTIME)   /* Returns the approximate difference in seconds between the    * two struct tm's.    */   static time_t my_tm_diff(const struct tm *t1, const struct tm *t2)   { -  time_t base = (t1->tm_year - t2->tm_year) * 32140800; +  time_t base;    -  +  /* Win32 localtime() returns NULL for all dates before Jan 01, 1970. */ +  if (!t2) return -1; +  +  base = (t1->tm_year - t2->tm_year) * 32140800; +     /* Overflow detection. (Should possibly be done on the other fields    * too to cope with very large invalid dates.) */    if ((t1->tm_year > t2->tm_year) && (base < 0))    return MAX_TIME_T;    if ((t1->tm_year < t2->tm_year) && (base > 0))    return MIN_TIME_T;       base +=    (t1->tm_mon - t2->tm_mon) * 2678400 +    (t1->tm_mday - t2->tm_mday) * 86400 +
pike.git/src/builtin_functions.c:4447: Inside #if defined (HAVE_GMTIME) || defined (HAVE_LOCALTIME)
   for (loop_cnt = 0; loop_cnt < 20; loop_cnt++, old_diff_ts = diff_ts) {    diff_ts = my_tm_diff(target_tm, current_tm = timefn(&current_ts));      #ifdef DEBUG_MY_TIME_INVERSE    fprintf (stderr, "curr: y %d m %d d %d h %d m %d isdst %d\n",    current_tm->tm_year, current_tm->tm_mon, current_tm->tm_mday,    current_tm->tm_hour, current_tm->tm_min, current_tm->tm_isdst);    fprintf (stderr, "diff: %ld\n", (long) diff_ts);   #endif    +  if (!current_tm) { + #ifdef DEBUG_MY_TIME_INVERSE +  fprintf (stderr, "outside range for timefn().\n"); + #endif +  return 0; +  } +     if (!diff_ts) {    /* Got a satisfactory time, but if target_tm has an opinion on    * DST we should check if we can return an alternative in the    * same DST zone, to cope with the overlapping DST adjustment at    * fall. */    if (target_tm->tm_isdst >= 0 &&    target_tm->tm_isdst != current_tm->tm_isdst &&    !tried_dst_displacement) {    /* Offset the time a day and iterate some more (only once    * more, really), so that we approach the target time from the
pike.git/src/builtin_functions.c:4559: Inside #if defined (HAVE_MKTIME) || defined (HAVE_LOCALTIME)
   *! @member int(0..1) "isdst"    *! Is daylight savings time.    *! @member int "timezone"    *! The timezone offset from UTC in seconds. If left out, the time    *! will be calculated in the local timezone.    *! @endmapping    *!    *! Or you can just send them all on one line as the second syntax suggests.    *!    *! @note -  *! On some operating systems (notably AIX), dates before 00:00:00 -  *! UTC, Jan 1, 1970 are not supported. +  *! On some operating systems (notably AIX and Win32), dates before +  *! 00:00:00 UTC, Jan 1, 1970 are not supported.    *!    *! On most systems, the supported range of dates are Dec 13, 1901    *! 20:45:52 UTC through Jan 19, 2038 03:14:07 UTC (inclusive).    *!    *! @seealso    *! @[time()], @[ctime()], @[localtime()], @[gmtime()]    */   PMOD_EXPORT void f_mktime (INT32 args)   {    INT_TYPE sec, min, hour, mday, mon, year;
pike.git/src/builtin_functions.c:4658:   #endif /* STRUCT_TM_HAS_GMTOFF */   #endif /* !HAVE_GMTIME */      #ifdef HAVE_MKTIME    retval = mktime(&date);    if (retval == -1)   #endif    {   #ifdef HAVE_LOCALTIME    /* mktime might fail on dates before 1970 (e.g. GNU libc 2.3.2), -  * so try our own inverse function with localtime. */ +  * so try our own inverse function with localtime. +  * +  * Note that localtime on Win32 will also fail for dates before 1970. +  */    if (!my_time_inverse (&date, &retval, localtime))   #endif    PIKE_ERROR("mktime", "Time conversion unsuccessful.\n", Pike_sp, args);    }      #if !defined (HAVE_GMTIME) && (defined(STRUCT_TM_HAS_GMTOFF) || defined(STRUCT_TM_HAS___TM_GMTOFF))    if((args > 7) && (Pike_sp[7-args].subtype == NUMBER_NUMBER))    {    /* Post-adjust for the timezone.    *