|
Message-ID: <20131205051809.GY1685@port70.net> Date: Thu, 5 Dec 2013 06:18:09 +0100 From: Szabolcs Nagy <nsz@...t70.net> To: musl@...ts.openwall.com Subject: Re: [PATCHv2] Add support for leap seconds in zoneinfo files * Laurent Bercot <ska-dietlibc@...rnet.org> [2013-12-05 01:13:30 +0000]: > > +static int leapsecs_sub(long long *t) > +{ > + long long trans; > + int corr; > + unsigned int i = __leapsecs_num; > + int hit = 0; > + for (; i; i--) { > + __leapsecs_read(i-1, &trans, &corr); > + if (*t >= trans) break; > + } > + if (i) { > + if (*t == trans) hit = 1; > + *t -= corr; > + } > + return hit; > +} > > +static void leapsecs_add(long long *t, int hit) > +{ > + int oldcorr = 0; > + unsigned int i = 0; > + for (; i < __leapsecs_num; i++) { > + long long trans; > + int newcorr; > + __leapsecs_read(i, &trans, &newcorr); > + if (*t < trans) break; > + if (!hit || (*t > trans)) { > + *t += newcorr - oldcorr; > + } > + oldcorr = newcorr; > + } > +} > + i assume hit=leapsecs_sub(&t); if(hit) t++; leapsecs_add(&t,hit); should give back the original t, then the add part can go backwards on the leapsec list instead of forward: static void leapsecs_add(long long *t, int hit) { long long trans; int corr; unsigned int i = __leapsecs_num; for (; i; i--) { __leapsecs_read(i-1, &trans, &corr); if (*t+corr > trans) { *t += corr; // only consider hit at a leapsecond if (hit && *t == trans+1) *t--; break; } } }
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.