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.579 2004/12/14 15:07:46 mast Exp $ + || $Id: builtin_functions.c,v 1.580 2004/12/14 16:22:01 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:4423: Inside #if defined (HAVE_GMTIME) || defined (HAVE_LOCALTIME)
   (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;   }      typedef struct tm *time_fn (const time_t *);    - /* Inverse operation of gmtime or localtime. + /* Inverse operation of gmtime or localtime. Unlike mktime(3), this +  * doesn't fill in a normalized time in target_tm.    */   static int my_time_inverse (struct tm *target_tm, time_t *result, time_fn timefn)   {    time_t current_ts = 0;    time_t diff_ts, old_diff_ts = 0;    struct tm *current_tm;    int loop_cnt, tried_dst_displacement = 0;       /* This loop seems stable, and usually converges in two passes.    * The loop counter is for paranoia reasons.
pike.git/src/builtin_functions.c:4622: Inside #if defined (HAVE_MKTIME) || defined (HAVE_LOCALTIME) and #if defined(HAVE_GMTIME)
   if((args > 7) && (Pike_sp[7-args].subtype == NUMBER_NUMBER))    {    /* UTC-relative time. Use gmtime. */    if (!my_time_inverse (&date, &retval, gmtime))    PIKE_ERROR("mktime", "Time conversion failed.\n", Pike_sp, args);    retval += tz;    } else   #endif /* HAVE_GMTIME */       { - #ifdef HAVE_MKTIME -  + #ifndef HAVE_GMTIME   #ifdef STRUCT_TM_HAS_GMTOFF    /* BSD-style */    date.tm_gmtoff = 0;   #else   #ifdef STRUCT_TM_HAS___TM_GMTOFF -  /* Linux-style */ +  /* (Old) Linux-style */    date.__tm_gmtoff = 0;   #else    if((args > 7) && (Pike_sp[7-args].subtype == NUMBER_NUMBER))    {    /* Pre-adjust for the timezone.    *    * Note that pre-adjustment must be done on AIX for dates    * near Jan 1, 1970, since AIX mktime(3) doesn't support    * negative time.    */    date.tm_sec += tz   #ifdef HAVE_EXTERNAL_TIMEZONE    - timezone   #endif /* HAVE_EXTERNAL_TIMEZONE */    ;    }   #endif /* STRUCT_TM_HAS___TM_GMTOFF */   #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. */ +  if (!my_time_inverse (&date, &retval, localtime)) + #endif +  PIKE_ERROR("mktime", "Time conversion unsuccessful.\n", Pike_sp, args); +  }    -  if (retval != -1) { - #if defined(STRUCT_TM_HAS_GMTOFF) || defined(STRUCT_TM_HAS___TM_GMTOFF) + #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.    *    * Note that tm_gmtoff has the opposite sign of timezone.    *    * Note also that it must be post-adjusted, since the gmtoff    * field is set by mktime(3).    */   #ifdef STRUCT_TM_HAS_GMTOFF    retval += tz + date.tm_gmtoff;   #else    retval += tz + date.__tm_gmtoff;   #endif /* STRUCT_TM_HAS_GMTOFF */    } -  + #endif /* !HAVE_GMTIME && (STRUCT_TM_HAS_GMTOFF || STRUCT_TM_HAS___TM_GMTOFF) */    -  + #if 0 +  /* Disabled since the adjustment done here with a hardcoded one +  * hour is bogus in many time zones. mktime(3) in GNU libc is +  * documented to normalize the date spec, which means that e.g. +  * asking for DST time in a non-DST zone will override tm_isdst. +  * /mast */    if ((isdst != -1) && (isdst != date.tm_isdst)) {    /* Some stupid libc's (Hi Linux!) don't accept that we've set isdst... */   #ifdef HAVE_LOCALTIME    if (!my_time_inverse (&date, &retval, localtime))    PIKE_ERROR("mktime", "Cannot convert.\n", Pike_sp, args);   #else    /* Last resort: Assumes a one hour DST. */    retval += 3600 * (isdst - date.tm_isdst);   #endif    } - #endif /* STRUCT_TM_HAS_GMTOFF || STRUCT_TM_HAS___TM_GMTOFF */ + #endif /* 0 */    } -  else - #endif /* HAVE_MKTIME */ +     -  { - #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 */