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

4.115
Last change on this file since a0e6c73 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 *  adjime() function
3 *
4 *  This method was initially added as part of porting NTP to RTEMS.
5 *  It is a BSD compatability function and now is available on
6 *  GNU/Linux.
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2007.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.com/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <time.h>
23#include <sys/time.h>
24#include <errno.h>
25
26#include <rtems/system.h>
27#include <rtems/config.h>
28#include <rtems/seterr.h>
29#include <rtems/score/tod.h>
30#include <rtems/posix/time.h>
31#include <rtems/score/thread.h>
32#include <rtems/score/timespec.h>
33
34/*
35 *  At one point there was a static variable named adjustment
36 *  used by this implementation.  I don't see any reason for it
37 *  to be here based upon the GNU/Linux documentation.
38 */
39
40int  adjtime(
41  const struct timeval *delta,
42  struct timeval *olddelta
43)
44{
45  struct timespec ts;
46  long   adjustment;
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  if ( olddelta ) {
58    olddelta->tv_sec  = 0;
59    olddelta->tv_usec = 0;
60  }
61
62  /* convert delta to microseconds */
63  adjustment  = (delta->tv_sec * TOD_MICROSECONDS_PER_SECOND);
64  adjustment += delta->tv_usec;
65
66  /* too small to account for */
67  if ( adjustment < rtems_configuration_get_microseconds_per_tick() )
68    return 0;
69
70  /*
71   * This prevents context switches while we are adjusting the TOD
72   */
73
74  _Thread_Disable_dispatch();
75
76    _TOD_Get( &ts );
77
78    ts.tv_sec  += delta->tv_sec;
79    ts.tv_nsec += delta->tv_usec * TOD_NANOSECONDS_PER_MICROSECOND;
80
81    /* if adjustment is too much positive */
82    while ( ts.tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) {
83      ts.tv_nsec -= TOD_NANOSECONDS_PER_SECOND;
84      ts.tv_sec++;
85    }
86
87    /* if adjustment is too much negative */
88    while ( ts.tv_nsec <= (-1 * TOD_NANOSECONDS_PER_SECOND) ) {
89      ts.tv_nsec += TOD_NANOSECONDS_PER_SECOND;
90      ts.tv_sec--;
91    }
92
93    _TOD_Set( &ts );
94
95  _Thread_Enable_dispatch();
96
97  /* set the user's output */
98  if ( olddelta )
99    *olddelta = *delta;
100
101  return 0;
102}
Note: See TracBrowser for help on using the repository browser.