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.578 2004/12/13 19:37:31 mast Exp $ + || $Id: builtin_functions.c,v 1.579 2004/12/14 15:07:46 mast 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:4407: Inside #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;       /* 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 0x7fffffff; +  return MAX_TIME_T;    if ((t1->tm_year < t2->tm_year) && (base > 0)) -  return -0x7fffffff; +  return MIN_TIME_T;       base +=    (t1->tm_mon - t2->tm_mon) * 2678400 +    (t1->tm_mday - t2->tm_mday) * 86400 +    (t1->tm_hour - t2->tm_hour) * 3600 +    (t1->tm_min - t2->tm_min) * 60 +    (t1->tm_sec - t2->tm_sec);       return base;   }
pike.git/src/builtin_functions.c:4442: Inside #if defined (HAVE_GMTIME) || defined (HAVE_LOCALTIME)
   /* This loop seems stable, and usually converges in two passes.    * The loop counter is for paranoia reasons.    */    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: %d\n", diff_ts); +  fprintf (stderr, "diff: %ld\n", (long) diff_ts);   #endif       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) {
pike.git/src/builtin_functions.c:4498: Inside #if defined (HAVE_GMTIME) || defined (HAVE_LOCALTIME)
   * it's correct to always go forward so that e.g. April 31st    * maps to May 1st. */    if (diff_ts > 0)    current_ts += diff_ts;   #ifdef DEBUG_MY_TIME_INVERSE    fprintf (stderr, "end of month gap\n");   #endif    break;    }    +  if (INT_TYPE_ADD_OVERFLOW (current_ts, diff_ts)) { +  if (diff_ts > 0 && current_ts < MAX_TIME_T) +  current_ts = MAX_TIME_T; +  else if (diff_ts < 0 && current_ts > MIN_TIME_T) +  current_ts = MIN_TIME_T; +  else { + #ifdef DEBUG_MY_TIME_INVERSE +  fprintf (stderr, "outside time_t range\n"); + #endif +  return 0; +  } +  } +  else    current_ts += diff_ts;    }      #ifdef DEBUG_MY_TIME_INVERSE    fprintf (stderr, "res: 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);   #endif    *result = current_ts;    return 1;
pike.git/src/builtin_functions.c:4682: Inside #if defined(HAVE_LOCALTIME)
  #ifdef HAVE_LOCALTIME    /* mktime might fail on dates before 1970 (GNU libc 2.3.2), so    * try our own inverse function with localtime. */    if (!my_time_inverse (&date, &retval, localtime))   #endif    PIKE_ERROR("mktime", "Time conversion unsuccessful.\n", Pike_sp, args);    }    }       pop_n_elems(args); + #if SIZEOF_TIME_T > SIZEOF_INT_TYPE +  push_int64 (retval); + #else    push_int(retval); -  + #endif   }   #define GOT_F_MKTIME   #endif /* HAVE_MKTIME || HAVE_LOCALTIME */      /* Parse a sprintf/sscanf-style format string */   static ptrdiff_t low_parse_format(p_wchar0 *s, ptrdiff_t slen)   {    ptrdiff_t i;    ptrdiff_t offset = 0;    struct svalue *old_sp = Pike_sp;