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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [misc/] [time/] [adjtime.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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