comparison src/strftime.c @ 111628:9937e00afbbc

Convert definitions to standard C. * src/strftime.c (my_strftime_gmtime_r, my_strftime_localtime_r) (tm_diff): Convert definitions to standard C. (extra_args_spec_iso): Remove, unused.
author Dan Nicolaescu <dann@ics.uci.edu>
date Thu, 18 Nov 2010 08:49:30 -0800
parents a673d202fe46
children d54bb4248183
comparison
equal deleted inserted replaced
111627:f61ceeffc5da 111628:9937e00afbbc
177 /* If we're a strftime substitute in a GNU program, then prefer gmtime 177 /* If we're a strftime substitute in a GNU program, then prefer gmtime
178 to gmtime_r, since many gmtime_r implementations are buggy. 178 to gmtime_r, since many gmtime_r implementations are buggy.
179 Similarly for localtime_r. */ 179 Similarly for localtime_r. */
180 180
181 # if ! HAVE_TM_GMTOFF 181 # if ! HAVE_TM_GMTOFF
182 static struct tm *my_strftime_gmtime_r (const time_t *, struct tm *);
183 static struct tm * 182 static struct tm *
184 my_strftime_gmtime_r (t, tp) 183 my_strftime_gmtime_r (const time_t *t, struct tm *tp)
185 const time_t *t;
186 struct tm *tp;
187 { 184 {
188 struct tm *l = gmtime (t); 185 struct tm *l = gmtime (t);
189 if (! l) 186 if (! l)
190 return 0; 187 return 0;
191 *tp = *l; 188 *tp = *l;
192 return tp; 189 return tp;
193 } 190 }
194 191
195 static struct tm *my_strftime_localtime_r (const time_t *, struct tm *);
196 static struct tm * 192 static struct tm *
197 my_strftime_localtime_r (t, tp) 193 my_strftime_localtime_r (const time_t *t, struct tm *tp)
198 const time_t *t;
199 struct tm *tp;
200 { 194 {
201 struct tm *l = localtime (t); 195 struct tm *l = localtime (t);
202 if (! l) 196 if (! l)
203 return 0; 197 return 0;
204 *tp = *l; 198 *tp = *l;
378 372
379 #if ! HAVE_TM_GMTOFF 373 #if ! HAVE_TM_GMTOFF
380 /* Yield the difference between *A and *B, 374 /* Yield the difference between *A and *B,
381 measured in seconds, ignoring leap seconds. */ 375 measured in seconds, ignoring leap seconds. */
382 # define tm_diff ftime_tm_diff 376 # define tm_diff ftime_tm_diff
383 static int tm_diff (const struct tm *, const struct tm *);
384 static int 377 static int
385 tm_diff (a, b) 378 tm_diff (const struct tm *a, const struct tm *b)
386 const struct tm *a;
387 const struct tm *b;
388 { 379 {
389 /* Compute intervening leap days correctly even if year is negative. 380 /* Compute intervening leap days correctly even if year is negative.
390 Take care to avoid int overflow in leap day calculations, 381 Take care to avoid int overflow in leap day calculations,
391 but it's OK to assume that A and B are close to each other. */ 382 but it's OK to assume that A and B are close to each other. */
392 int a4 = (a->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (a->tm_year & 3); 383 int a4 = (a->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (a->tm_year & 3);
449 extra arguments UT and NS. */ 440 extra arguments UT and NS. */
450 441
451 #ifdef my_strftime 442 #ifdef my_strftime
452 # define extra_args , ut, ns 443 # define extra_args , ut, ns
453 # define extra_args_spec , int ut, int ns 444 # define extra_args_spec , int ut, int ns
454 # define extra_args_spec_iso , int ut, int ns
455 #else 445 #else
456 # ifdef COMPILE_WIDE 446 # ifdef COMPILE_WIDE
457 # define my_strftime wcsftime 447 # define my_strftime wcsftime
458 # define nl_get_alt_digit _nl_get_walt_digit 448 # define nl_get_alt_digit _nl_get_walt_digit
459 # else 449 # else
460 # define my_strftime strftime 450 # define my_strftime strftime
461 # define nl_get_alt_digit _nl_get_alt_digit 451 # define nl_get_alt_digit _nl_get_alt_digit
462 # endif 452 # endif
463 # define extra_args 453 # define extra_args
464 # define extra_args_spec 454 # define extra_args_spec
465 # define extra_args_spec_iso
466 /* We don't have this information in general. */ 455 /* We don't have this information in general. */
467 # define ut 0 456 # define ut 0
468 # define ns 0 457 # define ns 0
469 #endif 458 #endif
470 459
471 #if !defined _LIBC && !defined(WINDOWSNT) && HAVE_TZNAME && HAVE_TZSET 460 #if !defined _LIBC && !defined(WINDOWSNT) && HAVE_TZNAME && HAVE_TZSET
472 /* Solaris 2.5 tzset sometimes modifies the storage returned by localtime. 461 /* Solaris 2.5 tzset sometimes modifies the storage returned by localtime.
473 Work around this bug by copying *tp before it might be munged. */ 462 Work around this bug by copying *tp before it might be munged. */
474 size_t _strftime_copytm (char *, size_t, const char *,
475 const struct tm * extra_args_spec_iso);
476 size_t 463 size_t
477 my_strftime (s, maxsize, format, tp extra_args) 464 my_strftime (CHAR_T *s, size_t maxsize, const CHAR_T *format,
478 CHAR_T *s; 465 const struct tm *tp extra_args_spec)
479 size_t maxsize;
480 const CHAR_T *format;
481 const struct tm *tp;
482 extra_args_spec
483 { 466 {
484 struct tm tmcopy; 467 struct tm tmcopy;
485 tmcopy = *tp; 468 tmcopy = *tp;
486 return _strftime_copytm (s, maxsize, format, &tmcopy extra_args); 469 return _strftime_copytm (s, maxsize, format, &tmcopy extra_args);
487 } 470 }