lutimes.c 857 B

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