utimes.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * utimes() 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 <sys/time.h>
  10. #if (defined (__NR_utimensat) || defined(__NR_utimensat_time64)) && !defined __NR_utimes
  11. # include <fcntl.h>
  12. # include <stddef.h>
  13. int utimes(const char *file, const struct timeval tvp[2])
  14. {
  15. struct timespec ts[2], *times;
  16. if (tvp) {
  17. times = ts;
  18. times[0].tv_sec = tvp[0].tv_sec;
  19. times[0].tv_nsec = tvp[0].tv_usec * 1000;
  20. times[1].tv_sec = tvp[1].tv_sec;
  21. times[1].tv_nsec = tvp[1].tv_usec * 1000;
  22. } else {
  23. times = NULL;
  24. }
  25. return utimensat(AT_FDCWD, file, times, 0);
  26. }
  27. #elif defined __NR_utimes
  28. _syscall2(int, utimes, const char *, file, const struct timeval *, tvp)
  29. #elif defined __NR_utime
  30. # define __need_NULL
  31. # include <stddef.h>
  32. # include <utime.h>
  33. int utimes(const char *file, const struct timeval tvp[2])
  34. {
  35. struct utimbuf buf, *times;
  36. if (tvp) {
  37. times = &buf;
  38. times->actime = tvp[0].tv_sec;
  39. times->modtime = tvp[1].tv_sec;
  40. } else {
  41. times = NULL;
  42. }
  43. return utime(file, times);
  44. }
  45. #endif
  46. #if defined __NR_utimensat || defined __NR_utimensat_time64 || defined __NR_utimes || defined __NR_utime
  47. libc_hidden_def(utimes)
  48. #endif