MCPcopy Create free account
hub / github.com/F-Stack/f-stack / timespec2fattime

Function timespec2fattime

freebsd/kern/subr_fattime.c:138–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136};
137
138void
139timespec2fattime(const struct timespec *tsp, int utc, uint16_t *ddp,
140 uint16_t *dtp, uint8_t *dhp)
141{
142 time_t t1;
143 unsigned t2, l, m;
144
145 t1 = tsp->tv_sec;
146 if (!utc)
147 t1 -= utc_offset();
148
149 if (dhp != NULL)
150 *dhp = (tsp->tv_sec & 1) * 100 + tsp->tv_nsec / 10000000;
151 if (dtp != NULL) {
152 *dtp = (t1 / 2) % 30;
153 *dtp |= ((t1 / 60) % 60) << 5;
154 *dtp |= ((t1 / 3600) % 24) << 11;
155 }
156 if (ddp != NULL) {
157 t2 = t1 / DAY;
158 if (t2 < T1980) {
159 /* Impossible date, truncate to 1980-01-01 */
160 *ddp = 0x0021;
161 } else {
162 t2 -= T1980;
163
164 /*
165 * 2100 is not a leap year.
166 * XXX: a 32 bit time_t can not get us here.
167 */
168 if (t2 >= ((2100 - 1980) / 4 * LYC + FEB))
169 t2++;
170
171 /* Account for full leapyear cycles */
172 l = t2 / LYC;
173 *ddp = (l * 4) << 9;
174 t2 -= l * LYC;
175
176 /* Find approximate table entry */
177 m = t2 / 32;
178
179 /* Find correct table entry */
180 while (m < 47 && mtab[m + 1].days <= t2)
181 m++;
182
183 /* Get year + month from the table */
184 *ddp += mtab[m].coded;
185
186 /* And apply the day in the month */
187 t2 -= mtab[m].days - 1;
188 *ddp |= t2;
189 }
190 }
191}
192
193/*
194 * Table indexed by the bottom two bits of year + four bits of the month

Callers

nothing calls this directly

Calls 1

utc_offsetFunction · 0.85

Tested by

no test coverage detected