lutimes.c 832 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * lutimes() implementation for uClibc
  3. *
  4. * Copyright (C) 2010 Vladimir Zapolskiy <vzapolskiy@gmail.com>
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  7. */
  8. #include <sys/syscall.h>
  9. #include <time.h>
  10. #ifdef __NR_lutimes
  11. _syscall2(int, lutimes, const char *, file, const struct timeval *, tvp)
  12. #elif defined __NR_utimensat
  13. #include <sys/time.h>
  14. #include <fcntl.h>
  15. int lutimes(const char *file, const struct timeval tvp[2])
  16. {
  17. struct timespec ts[2];
  18. if (tvp != NULL)
  19. {
  20. if (tvp[0].tv_usec < 0 || tvp[0].tv_usec >= 1000000
  21. || tvp[1].tv_usec < 0 || tvp[1].tv_usec >= 1000000)
  22. {
  23. __set_errno(EINVAL);
  24. return -1;
  25. }
  26. TIMEVAL_TO_TIMESPEC(&tvp[0], &ts[0]);
  27. TIMEVAL_TO_TIMESPEC(&tvp[1], &ts[1]);
  28. }
  29. return utimensat(AT_FDCWD, file, tvp ? ts : NULL, AT_SYMLINK_NOFOLLOW);
  30. }
  31. #endif