2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 2001, 2012 Oracle and/or its affiliates. All rights reserved.
13 static void __os_windows_ct_numb __P((char *, int));
17 * Format a time-stamp.
20 __os_ctime(tod, time_buf)
26 struct _FILETIME file_tod, file_loc;
27 struct _SYSTEMTIME sys_loc;
28 static const __int64 SECS_BETWEEN_EPOCHS = 11644473600;
29 static const __int64 SECS_TO_100NS = 10000000; /* 10^7 */
31 strcpy(time_buf, "Thu Jan 01 00:00:00 1970");
32 time_buf[CTIME_BUFLEN - 1] = '\0';
34 /* Convert the tod to a SYSTEM_TIME struct */
36 i64_tod = (i64_tod + SECS_BETWEEN_EPOCHS)*SECS_TO_100NS;
37 memcpy(&file_tod, &i64_tod, sizeof(file_tod));
38 FileTimeToLocalFileTime(&file_tod, &file_loc);
39 FileTimeToSystemTime(&file_loc, &sys_loc);
42 * Convert the _SYSTEMTIME to the correct format in time_buf.
43 * Based closely on the os_brew/ctime.c implementation.
45 * wWeekDay : Day of the week 0-6 (0=Monday, 6=Sunday)
47 ncp = &"MonTueWedThuFriSatSun"[sys_loc.wDayOfWeek*3];
51 ncp = &"JanFebMarAprMayJunJulAugSepOctNovDec"[(sys_loc.wMonth - 1) * 3];
56 __os_windows_ct_numb(time_buf + 8, sys_loc.wDay);
57 /* Add 100 to keep the leading zero. */
58 __os_windows_ct_numb(time_buf + 11, sys_loc.wHour + 100);
59 __os_windows_ct_numb(time_buf + 14, sys_loc.wMinute + 100);
60 __os_windows_ct_numb(time_buf + 17, sys_loc.wSecond + 100);
62 if (sys_loc.wYear < 100) { /* 9 99 */
65 __os_windows_ct_numb(time_buf + 22, sys_loc.wYear);
66 } else { /* 99 1999 */
67 __os_windows_ct_numb(time_buf + 20, sys_loc.wYear / 100);
68 __os_windows_ct_numb(time_buf + 22, sys_loc.wYear % 100 + 100);
75 * __os_windows_ct_numb --
76 * Append ASCII representations for two digits to a string.
79 __os_windows_ct_numb(cp, n)
85 cp[0] = (n / 10) % 10 + '0';