timespec_get.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Copyright (C) 2011-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <time.h>
  15. #include <sysdep.h>
  16. #include <errno.h>
  17. #ifdef HAVE_CLOCK_GETTIME_VSYSCALL
  18. # define HAVE_VSYSCALL
  19. #endif
  20. #include <sysdep-vdso.h>
  21. /* Set TS to calendar time based in time base BASE. */
  22. int
  23. timespec_get (struct timespec *ts, int base)
  24. {
  25. switch (base)
  26. {
  27. int res;
  28. INTERNAL_SYSCALL_DECL (err);
  29. case TIME_UTC:
  30. res = INTERNAL_VSYSCALL (clock_gettime, err, 2, CLOCK_REALTIME, ts);
  31. if (INTERNAL_SYSCALL_ERROR_P (res, err))
  32. return 0;
  33. break;
  34. default:
  35. return 0;
  36. }
  37. return base;
  38. }