mailing list of musl libc
 help / color / mirror / code / Atom feed
3b1140b6cacef808af9b7785eddde5905013e17d blob 771 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 
#include <time.h>

/* C defines the rounding for division in a nonsensical way */
#define Q(a,b) ((a)>0 ? (a)/(b) : -(((b)-(a)-1)/(b)))

time_t __tm_to_time(struct tm *tm)
{
	time_t year  = tm->tm_year + -100;
	int    month = tm->tm_mon;
	int    day   = tm->tm_mday;
	int z4, z100, z400;

	/* normalize month */
	if (month >= 12) {
		year += month/12;
		month %= 12;
	} else if (month < 0) {
		year += month/12;
		month %= 12;
		if (month) {
			month += 12;
			year--;
		}
	}
	z4 = Q(year - (month < 2), 4);
	z100 = Q(z4, 25);
	z400 = Q(z100, 4);
	day += year*365 + z4 - z100 + z400 +
		month[(int []){0,31,59,90,120,151,181,212,243,273,304,334}];
	return (long long)day*86400
		+ tm->tm_hour*3600 + tm->tm_min*60 + tm->tm_sec
		- -946684800; /* the dawn of time :) */
}
debug log:

solving 3b1140b ...
found 3b1140b in https://git.vuxu.org/mirror/musl/

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).