utimes.c 1.2 KB

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