Ticket #1014: 0001-Use-sane-default-time-struct-for-string-time-1014.patch

File 0001-Use-sane-default-time-struct-for-string-time-1014.patch, 1.7 KB (added by Jim Ursetto, 9 years ago)
  • posixunix.scm

    From 5e4e15d9d82c58869fb5d0633d51157331aa2fce Mon Sep 17 00:00:00 2001
    From: Jim Ursetto <zbigniewsz@gmail.com>
    Date: Fri, 24 May 2013 19:56:36 -0500
    Subject: [PATCH] Use sane default time struct for string->time (#1014)
    
    Ensure struct tm* C_tm is initialized to default
    of 1900/1/1 00:00:00 so that successive calls to
    strptime do not return old data.
    
    Also ensure day of week and day of year are set
    correctly by calling mktime [note: some libraries
    such as glibc do this automatically in strptime].
    ---
     posixunix.scm |   12 +++++++++++-
     1 files changed, 11 insertions(+), 1 deletions(-)
    
    diff --git a/posixunix.scm b/posixunix.scm
    index a2776da..534458b 100644
    a b static time_t C_timegm(struct tm *t) 
    327327#define C_timegm timegm
    328328#endif
    329329
     330static struct tm *C_tm_init() {
     331    /* init C_tm to sane default: 1900/01/01 00:00:00 */
     332    memset(&C_tm, 0, sizeof(C_tm));
     333    C_tm.tm_mday = 1;
     334    C_tm.tm_isdst = -1;
     335    return &C_tm;
     336}
     337
    330338#define cpy_tmvec_to_tmstc08(ptm, v) \
    331339    (memset((ptm), 0, sizeof(struct tm)), \
    332340    (ptm)->tm_sec = C_unfix(C_block_item((v), 0)), \
    C_tm_set( C_word v ) 
    374382static C_word
    375383C_tm_get( C_word v )
    376384{
     385  mktime(&C_tm);
    377386  C_tm_get_08( v );
    378387  return v;
    379388}
    C_tm_set( C_word v ) 
    391400static C_word
    392401C_tm_get( C_word v )
    393402{
     403  mktime(&C_tm);
    394404  C_tm_get_08( v );
    395405  C_tm_get_9( v );
    396406  return v;
    extern pid_t getpgid(pid_t pid); 
    412422#endif
    413423
    414424#define C_strptime(s, f, v) \
    415         (strptime(C_c_string(s), C_c_string(f), &C_tm) ? C_tm_get(v) : C_SCHEME_FALSE)
     425        (strptime(C_c_string(s), C_c_string(f), C_tm_init()) ? C_tm_get(v) : C_SCHEME_FALSE)
    416426
    417427static gid_t *C_groups = NULL;
    418428