utime.c 947 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. #define utimes __utimes
  10. #define gettimeofday __gettimeofday
  11. #include "syscalls.h"
  12. #include <utime.h>
  13. #ifdef __NR_utime
  14. #define __NR___utime __NR_utime
  15. attribute_hidden _syscall2(int, __utime, const char *, file, const struct utimbuf *, times);
  16. #else
  17. #include <stdlib.h>
  18. #include <sys/time.h>
  19. int attribute_hidden __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. strong_alias(__utime,utime)