clock_gettime.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * clock_gettime() for uClibc
  3. *
  4. * Copyright (C) 2003 by Justus Pendleton <uc@ryoohki.net>
  5. * Copyright (C) 2005 by Peter Kjellerstedt <pkj@axis.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Library General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  15. * for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public License
  18. * along with this program; if not, write to the Free Software Foundation,
  19. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. #define _GNU_SOURCE
  23. #include "syscalls.h"
  24. #include <time.h>
  25. #include <sys/time.h>
  26. #ifdef __NR_clock_gettime
  27. _syscall2(int, clock_gettime, clockid_t, clock_id, struct timespec*, tp);
  28. #else
  29. int clock_gettime(clockid_t clock_id, struct timespec* tp)
  30. {
  31. struct timeval tv;
  32. int retval = -1;
  33. switch (clock_id) {
  34. case CLOCK_REALTIME:
  35. retval = gettimeofday(&tv, NULL);
  36. if (retval == 0) {
  37. TIMEVAL_TO_TIMESPEC(&tv, tp);
  38. }
  39. break;
  40. default:
  41. errno = EINVAL;
  42. break;
  43. }
  44. return retval;
  45. }
  46. #endif