timer_settime.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Copyright (C) 2003 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public License as
  6. published by the Free Software Foundation; either version 2.1 of the
  7. License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; see the file COPYING.LIB. If
  14. not, see <http://www.gnu.org/licenses/>. */
  15. #include <errno.h>
  16. #include <stdlib.h>
  17. #include <time.h>
  18. #include <sysdep.h>
  19. #include <bits/kernel-features.h>
  20. #include "kernel-posix-timers.h"
  21. #if defined(__UCLIBC_USE_TIME64__)
  22. #include "internal/time64_helpers.h"
  23. #endif
  24. #ifdef __NR_timer_settime
  25. # ifndef __ASSUME_POSIX_TIMERS
  26. static int compat_timer_settime (timer_t timerid, int flags,
  27. const struct itimerspec *value,
  28. struct itimerspec *ovalue);
  29. # define timer_settime static compat_timer_settime
  30. # include <nptl/sysdeps/pthread/timer_settime.c>
  31. # undef timer_settime
  32. # endif
  33. # ifdef timer_settime_alias
  34. # define timer_settime timer_settime_alias
  35. # endif
  36. int
  37. timer_settime (
  38. timer_t timerid,
  39. int flags,
  40. const struct itimerspec *value,
  41. struct itimerspec *ovalue)
  42. {
  43. # undef timer_settime
  44. # ifndef __ASSUME_POSIX_TIMERS
  45. if (__no_posix_timers >= 0)
  46. # endif
  47. {
  48. struct timer *kt = (struct timer *) timerid;
  49. /* Delete the kernel timer object. */
  50. # if defined(__UCLIBC_USE_TIME64__) && defined(__NR_timer_settime64)
  51. int res = INLINE_SYSCALL (timer_settime64, 4, kt->ktimerid, flags,
  52. TO_ITS64_P(value), ovalue);
  53. # else
  54. int res = INLINE_SYSCALL (timer_settime, 4, kt->ktimerid, flags,
  55. value, ovalue);
  56. # endif
  57. # ifndef __ASSUME_POSIX_TIMERS
  58. if (res != -1 || errno != ENOSYS)
  59. {
  60. /* We know the syscall support is available. */
  61. __no_posix_timers = 1;
  62. # endif
  63. return res;
  64. # ifndef __ASSUME_POSIX_TIMERS
  65. }
  66. # endif
  67. # ifndef __ASSUME_POSIX_TIMERS
  68. __no_posix_timers = -1;
  69. # endif
  70. }
  71. # ifndef __ASSUME_POSIX_TIMERS
  72. return compat_timer_settime (timerid, flags, value, ovalue);
  73. # endif
  74. }
  75. #else
  76. # ifdef timer_settime_alias
  77. # define timer_settime timer_settime_alias
  78. # endif
  79. /* The new system calls are not available. Use the userlevel
  80. implementation. */
  81. # include <nptl/sysdeps/pthread/timer_settime.c>
  82. #endif