timer_settime.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifdef __NR_timer_settime
  22. # ifndef __ASSUME_POSIX_TIMERS
  23. static int compat_timer_settime (timer_t timerid, int flags,
  24. const struct itimerspec *value,
  25. struct itimerspec *ovalue);
  26. # define timer_settime static compat_timer_settime
  27. # include <nptl/sysdeps/pthread/timer_settime.c>
  28. # undef timer_settime
  29. # endif
  30. # ifdef timer_settime_alias
  31. # define timer_settime timer_settime_alias
  32. # endif
  33. int
  34. timer_settime (
  35. timer_t timerid,
  36. int flags,
  37. const struct itimerspec *value,
  38. struct itimerspec *ovalue)
  39. {
  40. # undef timer_settime
  41. # ifndef __ASSUME_POSIX_TIMERS
  42. if (__no_posix_timers >= 0)
  43. # endif
  44. {
  45. struct timer *kt = (struct timer *) timerid;
  46. /* Delete the kernel timer object. */
  47. # if defined(__UCLIBC_USE_TIME64__) && defined(__NR_timer_settime64)
  48. int res = INLINE_SYSCALL (timer_settime64, 4, kt->ktimerid, flags,
  49. value, ovalue);
  50. # else
  51. int res = INLINE_SYSCALL (timer_settime, 4, kt->ktimerid, flags,
  52. value, ovalue);
  53. # endif
  54. # ifndef __ASSUME_POSIX_TIMERS
  55. if (res != -1 || errno != ENOSYS)
  56. {
  57. /* We know the syscall support is available. */
  58. __no_posix_timers = 1;
  59. # endif
  60. return res;
  61. # ifndef __ASSUME_POSIX_TIMERS
  62. }
  63. # endif
  64. # ifndef __ASSUME_POSIX_TIMERS
  65. __no_posix_timers = -1;
  66. # endif
  67. }
  68. # ifndef __ASSUME_POSIX_TIMERS
  69. return compat_timer_settime (timerid, flags, value, ovalue);
  70. # endif
  71. }
  72. #else
  73. # ifdef timer_settime_alias
  74. # define timer_settime timer_settime_alias
  75. # endif
  76. /* The new system calls are not available. Use the userlevel
  77. implementation. */
  78. # include <nptl/sysdeps/pthread/timer_settime.c>
  79. #endif