time.c 632 B

1234567891011121314151617181920212223242526272829303132
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * time() for uClibc
  4. *
  5. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  6. *
  7. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  8. */
  9. #include <sys/syscall.h>
  10. #include <time.h>
  11. #ifdef __NR_time
  12. _syscall_noerr1(time_t, time, time_t *, t)
  13. #else
  14. # include <sys/time.h>
  15. time_t time(time_t * t)
  16. {
  17. time_t result;
  18. struct timeval tv;
  19. /* In Linux, gettimeofday fails only on bad parameter.
  20. * We know that here parameter isn't bad.
  21. */
  22. gettimeofday(&tv, NULL);
  23. result = (time_t) tv.tv_sec;
  24. if (t != NULL)
  25. *t = result;
  26. return result;
  27. }
  28. #endif
  29. libc_hidden_def(time)