time: Use 64 bit time on tzfile
[glibc.git] / nptl / sem_timedwait.c
blob63e778245c885fca6970bdbb98b4e132bf57c8f5
1 /* sem_timedwait -- wait on a semaphore with timeout.
2 Copyright (C) 2003-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <time.h>
20 #include "semaphoreP.h"
21 #include "sem_waitcommon.c"
23 /* This is in a separate file because because sem_timedwait is only provided
24 if __USE_XOPEN2K is defined. */
25 int
26 ___sem_timedwait64 (sem_t *sem, const struct __timespec64 *abstime)
28 if (! valid_nanoseconds (abstime->tv_nsec))
30 __set_errno (EINVAL);
31 return -1;
34 /* Check sem_wait.c for a more detailed explanation why it is required. */
35 __pthread_testcancel ();
37 if (__new_sem_wait_fast ((struct new_sem *) sem, 0) == 0)
38 return 0;
39 else
40 return __new_sem_wait_slow64 ((struct new_sem *) sem,
41 CLOCK_REALTIME, abstime);
44 #if __TIMESIZE == 64
45 strong_alias (___sem_timedwait64, ___sem_timedwait)
46 #else /* __TIMESPEC64 != 64 */
47 strong_alias (___sem_timedwait64, __sem_timedwait64)
48 libc_hidden_def (__sem_timedwait64)
50 int
51 ___sem_timedwait (sem_t *sem, const struct timespec *abstime)
53 struct __timespec64 ts64 = valid_timespec_to_timespec64 (*abstime);
55 return __sem_timedwait64 (sem, &ts64);
57 #endif /* __TIMESPEC64 != 64 */
58 versioned_symbol (libc, ___sem_timedwait, sem_timedwait, GLIBC_2_34);
59 #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_2, GLIBC_2_34)
60 compat_symbol (libpthread, ___sem_timedwait, sem_timedwait, GLIBC_2_2);
61 #endif