utime.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * utime() 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 <utime.h>
  11. #if defined __NR_utimensat && !defined __NR_utime
  12. # include <fcntl.h>
  13. # include <stddef.h>
  14. int utime(const char *file, const struct utimbuf *times)
  15. {
  16. struct timespec tspecs[2], *ts;
  17. if (times) {
  18. ts = tspecs;
  19. ts[0].tv_sec = times->actime;
  20. ts[0].tv_nsec = 0;
  21. ts[1].tv_sec = times->modtime;
  22. ts[1].tv_nsec = 0;
  23. } else {
  24. ts = NULL;
  25. }
  26. return utimensat(AT_FDCWD, file, ts, 0);
  27. }
  28. #elif defined(__NR_utime)
  29. _syscall2(int, utime, const char *, file, const struct utimbuf *, times)
  30. #elif defined __NR_utimes /* alpha || ia64 */
  31. # define __need_NULL
  32. # include <stddef.h>
  33. # include <sys/time.h>
  34. int utime(const char *file, const struct utimbuf *times)
  35. {
  36. struct timeval timevals[2];
  37. if (times != NULL) {
  38. timevals[0].tv_usec = 0L;
  39. timevals[1].tv_usec = 0L;
  40. timevals[0].tv_sec = (time_t) times->actime;
  41. timevals[1].tv_sec = (time_t) times->modtime;
  42. }
  43. return utimes(file, times ? timevals : NULL);
  44. }
  45. #endif
  46. #if (defined __NR_utimensat && !defined __NR_utime) || \
  47. defined __NR_utime || defined __NR_utimes
  48. link_warning(utime, "the use of OBSOLESCENT `utime' is discouraged, use `utimes'")
  49. libc_hidden_def(utime)
  50. #endif