Skip to content

Commit

Permalink
(get/set)timeofday now using sys_clock_(get/set)time, insane-adding-m…
Browse files Browse the repository at this point in the history
  • Loading branch information
brabo committed Mar 13, 2017
1 parent e42b1f8 commit 5e40781
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
24 changes: 22 additions & 2 deletions newlib/libc/sys/frosted/gettimeofday.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,35 @@
*/

#include "sys/frosted.h"
#include "time.h"
#include <sys/_timeval.h>
#include <errno.h>
struct timeval;
struct timezone;
extern int sys_gettimeofday(struct timeval *tv);
extern int sys_clock_gettime(clockid_t clock_id, struct timespec *tp);
extern int sys_clock_settime(clockid_t clock_id, struct timespec *tp);

int gettimeofday(struct timeval *tv, struct timezone *tz)
{
(void)tz; /* Timezone not implemented in frosted. */
int ret = sys_gettimeofday(tv);
struct timespec tp;
int ret = sys_clock_gettime(CLOCK_REALTIME, &tp);
if (ret < 0) {
errno = 0 - ret;
ret = -1;
}
tv->tv_sec = tp.tv_sec;
tv->tv_usec = (tp.tv_nsec / 1000);
return ret;
}

int settimeofday(struct timeval *tv, struct timezone *tz)
{
(void)tz; /* Timezone not implemented in frosted. */
struct timespec tp;
tp.tv_sec = tv->tv_sec;
tp.tv_nsec = (tv->tv_usec * 1000);
int ret = sys_clock_settime(CLOCK_REALTIME, &tp);
if (ret < 0) {
errno = 0 - ret;
ret = -1;
Expand Down
3 changes: 2 additions & 1 deletion newlib/libc/sys/frosted/include/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ int _EXFUN(nanosleep, (const struct timespec *rqtp, struct timespec *rmtp));

/* Manifest Constants, P1003.1b-1993, p. 262 */

#define CLOCK_REALTIME (clockid_t)1
#define CLOCK_REALTIME (clockid_t)0
#define CLOCK_MONOTONIC (clockid_t)1

/* Flag indicating time is "absolute" with respect to the clock
associated with a time. */
Expand Down
19 changes: 6 additions & 13 deletions newlib/libc/sys/frosted/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

#include "sys/frosted.h"
#include "sys/time.h"
#include "time.h"
#include <errno.h>

extern int sys_sleep(int ms, uint32_t *rem);
Expand Down Expand Up @@ -57,7 +57,8 @@ int nanosleep(const struct timespec *req, struct timespec *rem)
return ret;
}

extern int sys_gettimeofday(struct timeval *tv);
extern int sys_clock_gettime(clockid_t clock_id, struct timespec *tp);
extern int sys_clock_settime(clockid_t clock_id, struct timespec *tp);

int clock_getres(clockid_t clock_id, struct timespec *res)
{
Expand All @@ -72,30 +73,22 @@ int clock_getres(clockid_t clock_id, struct timespec *res)

int clock_gettime(clockid_t clock_id, struct timespec *tp)
{
struct timeval tv;
int ret = sys_gettimeofday(&tv);
int ret = sys_clock_gettime(clock_id, tp);
if (ret < 0) {
errno = 0 - ret;
ret = -1;
}
tp->tv_sec = tv.tv_sec;
tp->tv_nsec = tv.tv_usec * 1000;
return ret;
}

extern int sys_clock_settime(struct timeval *tv);

int clock_settime(clockid_t clock_id, const struct timespec *tp)
{
struct timeval tv;
tv.tv_sec = tp->tv_sec;
tv.tv_usec = tp->tv_nsec * 1000;

int ret = sys_clock_settime(&tv);
int ret = sys_clock_settime(clock_id, tp);
if (ret < 0) {
errno = 0 - ret;
ret = -1;
}
return ret;
}


0 comments on commit 5e40781

Please sign in to comment.