utime.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * utime() for uClibc
  3. *
  4. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  7. */
  8. #include <sys/syscall.h>
  9. #include <utime.h>
  10. #if defined __NR_utimensat && !defined __NR_utime
  11. # include <fcntl.h>
  12. # include <stddef.h>
  13. int utime(const char *file, const struct utimbuf *times)
  14. {
  15. struct timespec tspecs[2], *ts;
  16. if (times) {
  17. ts = tspecs;
  18. ts[0].tv_sec = times->actime;
  19. ts[0].tv_nsec = 0;
  20. ts[1].tv_sec = times->modtime;
  21. ts[1].tv_nsec = 0;
  22. } else {
  23. ts = NULL;
  24. }
  25. return utimensat(AT_FDCWD, file, ts, 0);
  26. }
  27. #elif defined(__NR_utime)
  28. _syscall2(int, utime, const char *, file, const struct utimbuf *, times)
  29. #elif defined __NR_utimes /* alpha || ia64 */
  30. # define __need_NULL
  31. # include <stddef.h>
  32. # include <sys/time.h>
  33. int utime(const char *file, const struct utimbuf *times)
  34. {
  35. struct timeval timevals[2];
  36. if (times != NULL) {
  37. timevals[0].tv_usec = 0L;
  38. timevals[1].tv_usec = 0L;
  39. timevals[0].tv_sec = (time_t) times->actime;
  40. timevals[1].tv_sec = (time_t) times->modtime;
  41. }
  42. return utimes(file, times ? timevals : NULL);
  43. }
  44. #endif
  45. #if (defined __NR_utimensat && !defined __NR_utime) || \
  46. defined __NR_utime || defined __NR_utimes
  47. libc_hidden_def(utime)
  48. #endif