diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2009-10-16 09:36:09 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2009-10-16 09:36:09 +0000 |
commit | f6d16c6fd8ab5d57df740a5eff90dbfd4bbe9ccf (patch) | |
tree | 05cf42a3c56e9976e39198c2b6b0239188165dc6 /libsylph | |
parent | 441fdff85f0b2887e2e7206101822da822193b3c (diff) |
made tzoffset related functions thread-safe.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@2287 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'libsylph')
-rw-r--r-- | libsylph/utils.c | 19 | ||||
-rw-r--r-- | libsylph/utils.h | 2 |
2 files changed, 15 insertions, 6 deletions
diff --git a/libsylph/utils.c b/libsylph/utils.c index b675c4fe..f2b2481b 100644 --- a/libsylph/utils.c +++ b/libsylph/utils.c @@ -4139,10 +4139,9 @@ time_t tzoffset_sec(time_t *now) return off * 60; } -/* calculate timezone offset */ -gchar *tzoffset(time_t *now) +/* calculate timezone offset (buf must not be less than 6 bytes) */ +gchar *tzoffset_buf(gchar *buf, time_t *now) { - static gchar offset_string[6]; struct tm gmt, *tmp, *lt; gint off; gchar sign = '+'; @@ -4172,9 +4171,16 @@ gchar *tzoffset(time_t *now) if (off >= 24 * 60) /* should be impossible */ off = 23 * 60 + 59; /* if not, insert silly value */ - sprintf(offset_string, "%c%02d%02d", sign, off / 60, off % 60); + g_snprintf(buf, 6, "%c%02d%02d", sign, off / 60, off % 60); + + return buf; +} + +gchar *tzoffset(time_t *now) +{ + static gchar offset_string[6]; - return offset_string; + return tzoffset_buf(offset_string, now); } void get_rfc822_date(gchar *buf, gint len) @@ -4183,6 +4189,7 @@ void get_rfc822_date(gchar *buf, gint len) time_t t; gchar day[4], mon[4]; gint dd, hh, mm, ss, yyyy; + gchar off[6]; t = time(NULL); lt = localtime(&t); @@ -4190,7 +4197,7 @@ void get_rfc822_date(gchar *buf, gint len) sscanf(asctime(lt), "%3s %3s %d %d:%d:%d %d\n", day, mon, &dd, &hh, &mm, &ss, &yyyy); g_snprintf(buf, len, "%s, %d %s %d %02d:%02d:%02d %s", - day, dd, mon, yyyy, hh, mm, ss, tzoffset(&t)); + day, dd, mon, yyyy, hh, mm, ss, tzoffset_buf(off, &t)); } /* just a wrapper to suppress the warning of gcc about %c */ diff --git a/libsylph/utils.h b/libsylph/utils.h index aca5351e..c43f690f 100644 --- a/libsylph/utils.h +++ b/libsylph/utils.h @@ -485,6 +485,8 @@ gint open_uri(const gchar *uri, const gchar *cmdline); /* time functions */ time_t remote_tzoffset_sec (const gchar *zone); time_t tzoffset_sec (time_t *now); +gchar *tzoffset_buf (gchar *buf, + time_t *now); gchar *tzoffset (time_t *now); void get_rfc822_date (gchar *buf, gint len); |