pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.c:5498: Inside #if defined(PIKE_DEBUG) and #if defined(YYDEBUG)
      get_all_args("_compiler_trace", args, "%i", &yyd);    pop_n_elems(args);    push_int(yydebug);    yydebug = yyd;   }      #endif /* YYDEBUG */   #endif    - #if defined(HAVE_LOCALTIME) || defined(HAVE_GMTIME) +    static void encode_struct_tm(struct tm *tm)   {    push_text("sec");    push_int(tm->tm_sec);    push_text("min");    push_int(tm->tm_min);    push_text("hour");    push_int(tm->tm_hour);       push_text("mday");
pike.git/src/builtin_functions.c:5522: Inside #if defined(HAVE_LOCALTIME) || defined(HAVE_GMTIME)
   push_text("year");    push_int(tm->tm_year);       push_text("wday");    push_int(tm->tm_wday);    push_text("yday");    push_int(tm->tm_yday);    push_text("isdst");    push_int(tm->tm_isdst);   } - #endif +     - #if defined (HAVE_GMTIME) || defined (HAVE_GMTIME_R) || defined (HAVE_GMTIME_S) +    /*! @decl mapping(string:int) gmtime(int timestamp)    *!    *! Convert seconds since 00:00:00 UTC, Jan 1, 1970 into components.    *!    *! This function works like @[localtime()] but the result is    *! not adjusted for the local time zone.    *!    *! @seealso    *! @[localtime()], @[time()], @[ctime()], @[mktime()]    */
pike.git/src/builtin_functions.c:5568:   #endif    if (!tm) Pike_error ("gmtime() on this system cannot handle "    "the timestamp %"PRINTLONGEST"d.\n", (LONGEST) t);    pop_n_elems(args);    encode_struct_tm(tm);       push_text("timezone");    push_int(0);    f_aggregate_mapping(20);   } - #endif +     - #ifdef HAVE_LOCALTIME +    /*! @decl mapping(string:int) localtime(int timestamp)    *!    *! Convert seconds since 00:00:00 UTC, 1 Jan 1970 into components.    *!    *! @returns    *! This function returns a mapping with the following components:    *! @mapping    *! @member int(0..60) "sec"    *! Seconds over the minute.    *! @member int(0..59) "min"
pike.git/src/builtin_functions.c:5645:    push_int(-tm->__tm_gmtoff);   #elif defined(HAVE_EXTERNAL_TIMEZONE)    /* Assume dst is one hour. */    push_int(timezone - 3600*tm->tm_isdst);   #else    /* Assume dst is one hour. */    push_int(-3600*tm->tm_isdst);   #endif    f_aggregate_mapping(20);   } - #endif +     - #if defined (HAVE_GMTIME) || defined (HAVE_LOCALTIME) -  +    #define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)      static const int mon_lengths[2][12] = {    {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},    {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}   };      static void normalize_date (struct tm *t)   /* Normalizes t->tm_mday and t->tm_mon. */   {
pike.git/src/builtin_functions.c:5868:    else    return 0;    });    }       CHECKED_ADD (current_ts, displacement, return 0);       *result = current_ts;    return 1;   } - #endif /* HAVE_GMTIME || HAVE_LOCALTIME */ +     - #if defined (HAVE_MKTIME) || defined (HAVE_LOCALTIME) +    /*! @decl int mktime(mapping(string:int) tm)    *! @decl int mktime(int sec, int min, int hour, int mday, int mon, int year, @    *! int|void isdst, int|void tz)    *!    *! This function converts information about date and time into an integer    *! which contains the number of seconds since 00:00:00 UTC, Jan 1, 1970.    *!    *! You can either call this function with a mapping containing the    *! following elements:    *! @mapping
pike.git/src/builtin_functions.c:5957: Inside #if defined (HAVE_MKTIME) || defined (HAVE_LOCALTIME)
   date.tm_sec=sec;    date.tm_min=min;    date.tm_hour=hour;    date.tm_mday=mday;    date.tm_mon=mon;    date.tm_year=year;    date.tm_isdst=isdst;       /* date.tm_zone = NULL; */    - #ifdef HAVE_GMTIME +     if((args > 7) && (SUBTYPEOF(Pike_sp[7-args]) == 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 */ +        { - #ifndef HAVE_GMTIME - #ifdef STRUCT_TM_HAS_GMTOFF -  /* BSD-style */ -  date.tm_gmtoff = 0; - #else - #ifdef STRUCT_TM_HAS___TM_GMTOFF -  /* (Old) Linux-style */ -  date.__tm_gmtoff = 0; - #else -  if((args > 7) && (SUBTYPEOF(Pike_sp[7-args]) == 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.    *    * 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) && (SUBTYPEOF(Pike_sp[7-args]) == 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) */ +     -  } -  +     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 */ +       /* Common case: both strings are 8bit. */   static int does_match_8_8( const unsigned char *s, int j, int sl,    const unsigned char *m, int i, int ml)   {    for (; i<ml; i++)    {    switch (m[i])    {    case '?':
pike.git/src/builtin_functions.c:10046:       /* FIXME: Could have a stricter type. */    ADD_EFUN("__get_first_arg_type", f___get_first_arg_type,    tFunc(tType(tCallable), tType(tMix)),    OPT_TRY_OPTIMIZE);       ADD_EFUN("__get_type_attributes", f___get_type_attributes,    tFunc(tType(tMix), tArr(tString)),    OPT_TRY_OPTIMIZE);    - #ifdef HAVE_LOCALTIME -  +    /* function(int:mapping(string:int)) */    ADD_EFUN("localtime",f_localtime,    tFunc(tInt,tMap(tStr,tInt)),OPT_EXTERNAL_DEPEND); - #endif - #ifdef HAVE_GMTIME +       /* function(int:mapping(string:int)) */    ADD_EFUN("gmtime",f_gmtime,tFunc(tInt,tMap(tStr,tInt)),OPT_TRY_OPTIMIZE); - #endif +     - #ifdef GOT_F_MKTIME -  +    /* function(int,int,int,int,int,int,int,void|int:int)|function(object|mapping:int) */    ADD_EFUN("mktime",f_mktime,    tOr(tFunc(tInt tInt tInt tInt tInt tInt    tOr(tVoid,tInt) tOr(tVoid,tInt),tInt),    tFunc(tOr(tObj,tMapping),tInt)),OPT_TRY_OPTIMIZE); - #endif +       /* function(:void) */    ADD_EFUN("_verify_internals",f__verify_internals,    tFunc(tNone,tVoid),OPT_SIDE_EFFECT|OPT_EXTERNAL_DEPEND);      #ifdef PIKE_DEBUG      /* function(int:int) */    ADD_EFUN("_debug",f__debug,    tFunc(tIntPos,tIntPos),OPT_SIDE_EFFECT|OPT_EXTERNAL_DEPEND);