utime.c 787 B

12345678910111213141516171819202122232425262728293031323334
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * utime() for uClibc
  4. *
  5. * Copyright (C) 2000-2004 by Erik Andersen <andersen@codpoet.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. _syscall2(int, utime, const char *, file, const struct utimbuf *, times);
  13. #else
  14. #include <stdlib.h>
  15. #include <sys/time.h>
  16. int utime(const char *file, const struct utimbuf *times)
  17. {
  18. struct timeval timevals[2];
  19. if (times != NULL) {
  20. timevals[0].tv_usec = 0L;
  21. timevals[1].tv_usec = 0L;
  22. timevals[0].tv_sec = (long int) times->actime;
  23. timevals[1].tv_sec = (long int) times->modtime;
  24. } else {
  25. if (gettimeofday(&timevals[0], NULL) < 0) {
  26. return -1;
  27. }
  28. timevals[1] = timevals[0];
  29. }
  30. return utimes(file, timevals);
  31. }
  32. #endif