utime.c 920 B

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