Commit a557a8ee authored by Christoffer Ackelman's avatar Christoffer Ackelman

Moved clock_gettime() for MacOS to co_time.

parent 118aff70
......@@ -39,6 +39,9 @@
localtime_r must be used, which doesn't exist on DEC. */
#include <ctype.h>
#ifdef OS_MACOS
#include <errno.h>
#endif
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
......@@ -73,6 +76,33 @@
static const char* monStr[] = { "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL",
"AUG", "SEP", "OCT", "NOV", "DEC" };
#ifdef OS_MACOS
int clock_gettime(clockid_t clockid, struct timespec* pt)
{
if (clockid == CLOCK_REALTIME) {
struct timeval tv;
gettimeofday(&tv, 0);
pt->tv_sec = tv.tv_sec;
pt->tv_nsec = tv.tv_usec * 1000;
} else if (clockid == CLOCK_MONOTONIC) {
// TODO
struct timeval tv;
gettimeofday(&tv, 0);
pt->tv_sec = tv.tv_sec;
pt->tv_nsec = tv.tv_usec * 1000;
} else {
errno = EINVAL;
return -1;
}
return 0;
}
#endif
static pwr_tStatus validateTm(struct tm* tms);
/* Validate data in struct tm. */
......
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* co_clock.c -- .
*/
#ifndef OS_FREEBSD
#error This file is only for FreeBSD
#endif
#include <errno.h>
#include "co_time.h"
#include "co_time_msg.h"
int clock_gettime(clockid_t clockid, struct timespec* pt)
{
if (clockid == CLOCK_REALTIME) {
struct timeval tv;
gettimeofday(&tv, 0);
pt->tv_sec = tv.tv_sec;
pt->tv_nsec = tv.tv_usec * 1000;
} else if (clockid == CLOCK_MONOTONIC) {
// TODO
struct timeval tv;
gettimeofday(&tv, 0);
pt->tv_sec = tv.tv_sec;
pt->tv_nsec = tv.tv_usec * 1000;
} else {
errno = EINVAL;
return -1;
}
return 0;
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* co_clock.c -- .
*/
#ifndef OS_MACOS
#error This file is only for Mac OS
#endif
#include <errno.h>
#include "co_time.h"
#include "co_time_msg.h"
int clock_gettime(clockid_t clockid, struct timespec* pt)
{
if (clockid == CLOCK_REALTIME) {
struct timeval tv;
gettimeofday(&tv, 0);
pt->tv_sec = tv.tv_sec;
pt->tv_nsec = tv.tv_usec * 1000;
} else if (clockid == CLOCK_MONOTONIC) {
// TODO
struct timeval tv;
gettimeofday(&tv, 0);
pt->tv_sec = tv.tv_sec;
pt->tv_nsec = tv.tv_usec * 1000;
} else {
errno = EINVAL;
return -1;
}
return 0;
}
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2018 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
/* co_clock.c -- .
*/
#ifndef OS_OPENBSD
#error This file is only for OpenBSD
#endif
#include <errno.h>
#include "co_time.h"
#include "co_time_msg.h"
int clock_gettime(clockid_t clockid, struct timespec* pt)
{
if (clockid == CLOCK_REALTIME) {
struct timeval tv;
gettimeofday(&tv, 0);
pt->tv_sec = tv.tv_sec;
pt->tv_nsec = tv.tv_usec * 1000;
} else if (clockid == CLOCK_MONOTONIC) {
// TODO
struct timeval tv;
gettimeofday(&tv, 0);
pt->tv_sec = tv.tv_sec;
pt->tv_nsec = tv.tv_usec * 1000;
} else {
errno = EINVAL;
return -1;
}
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment