time.c 640 B

1234567891011121314151617181920212223242526272829303132333435
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * time() for uClibc
  4. *
  5. * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
  6. *
  7. * GNU Library General Public License (LGPL) version 2 or later.
  8. */
  9. #include "syscalls.h"
  10. #include <time.h>
  11. #include <sys/time.h>
  12. #ifdef __NR_time
  13. _syscall1(time_t, time, time_t *, t);
  14. #else
  15. libc_hidden_proto(gettimeofday)
  16. time_t time(time_t * t)
  17. {
  18. time_t result;
  19. struct timeval tv;
  20. if (gettimeofday(&tv, (struct timezone *) NULL)) {
  21. result = (time_t) - 1;
  22. } else {
  23. result = (time_t) tv.tv_sec;
  24. }
  25. if (t != NULL) {
  26. *t = result;
  27. }
  28. return result;
  29. }
  30. #endif
  31. libc_hidden_proto(time)
  32. libc_hidden_def(time)