OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uC-libc/] [sysdeps/] [adjtime.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
#include <syscall.h>
2
#include <sys/time.h>
3
#include <errno.h>
4
#include <limits.h>
5
#include <linux/timex.h>
6
 
7
#ifdef __SVR4_I386_ABI_L1__
8
#define adjtimex __adjtimex
9
#else
10
inline static
11
_syscall1(int, adjtimex, struct timex *, ntx);
12
#endif
13
 
14
#define MAX_SEC (LONG_MAX / 1000000L - 2)
15
#define MIN_SEC (LONG_MIN / 1000000L + 2)
16
 
17
#ifndef MOD_OFFSET
18
#define modes mode
19
#endif
20
 
21
int
22
adjtime(struct timeval * itv, struct timeval * otv)
23
{
24
  struct timex tntx;
25
 
26
  if (itv)
27
  {
28
    struct timeval tmp;
29
 
30
    /* We will do some check here. */
31
    tmp.tv_sec = itv->tv_sec + itv->tv_usec / 1000000L;
32
    tmp.tv_usec = itv->tv_usec % 1000000L;
33
    if (tmp.tv_sec > MAX_SEC || tmp.tv_sec < MIN_SEC)
34
    {
35
        errno = EINVAL;
36
        return -1;
37
    }
38
    tntx.offset = tmp.tv_usec + tmp.tv_sec * 1000000L;
39
    tntx.modes = ADJ_OFFSET_SINGLESHOT;
40
  }
41
  else
42
  {
43
    tntx.modes = 0;
44
  }
45
  if (adjtimex(&tntx) < 0) return -1;
46
  if (otv)
47
    if (tntx.offset < 0)
48
      {
49
        otv->tv_usec = -(-tntx.offset % 1000000);
50
        otv->tv_sec  = -(-tntx.offset / 1000000);
51
      }
52
    else
53
      {
54
        otv->tv_usec = tntx.offset % 1000000;
55
        otv->tv_sec  = tntx.offset / 1000000;
56
      }
57
  return 0;
58
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.