/[cvs]/ccvs/lib/mktime.c
ViewVC logotype

Diff of /ccvs/lib/mktime.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by dprice, Mon May 23 17:44:31 2005 UTC revision 1.11 by dprice, Fri Aug 12 20:58:10 2005 UTC
# Line 1  Line 1 
1  /* Convert a `struct tm' to a time_t value.  /* Convert a `struct tm' to a time_t value.
2     Copyright (C) 1993-1999, 2002, 2003, 2004, 2005 Free Software Foundation,     Copyright (C) 1993-1999, 2002-2004, 2005 Free Software Foundation, Inc.
3     Inc.     Inc.
4     This file is part of the GNU C Library.     This file is part of the GNU C Library.
5     Contributed by Paul Eggert (eggert@twinsun.com).     Contributed by Paul Eggert (eggert@twinsun.com).
# Line 38  Line 38 
38    
39  #include <limits.h>  #include <limits.h>
40    
41    #include <string.h>             /* For the real memcpy prototype.  */
42    
43  #if DEBUG  #if DEBUG
44  # include <stdio.h>  # include <stdio.h>
45  # include <stdlib.h>  # include <stdlib.h>
 # include <string.h>  
46  /* Make it work even if the system's libc has its own mktime routine.  */  /* Make it work even if the system's libc has its own mktime routine.  */
47  # define mktime my_mktime  # define mktime my_mktime
48  #endif /* DEBUG */  #endif /* DEBUG */
# Line 228  static struct tm * Line 229  static struct tm *
229  ranged_convert (struct tm *(*convert) (const time_t *, struct tm *),  ranged_convert (struct tm *(*convert) (const time_t *, struct tm *),
230                  time_t *t, struct tm *tp)                  time_t *t, struct tm *tp)
231  {  {
232    struct tm *r;    struct tm *r = convert (t, tp);
233    
234    if (! (r = (*convert) (t, tp)) && *t)    if (!r && *t)
235      {      {
236        time_t bad = *t;        time_t bad = *t;
237        time_t ok = 0;        time_t ok = 0;
       struct tm tm;  
238    
239        /* BAD is a known unconvertible time_t, and OK is a known good one.        /* BAD is a known unconvertible time_t, and OK is a known good one.
240           Use binary search to narrow the range between BAD and OK until           Use binary search to narrow the range between BAD and OK until
# Line 244  ranged_convert (struct tm *(*convert) (c Line 244  ranged_convert (struct tm *(*convert) (c
244            time_t mid = *t = (bad < 0            time_t mid = *t = (bad < 0
245                               ? bad + ((ok - bad) >> 1)                               ? bad + ((ok - bad) >> 1)
246                               : ok + ((bad - ok) >> 1));                               : ok + ((bad - ok) >> 1));
247            if ((r = (*convert) (t, tp)))            r = convert (t, tp);
248              {            if (r)
249                tm = *r;              ok = mid;
               ok = mid;  
             }  
250            else            else
251              bad = mid;              bad = mid;
252          }          }
# Line 258  ranged_convert (struct tm *(*convert) (c Line 256  ranged_convert (struct tm *(*convert) (c
256            /* The last conversion attempt failed;            /* The last conversion attempt failed;
257               revert to the most recent successful attempt.  */               revert to the most recent successful attempt.  */
258            *t = ok;            *t = ok;
259            *tp = tm;            r = convert (t, tp);
           r = tp;  
260          }          }
261      }      }
262    
# Line 488  __mktime_internal (struct tm *tp, Line 485  __mktime_internal (struct tm *tp,
485        t2 = t1 + sec_adjustment;        t2 = t1 + sec_adjustment;
486        if (((t1 < t) != (sec_requested < 0))        if (((t1 < t) != (sec_requested < 0))
487            | ((t2 < t1) != (sec_adjustment < 0))            | ((t2 < t1) != (sec_adjustment < 0))
488            | ! (*convert) (&t2, &tm))            | ! convert (&t2, &tm))
489          return -1;          return -1;
490        t = t2;        t = t2;
491      }      }

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26