Back to index

glibc  2.9
Defines | Functions
clock_settime.c File Reference
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <libc-internal.h>
#include <ldsodefs.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define HANDLE_REALTIME

Functions

int clock_settime (clockid_t clock_id, const struct timespec *tp)

Define Documentation

#define HANDLE_REALTIME
Value:
do {                                                          \
       struct timeval tv;                                            \
       TIMESPEC_TO_TIMEVAL (&tv, tp);                                       \
                                                                     \
       retval = settimeofday (&tv, NULL);                            \
      } while (0)

Function Documentation

int clock_settime ( clockid_t  clock_id,
const struct timespec tp 
)

Definition at line 76 of file clock_settime.c.

{
  int retval;

  /* Make sure the time cvalue is OK.  */
  if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000)
    {
      __set_errno (EINVAL);
      return -1;
    }

  switch (clock_id)
    {
#define HANDLE_REALTIME \
      do {                                                           \
       struct timeval tv;                                            \
       TIMESPEC_TO_TIMEVAL (&tv, tp);                                       \
                                                                     \
       retval = settimeofday (&tv, NULL);                            \
      } while (0)

#ifdef SYSDEP_SETTIME
      SYSDEP_SETTIME;
#endif

#ifndef HANDLED_REALTIME
    case CLOCK_REALTIME:
      HANDLE_REALTIME;
      break;
#endif

    default:
#ifdef SYSDEP_SETTIME_CPU
      SYSDEP_SETTIME_CPU;
#endif
#ifndef HANDLED_CPUTIME
# if HP_TIMING_AVAIL
      if (CPUCLOCK_WHICH (clock_id) == CLOCK_PROCESS_CPUTIME_ID
         || CPUCLOCK_WHICH (clock_id) == CLOCK_THREAD_CPUTIME_ID)
       retval = hp_timing_settime (clock_id, tp);
      else
# endif
       {
         __set_errno (EINVAL);
         retval = -1;
       }
#endif
      break;
    }

  return retval;
}