clock_gettime.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 gettimeofday __gettimeofday
  23. #define _GNU_SOURCE
  24. #include "syscalls.h"
  25. #include <time.h>
  26. #include <sys/time.h>
  27. #ifdef __NR_clock_gettime
  28. _syscall2(int, clock_gettime, clockid_t, clock_id, struct timespec*, tp);
  29. #else
  30. int clock_gettime(clockid_t clock_id, struct timespec* tp)
  31. {
  32. struct timeval tv;
  33. int retval = -1;
  34. switch (clock_id) {
  35. case CLOCK_REALTIME:
  36. retval = gettimeofday(&tv, NULL);
  37. if (retval == 0) {
  38. TIMEVAL_TO_TIMESPEC(&tv, tp);
  39. }
  40. break;
  41. default:
  42. errno = EINVAL;
  43. break;
  44. }
  45. return retval;
  46. }
  47. #endif