utime.c 913 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * utime() 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 <utime.h>
  11. #ifdef __NR_utime
  12. attribute_hidden _syscall2(int, utime, const char *, file, const struct utimbuf *, times);
  13. #else
  14. #include <stdlib.h>
  15. #include <sys/time.h>
  16. libc_hidden_proto(utimes)
  17. libc_hidden_proto(gettimeofday)
  18. int utime(const char *file, const struct utimbuf *times)
  19. {
  20. struct timeval timevals[2];
  21. if (times != NULL) {
  22. timevals[0].tv_usec = 0L;
  23. timevals[1].tv_usec = 0L;
  24. timevals[0].tv_sec = (long int) times->actime;
  25. timevals[1].tv_sec = (long int) times->modtime;
  26. } else {
  27. if (gettimeofday(&timevals[0], NULL) < 0) {
  28. return -1;
  29. }
  30. timevals[1] = timevals[0];
  31. }
  32. return utimes(file, timevals);
  33. }
  34. #endif
  35. libc_hidden_proto(utime)
  36. libc_hidden_def(utime)