Fix FreeBSD 11 compile via gmake gcc (#180)

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2021-06-12 19:27:29 -05:00
committed by GitHub
parent 40cce9f97c
commit 89d7af707e
3 changed files with 17 additions and 4 deletions
+4
View File
@@ -9,6 +9,10 @@
.PHONY: all .PHONY: all
all: apps all: apps
.PHONY: bsd
bsd:
$(MAKE) BACNET_PORT=bsd -C apps all
.PHONY: win32 .PHONY: win32
win32: win32:
$(MAKE) BACNET_PORT=win32 -C apps all $(MAKE) BACNET_PORT=win32 -C apps all
+3 -2
View File
@@ -51,6 +51,7 @@ bool datetime_local(BACNET_DATE *bdate,
* int tm_wday Day of week [0,6] (Sunday =0). * int tm_wday Day of week [0,6] (Sunday =0).
* int tm_yday Day of year [0,365]. * int tm_yday Day of year [0,365].
* int tm_isdst Daylight Savings flag. * int tm_isdst Daylight Savings flag.
* long tm_gmtoff offset from UTC in seconds
*/ */
datetime_set_date(bdate, (uint16_t)tblock->tm_year + 1900, datetime_set_date(bdate, (uint16_t)tblock->tm_year + 1900,
(uint8_t)tblock->tm_mon + 1, (uint8_t)tblock->tm_mday); (uint8_t)tblock->tm_mon + 1, (uint8_t)tblock->tm_mday);
@@ -70,10 +71,10 @@ bool datetime_local(BACNET_DATE *bdate,
} }
/* note: timezone is declared in <time.h> stdlib. */ /* note: timezone is declared in <time.h> stdlib. */
if (utc_offset_minutes) { if (utc_offset_minutes) {
/* timezone is set to the difference, in seconds, /* tm_gmtoff is set to the difference, in seconds,
between Coordinated Universal Time (UTC) and between Coordinated Universal Time (UTC) and
local standard time */ local standard time */
*utc_offset_minutes = timezone / 60; *utc_offset_minutes = tblock->tm_gmtoff / 60;
} }
} }
+10 -2
View File
@@ -28,9 +28,10 @@
#include <stdint.h> #include <stdint.h>
#include <time.h> #include <time.h>
#include "bacnet/basic/sys/mstimer.h" #include "bacnet/basic/sys/mstimer.h"
#ifdef __MACH__
#include <mach/clock.h> #include <mach/clock.h>
#include <mach/mach.h> #include <mach/mach.h>
#endif
/** @file bsd/timer.c Provides BSD-specific time and timer functions. */ /** @file bsd/timer.c Provides BSD-specific time and timer functions. */
/* counter for the various timers */ /* counter for the various timers */
@@ -45,6 +46,7 @@ unsigned long timeGetTime(void)
struct timespec now; struct timespec now;
unsigned long ticks; unsigned long ticks;
#ifdef __MACH__
clock_serv_t cclock; clock_serv_t cclock;
mach_timespec_t mts; mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
@@ -52,7 +54,9 @@ unsigned long timeGetTime(void)
mach_port_deallocate(mach_task_self(), cclock); mach_port_deallocate(mach_task_self(), cclock);
now.tv_sec = mts.tv_sec; now.tv_sec = mts.tv_sec;
now.tv_nsec = mts.tv_nsec; now.tv_nsec = mts.tv_nsec;
#else
clock_gettime(CLOCK_MONOTONIC, &now);
#endif
ticks = (now.tv_sec - start.tv_sec) * 1000 + ticks = (now.tv_sec - start.tv_sec) * 1000 +
(now.tv_nsec - start.tv_nsec) / 1000000; (now.tv_nsec - start.tv_nsec) / 1000000;
@@ -82,6 +86,7 @@ unsigned long mstimer_now(void)
*/ */
void timer_init(void) void timer_init(void)
{ {
#ifdef __MACH__
clock_serv_t cclock; clock_serv_t cclock;
mach_timespec_t mts; mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
@@ -89,4 +94,7 @@ void timer_init(void)
mach_port_deallocate(mach_task_self(), cclock); mach_port_deallocate(mach_task_self(), cclock);
start.tv_sec = mts.tv_sec; start.tv_sec = mts.tv_sec;
start.tv_nsec = mts.tv_nsec; start.tv_nsec = mts.tv_nsec;
#else
clock_gettime(CLOCK_MONOTONIC, &start);
#endif
} }