clock_gettime.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* Copyright (C) 2003 Justus Pendleton <uc@ryoohki.net>
  2. *
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Library General Public
  5. * License as published by the Free Software Foundation; either
  6. * version 2 of the License, or (at your option) any later version.
  7. *
  8. * This 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. * Library General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Library General Public
  14. * License along with this library; if not, write to the Free
  15. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. #define _GNU_SOURCE
  18. #include <time.h>
  19. #include <errno.h>
  20. #include <sys/time.h>
  21. int clock_gettime (clockid_t clock, struct timespec* ts)
  22. {
  23. struct timeval tv;
  24. int retval = -1;
  25. switch (clock) {
  26. case CLOCK_REALTIME:
  27. retval = gettimeofday (&tv, NULL);
  28. if (retval == 0) {
  29. TIMEVAL_TO_TIMESPEC (&tv, ts);
  30. }
  31. break;
  32. default:
  33. errno = EINVAL;
  34. break;
  35. }
  36. return retval;
  37. }