summaryrefslogtreecommitdiff
path: root/cpu/sysdeps/unix/sysv/linux/i386/sys-clock_gettime.c
blob: af2a57dc22029aeb98b14076e034a9b28ea6c63e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/***************************************************************
  SYS-CLOCK_GETTIME.C

       This file contains Linux/i386/ILP32 implementation of
       __cpu_sys_clock_gettime().

       PART OF : CPU - library .

       USAGE   : Internal only .

       Copyright (C) 2026  by Andrew V.Kosteltsev.
       All Rights Reserved.
 ***************************************************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <errno.h>
#include <time.h>

#include <libmcpu.h>
#include <cpu-sysdeps.h>
#include "cpu-time-linux.h"


__mpu_int64_t
__cpu_sys_clock_gettime( __mpu_uint64_t clockid, struct __cpu_timespec *tp )
{
  struct timespec ts;
  clockid_t       host_clockid;
  int             error;

  if( !tp ) return( -(__mpu_int64_t)__MCPU_EFAULT );

  error = __cpu_clockid_to_host( clockid, &host_clockid );
  if( error ) return( -(__mpu_int64_t)error );

  if( clock_gettime( host_clockid, &ts ) < 0 )
    return( -(__mpu_int64_t)__cpu_errno_from_host( errno ) );

  error = __cpu_timespec_from_host( tp, &ts );
  if( error ) return( -(__mpu_int64_t)error );

  return( 0 );

} /* End of __cpu_sys_clock_gettime() */