Lines Matching +full:binary +full:- +full:coded
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2006 Poul-Henning Kamp
7 * Redistribution and use in source and binary forms, with or without
12 * 2. Redistributions in binary form must reproduce the above copyright
28 * Convert MS-DOS FAT format timestamps to and from unix timespecs
33 * yyyyyyymmmmddddd (year - 1980, month, day)
54 * The conversion functions below cut time into four-year leap-year
64 * they can represent up to 2107 which means that the non-leap-year
80 #define LYC (4 * YEAR + 1) /* Length of 4 year leap-year cycle */
98 /* Table of months in a 4 year leap-year cycle */
104 uint16_t coded; /* encoded year + month information */ member
144 t1 = tsp->tv_sec; in timespec2fattime()
146 t1 -= utc_offset(); in timespec2fattime()
149 *dhp = (tsp->tv_sec & 1) * 100 + tsp->tv_nsec / 10000000; in timespec2fattime()
158 /* Impossible date, truncate to 1980-01-01 */ in timespec2fattime()
161 t2 -= T1980; in timespec2fattime()
164 if (t2 >= ((2100 - 1980) / 4 * LYC + FEB)) in timespec2fattime()
170 t2 -= l * LYC; in timespec2fattime()
180 *ddp += mtab[m].coded; in timespec2fattime()
183 t2 -= mtab[m].days - 1; in timespec2fattime()
192 * leap-year cycle
222 tsp->tv_sec = (dt & 0x1f) << 1; in fattime2timespec()
223 tsp->tv_sec += ((dt & 0x7e0) >> 5) * 60; in fattime2timespec()
224 tsp->tv_sec += ((dt & 0xf800) >> 11) * 3600; in fattime2timespec()
225 tsp->tv_sec += dh / 100; in fattime2timespec()
226 tsp->tv_nsec = (dh % 100) * 10000000; in fattime2timespec()
229 day = (dd & 0x1f) - 1; in fattime2timespec()
231 /* Full leap-year cycles */ in fattime2timespec()
234 /* Month offset from leap-year cycle */ in fattime2timespec()
238 if (day >= ((2100 - 1980) / 4 * LYC + FEB)) in fattime2timespec()
239 day--; in fattime2timespec()
244 tsp->tv_sec += (time_t) DAY * day; in fattime2timespec()
246 tsp->tv_sec += utc_offset(); in fattime2timespec()
269 * 32-bits gets us to 2106-02-07 06:28:15, but we in main()
271 * a 36-bit second count to get us way past 2106. in main()
278 printf("%10jd.%03ld -- ", (intmax_t) ts.tv_sec, ts.tv_nsec / 1000000); in main()
282 printf("%s -- ", buf); in main()
284 a = ts.tv_sec + ts.tv_nsec * 1e-9; in main()
287 printf("%04x %04x %02x -- ", d, t, p); in main()
288 printf("%3d %02d %02d %02d %02d %02d -- ", in main()
301 printf("%s -- ", buf); in main()
302 a -= ts.tv_sec + ts.tv_nsec * 1e-9; in main()