MCPcopy Create free account
hub / github.com/coreboot/coreboot / eventlog_print_timestamp

Function eventlog_print_timestamp

util/cbfstool/eventlog.c:52–90  ·  view source on GitHub ↗

* eventlog_print_timestamp - forms the key-value pair for event timestamp * * @entry: the smbios log entry to get the data information * * Forms the key-value description pair for the event timestamp. */

Source from the content-addressed store, hash-verified

50 * Forms the key-value description pair for the event timestamp.
51 */
52static void eventlog_print_timestamp(const struct event_header *event,
53 enum eventlog_timezone tz)
54{
55 const char *tm_format = "%y-%m-%d%t%H:%M:%S";
56 char tm_string[40];
57 struct tm *tmptr;
58 struct tm tm;
59 time_t time;
60
61 memset(&tm, 0, sizeof(tm));
62
63 /* Time is in "hexa". Convert it to decimal, and then convert it to "tm" struct */
64 snprintf(tm_string, sizeof(tm_string), "%02x-%02x-%02x %02x:%02x:%02x", event->year,
65 event->month, event->day, event->hour, event->minute, event->second);
66
67 if (strptime(tm_string, tm_format, &tm) == NULL) {
68 /* Backup in case string could not be parsed. Timezone not included */
69 eventlog_printf("%02d%02x-%02x-%02x %02x:%02x:%02x",
70 (event->year > 0x80 && event->year < 0x99) ? 19 : 20,
71 event->year, event->month, event->day, event->hour,
72 event->minute, event->second);
73 return;
74 }
75
76 /* Set DST flag to -1 to indicate "not available" and let
77 * system determine if DST is on based on date */
78 tm.tm_isdst = -1;
79
80 time = mktime(&tm);
81 time += tm.tm_gmtoff; /* force adjust for timezone */
82
83 if (tz == EVENTLOG_TIMEZONE_UTC)
84 tmptr = gmtime(&time);
85 else
86 tmptr = localtime(&time);
87 strftime(tm_string, sizeof(tm_string), "%Y-%m-%d %H:%M:%S%z", tmptr);
88
89 eventlog_printf("%s", tm_string);
90}
91
92
93/*

Callers 1

eventlog_print_eventFunction · 0.85

Calls 3

eventlog_printfFunction · 0.85
memsetFunction · 0.50
snprintfFunction · 0.50

Tested by

no test coverage detected