scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit dc1a3248ccf389c94c16abf747bcd3348991c6c8
parent 042d494b739bd603589b7a2ff80010610834d7c5
Author: Naveen Narayanan <zerous@simple-cc.org>
Date:   Mon, 28 Sep 2020 18:26:08 +0200

libc: Set tm_yday in mktime.c

This patch implements the correct behavior of mktime which is to
ignore the original value of tm_yday and set it appropriately post
normalization.

Diffstat:
Msrc/libc/time/mktime.c | 7++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/libc/time/mktime.c b/src/libc/time/mktime.c @@ -32,7 +32,7 @@ norm(int *val, int *next, int qty) static int normalize(struct tm *tm) { - int mon, day, year; + int mon, day, year, yday; struct tm aux = *tm; if (!norm(&tm->tm_sec, &tm->tm_min, 60) || @@ -43,6 +43,7 @@ normalize(struct tm *tm) } day = tm->tm_mday; + yday = 0; year = 1900 + tm->tm_year; _daysmon[FEB] = FEBDAYS(year); @@ -68,9 +69,13 @@ normalize(struct tm *tm) } } + for (int i = 0; i < mon; i++) + yday += _daysmon[i]; + tm->tm_mon = mon; tm->tm_year = year - 1900; tm->tm_mday = day; + tm->tm_yday = yday + day - 1; tm->tm_wday = (_newyear(tm->tm_year) + tm->tm_yday) % 7; return 1;