diff --git a/src/irmc.c b/src/irmc.c index 80aa56b..1dc81e7 100644 --- a/src/irmc.c +++ b/src/irmc.c @@ -15,14 +15,6 @@ #include #include #include -#include -#include -#include - -#ifdef __MACH__ - #include - #include -#endif //#define DEBUG 1 @@ -30,6 +22,7 @@ #include "cwprotocol.h" #include "beep.h" +#include "util.h" int serial_status = 0, fd_serial, numbytes; @@ -53,21 +46,6 @@ char last_sender[16]; int translate = 1; int audio_status = 1; -/* portable time, as listed in https://gist.github.com/jbenet/1087739 */ -void current_utc_time(struct timespec *ts) { -#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time - clock_serv_t cclock; - mach_timespec_t mts; - host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); - clock_get_time(cclock, &mts); - mach_port_deallocate(mach_task_self(), cclock); - ts->tv_sec = mts.tv_sec; - ts->tv_nsec = mts.tv_nsec; -#else - clock_gettime(CLOCK_REALTIME, ts); -#endif -} - /* a better clock() in milliseconds */ long fastclock(void) { diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..6ce9d94 --- /dev/null +++ b/src/util.c @@ -0,0 +1,19 @@ + +#include "util.h" + +/* portable time, as listed in https://gist.github.com/jbenet/1087739 */ +void current_utc_time(struct timespec *ts) { +#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time + clock_serv_t cclock; + mach_timespec_t mts; + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + ts->tv_sec = mts.tv_sec; + ts->tv_nsec = mts.tv_nsec; +#else + clock_gettime(CLOCK_REALTIME, ts); +#endif +} + + diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..ad3d467 --- /dev/null +++ b/src/util.h @@ -0,0 +1,12 @@ +#include +#include + + +#ifdef __MACH__ + #include + #include +#endif + + +void current_utc_time(struct timespec *ts); +