Branch data Line data Source code
1 : : /* SPDX-FileCopyrightText: Copyright 2026 Cozens Software Solutions Limited
2 : : * SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 OR LicenseRef-PolyForm-Internal-Use-1.0.0 OR LicenseRef-COSOSO-Commercial
3 : : */
4 : :
5 : : #include "SolidSyslogVxWorks64Clock.h"
6 : :
7 : : #include <stdbool.h>
8 : : #include <stdint.h>
9 : :
10 : : #include "vxWorks.h"
11 : :
12 : : #include <time.h>
13 : :
14 : : #include "SolidSyslogTimestamp.h"
15 : :
16 : : enum
17 : : {
18 : : TM_YEAR_BASE = 1900,
19 : : NANOSECONDS_PER_MICROSECOND = 1000
20 : : };
21 : :
22 : : static inline bool VxWorks64Clock_GetBrokenDownTime(struct timespec* now, struct tm* breakdown);
23 : : static inline void VxWorks64Clock_PopulateTimestamp(
24 : : struct SolidSyslogTimestamp* timestamp,
25 : : const struct timespec* now,
26 : : const struct tm* breakdown
27 : : );
28 : :
29 : 54 : void SolidSyslogVxWorks64_GetTimestamp(struct SolidSyslogTimestamp* timestamp)
30 : : {
31 : : struct timespec now;
32 : : struct tm breakdown;
33 : :
34 : 54 : *timestamp = (struct SolidSyslogTimestamp) {0};
35 : :
36 [ + + ]: 54 : if (VxWorks64Clock_GetBrokenDownTime(&now, &breakdown))
37 : : {
38 : 52 : VxWorks64Clock_PopulateTimestamp(timestamp, &now, &breakdown);
39 : : }
40 : 54 : }
41 : :
42 : : /* gmtime_r here answers OK or ERROR rather than a pointer. */
43 : 54 : static inline bool VxWorks64Clock_GetBrokenDownTime(struct timespec* now, struct tm* breakdown)
44 : : {
45 [ + + + + ]: 54 : return (clock_gettime(CLOCK_REALTIME, now) == OK) && (gmtime_r(&now->tv_sec, breakdown) == OK);
46 : : }
47 : :
48 : 52 : static inline void VxWorks64Clock_PopulateTimestamp(
49 : : struct SolidSyslogTimestamp* timestamp,
50 : : const struct timespec* now,
51 : : const struct tm* breakdown
52 : : )
53 : : {
54 : 52 : timestamp->Year = (uint16_t) (breakdown->tm_year + TM_YEAR_BASE);
55 : 52 : timestamp->Month = (uint8_t) (breakdown->tm_mon + 1);
56 : 52 : timestamp->Day = (uint8_t) breakdown->tm_mday;
57 : 52 : timestamp->Hour = (uint8_t) breakdown->tm_hour;
58 : 52 : timestamp->Minute = (uint8_t) breakdown->tm_min;
59 : 52 : timestamp->Second = (uint8_t) breakdown->tm_sec;
60 : 52 : timestamp->Microsecond = (uint32_t) (now->tv_nsec / NANOSECONDS_PER_MICROSECOND);
61 : 52 : }
|