* time.c (localtime_with_gmtoff): fixed cross function jump.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23254 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-04-22 00:27:33 +00:00
parent a69b87e80e
commit d5704eb61a
3 changed files with 22 additions and 14 deletions

View File

@ -1,3 +1,7 @@
Wed Apr 22 09:27:31 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* time.c (localtime_with_gmtoff): fixed cross function jump.
Wed Apr 22 03:06:56 2009 Tanaka Akira <akr@fsij.org> Wed Apr 22 03:06:56 2009 Tanaka Akira <akr@fsij.org>
* lib/time.rb (Time#rfc2822): pad leading zeros for year. * lib/time.rb (Time#rfc2822): pad leading zeros for year.

View File

@ -202,7 +202,7 @@ rb_strftime(char *s, size_t maxsize, const char *format, const struct vtm *vtm,
static short first = 1; static short first = 1;
#ifdef POSIX_SEMANTICS #ifdef POSIX_SEMANTICS
static char *savetz = NULL; static char *savetz = NULL;
static int savetzlen = 0; static size_t savetzlen = 0;
char *tz; char *tz;
#endif /* POSIX_SEMANTICS */ #endif /* POSIX_SEMANTICS */
#ifndef HAVE_TM_ZONE #ifndef HAVE_TM_ZONE
@ -250,7 +250,7 @@ rb_strftime(char *s, size_t maxsize, const char *format, const struct vtm *vtm,
tz = getenv("TZ"); tz = getenv("TZ");
if (first) { if (first) {
if (tz != NULL) { if (tz != NULL) {
int tzlen = strlen(tz); size_t tzlen = strlen(tz);
savetz = (char *) malloc(tzlen + 1); savetz = (char *) malloc(tzlen + 1);
if (savetz != NULL) { if (savetz != NULL) {
@ -263,7 +263,7 @@ rb_strftime(char *s, size_t maxsize, const char *format, const struct vtm *vtm,
} }
/* if we have a saved TZ, and it is different, recapture and reset */ /* if we have a saved TZ, and it is different, recapture and reset */
if (tz && savetz && (tz[0] != savetz[0] || strcmp(tz, savetz) != 0)) { if (tz && savetz && (tz[0] != savetz[0] || strcmp(tz, savetz) != 0)) {
i = strlen(tz) + 1; size_t i = strlen(tz) + 1;
if (i > savetzlen) { if (i > savetzlen) {
savetz = (char *) realloc(savetz, i); savetz = (char *) realloc(savetz, i);
if (savetz) { if (savetz) {
@ -892,7 +892,7 @@ vtm2tm_noyear(const struct vtm *vtm, struct tm *result)
tm.tm_gmtoff = NUM2LONG(vtm->utc_offset); tm.tm_gmtoff = NUM2LONG(vtm->utc_offset);
#endif #endif
#if defined(HAVE_TM_ZONE) #if defined(HAVE_TM_ZONE)
tm.tm_zone = vtm->zone; tm.tm_zone = (char *)vtm->zone;
#endif #endif
*result = tm; *result = tm;
} }

20
time.c
View File

@ -27,6 +27,13 @@
#ifndef TYPEOF_TIMEVAL_TV_SEC #ifndef TYPEOF_TIMEVAL_TV_SEC
# define TYPEOF_TIMEVAL_TV_SEC time_t # define TYPEOF_TIMEVAL_TV_SEC time_t
#endif #endif
#ifndef TYPEOF_TIMEVAL_TV_USEC
# if INT_MAX >= 1000000
# define TYPEOF_TIMEVAL_TV_USEC int
# else
# define TYPEOF_TIMEVAL_TV_USEC long
# endif
#endif
#if SIZEOF_TIME_T == SIZEOF_LONG #if SIZEOF_TIME_T == SIZEOF_LONG
typedef unsigned long unsigned_time_t; typedef unsigned long unsigned_time_t;
@ -503,7 +510,7 @@ gmtime_with_leapsecond(const time_t *timep, struct tm *result)
result->tm_isdst = 0; result->tm_isdst = 0;
result->tm_gmtoff = 0; result->tm_gmtoff = 0;
#if defined(HAVE_TM_ZONE) #if defined(HAVE_TM_ZONE)
result->tm_zone = "UTC"; result->tm_zone = (char *)"UTC";
#endif #endif
return result; return result;
#else #else
@ -903,9 +910,9 @@ localtime_with_gmtoff(const time_t *t, struct tm *result, long *gmtoff)
long off; long off;
IF_HAVE_GMTIME_R(struct tm tmbuf); IF_HAVE_GMTIME_R(struct tm tmbuf);
l = &tm; l = &tm;
u = GMTIME(&t, tmbuf); u = GMTIME(t, tmbuf);
if (!u) if (!u)
goto no_localtime; return NULL;
if (l->tm_year != u->tm_year) if (l->tm_year != u->tm_year)
off = l->tm_year < u->tm_year ? -1 : 1; off = l->tm_year < u->tm_year ? -1 : 1;
else if (l->tm_mon != u->tm_mon) else if (l->tm_mon != u->tm_mon)
@ -966,9 +973,6 @@ localtimev(VALUE timev, struct vtm *result)
return result; return result;
} }
} }
#if !defined(HAVE_STRUCT_TM_TM_GMTOFF)
no_localtime:
#endif
if (!gmtimev(timev, result)) if (!gmtimev(timev, result))
return NULL; return NULL;
@ -1256,7 +1260,7 @@ time_timeval(VALUE num, int interval)
ts = time_timespec(num, interval); ts = time_timespec(num, interval);
tv.tv_sec = (TYPEOF_TIMEVAL_TV_SEC)ts.tv_sec; tv.tv_sec = (TYPEOF_TIMEVAL_TV_SEC)ts.tv_sec;
tv.tv_usec = ts.tv_nsec / 1000; tv.tv_usec = (TYPEOF_TIMEVAL_TV_USEC)(ts.tv_nsec / 1000);
return tv; return tv;
} }
@ -1278,7 +1282,7 @@ rb_time_timeval(VALUE time)
GetTimeval(time, tobj); GetTimeval(time, tobj);
ts = timev2timespec(tobj->timev); ts = timev2timespec(tobj->timev);
t.tv_sec = (TYPEOF_TIMEVAL_TV_SEC)ts.tv_sec; t.tv_sec = (TYPEOF_TIMEVAL_TV_SEC)ts.tv_sec;
t.tv_usec = ts.tv_nsec / 1000; t.tv_usec = (TYPEOF_TIMEVAL_TV_USEC)(ts.tv_nsec / 1000);
return t; return t;
} }
return time_timeval(time, Qfalse); return time_timeval(time, Qfalse);