diff options
author | Roman Shaposhnik <roman@shaposhnik.org> | 2004-08-18 08:15:07 +0000 |
---|---|---|
committer | Roman Shaposhnik <roman@shaposhnik.org> | 2004-08-18 08:15:07 +0000 |
commit | 0c9fc6e1878fb7d56f6cff0109ea546fda7710c8 (patch) | |
tree | 168ffd5abceb60a66f89f8a8f881a7a239e9cd79 /libavformat/cutils.c | |
parent | 0722ccdbc000b82b4bf52644a0e4964c64d1f537 (diff) | |
download | ffmpeg-0c9fc6e1878fb7d56f6cff0109ea546fda7710c8.tar.gz |
* replacing calls to not-always-available gmtime_r with our own code.
The new helper function actually differs in semantics from gmtime_r,
so if that seems to be a problem I can actually move it to dv.c
completely, since only DV muxer uses the code anyway.
Originally committed as revision 3399 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/cutils.c')
-rw-r--r-- | libavformat/cutils.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/libavformat/cutils.c b/libavformat/cutils.c index c31e5b5c17..1415e4e392 100644 --- a/libavformat/cutils.c +++ b/libavformat/cutils.c @@ -147,6 +147,40 @@ time_t mktimegm(struct tm *tm) return t; } +#define ISLEAP(y) (((y) % 4 == 0) && (((y) % 100) != 0 || ((y) % 400) == 0)) +#define LEAPS_COUNT(y) ((y)/4 - (y)/100 + (y)/400) + +/* this is our own gmtime_r. it differs from its POSIX counterpart in a + couple of places, though. */ +struct tm *brktimegm(time_t secs, struct tm *tm) +{ + int days, y, ny, m; + int md[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + + days = secs / 86400; + secs %= 86400; + tm->tm_hour = secs / 3600; + tm->tm_min = (secs % 3600) / 60; + tm->tm_sec = secs % 60; + + /* oh well, may be someone some day will invent a formula for this stuff */ + y = 1970; /* start "guessing" */ + while (days >= (ISLEAP(y)?366:365)) { + ny = (y + days/366); + days -= (ny - y) * 365 + LEAPS_COUNT(ny - 1) - LEAPS_COUNT(y - 1); + y = ny; + } + md[1] = ISLEAP(y)?29:28; + for (m=0; days >= md[m]; m++) + days -= md[m]; + + tm->tm_year = y; /* unlike gmtime_r we store complete year here */ + tm->tm_mon = m+1; /* unlike gmtime_r tm_mon is from 1 to 12 */ + tm->tm_mday = days+1; + + return tm; +} + /* get a positive number between n_min and n_max, for a maximum length of len_max. Return -1 if error. */ static int date_get_num(const char **pp, |