source: rtems/cpukit/posix/src/adjtime.c @ dbb30e26

5
Last change on this file since dbb30e26 was ed9a6fd, checked in by Sebastian Huber <sebastian.huber@…>, on 10/11/17 at 19:33:44

posix: Use right time format in adjtime()

Update #2740.

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Adjust the Time to Synchronize the System Clock
5 *  @ingroup POSIXAPI
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2014.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#define _BSD_SOURCE
22#include <time.h>
23#include <sys/time.h>
24#include <errno.h>
25
26#include <rtems/score/timespec.h>
27#include <rtems/score/threaddispatch.h>
28#include <rtems/score/todimpl.h>
29#include <rtems/config.h>
30#include <rtems/seterr.h>
31
32/**
33 * This method was initially added as part of porting NTP to RTEMS.
34 * It is a BSD compatability function and now is available on
35 * GNU/Linux.
36 *
37 * At one point there was a static variable named adjustment
38 * used by this implementation.  I don't see any reason for it
39 * to be here based upon the GNU/Linux documentation.
40 */
41int adjtime(
42  const struct timeval *delta,
43  struct timeval       *olddelta
44)
45{
46  struct timespec delta_as_timespec;
47
48  /*
49   * Simple validations
50   */
51  if ( !delta )
52    rtems_set_errno_and_return_minus_one( EINVAL );
53
54  if ( delta->tv_usec >= TOD_MICROSECONDS_PER_SECOND )
55    rtems_set_errno_and_return_minus_one( EINVAL );
56
57  /*
58   * An adjustment of zero is pretty easy.
59   */
60  if ( delta->tv_sec == 0 && delta->tv_usec == 0 )
61    return 0;
62
63  /*
64   * Currently, RTEMS does the adjustment in one movement so there
65   * is no way an adjustment was currently underway.
66   *
67   * Given interest, requirements, and sponsorship, a future
68   * enhancement would be to adjust the time in smaller increments
69   * at each clock tick. Until then, there is no outstanding
70   * adjustment.
71   */
72  if ( olddelta ) {
73    olddelta->tv_sec  = 0;
74    olddelta->tv_usec = 0;
75  }
76
77  /*
78   * convert delta timeval to timespec
79   */
80  delta_as_timespec.tv_sec = delta->tv_sec;
81  delta_as_timespec.tv_nsec = delta->tv_usec * 1000;
82
83  /*
84   * Now apply the adjustment
85   */
86  _TOD_Adjust( &delta_as_timespec );
87
88  return 0;
89}
Note: See TracBrowser for help on using the repository browser.