(root)/
glibc-2.38/
sysdeps/
unix/
sysv/
linux/
clock_adjtime.c
       1  /* clock_adjtime -- tune kernel clock.
       2     Copyright (C) 2020-2023 Free Software Foundation, Inc.
       3     This file is part of the GNU C Library.
       4  
       5     The GNU C Library is free software; you can redistribute it and/or
       6     modify it under the terms of the GNU Lesser General Public License as
       7     published by the Free Software Foundation; either version 2.1 of the
       8     License, or (at your option) any later version.
       9  
      10     The GNU C Library is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13     Lesser General Public License for more details.
      14  
      15     You should have received a copy of the GNU Lesser General Public
      16     License along with the GNU C Library; see the file COPYING.LIB.  If
      17     not, see <https://www.gnu.org/licenses/>.  */
      18  
      19  #include <errno.h>
      20  #include <stdlib.h>
      21  #include <time.h>
      22  #include <sysdep.h>
      23  #include <sys/timex.h>
      24  #include <kernel-features.h>
      25  
      26  int
      27  __clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64)
      28  {
      29  #ifndef __NR_clock_adjtime64
      30  # define __NR_clock_adjtime64 __NR_clock_adjtime
      31  #endif
      32    int r = INLINE_SYSCALL_CALL (clock_adjtime64, clock_id, tx64);
      33  #ifndef __ASSUME_TIME64_SYSCALLS
      34    if (r >= 0 || errno != ENOSYS)
      35      return r;
      36  
      37    if (tx64->modes & ADJ_SETOFFSET
      38        && ! in_int32_t_range (tx64->time.tv_sec))
      39      {
      40        __set_errno (EOVERFLOW);
      41        return -1;
      42      }
      43  
      44    struct timex tx32 = valid_timex64_to_timex (*tx64);
      45    r = INLINE_SYSCALL_CALL (clock_adjtime, clock_id, &tx32);
      46    if (r >= 0)
      47      *tx64 = valid_timex_to_timex64 (tx32);
      48  #endif
      49    return r;
      50  }
      51  
      52  #if __TIMESIZE != 64
      53  libc_hidden_def (__clock_adjtime64)
      54  
      55  int
      56  __clock_adjtime (const clockid_t clock_id, struct timex *tx)
      57  {
      58    struct __timex64 tx64;
      59    int retval;
      60  
      61    tx64 = valid_timex_to_timex64 (*tx);
      62    retval = __clock_adjtime64 (clock_id, &tx64);
      63    if (retval >= 0)
      64      *tx = valid_timex64_to_timex (tx64);
      65  
      66    return retval;
      67  }
      68  #endif
      69  libc_hidden_def (__clock_adjtime);
      70  strong_alias (__clock_adjtime, clock_adjtime)