source: rtems/cpukit/posix/src/clockgettime.c @ 2256946

Last change on this file since 2256946 was 2256946, checked in by Sebastian Huber <sebastian.huber@…>, on Oct 6, 2017 at 1:30:47 PM

score: Use struct timespec for TOD

Use the timestamps only for uptime based values. Use struct timespec
for the absolute time values (TOD).

Update #2740.

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/**
2 * @file
3 *
4 * @brief Retrieves the Specified Clock Time
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2007.
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#include <time.h>
22#include <errno.h>
23
24#include <rtems/score/todimpl.h>
25#include <rtems/seterr.h>
26
27/*
28 *  14.2.1 Clocks, P1003.1b-1993, p. 263
29 */
30
31int clock_gettime(
32  clockid_t        clock_id,
33  struct timespec *tp
34)
35{
36  if ( !tp )
37    rtems_set_errno_and_return_minus_one( EINVAL );
38
39  if ( clock_id == CLOCK_REALTIME ) {
40    _TOD_Get(tp);
41    return 0;
42  }
43#ifdef CLOCK_MONOTONIC
44  if ( clock_id == CLOCK_MONOTONIC ) {
45    _TOD_Get_zero_based_uptime_as_timespec( tp );
46    return 0;
47  }
48#endif
49
50#ifdef _POSIX_CPUTIME
51  if ( clock_id == CLOCK_PROCESS_CPUTIME_ID ) {
52    _TOD_Get_zero_based_uptime_as_timespec( tp );
53    return 0;
54  }
55#endif
56
57#ifdef _POSIX_THREAD_CPUTIME
58  if ( clock_id == CLOCK_THREAD_CPUTIME_ID )
59    rtems_set_errno_and_return_minus_one( ENOSYS );
60#endif
61
62  rtems_set_errno_and_return_minus_one( EINVAL );
63
64  return 0;
65}
Note: See TracBrowser for help on using the repository browser.