summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkos Chandras <markos.chandras@imgtec.com>2012-10-11 10:51:33 +0100
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2013-02-20 13:45:12 +0100
commitc7d36adfc2f4b6660602f3f5ed8079b4830158c2 (patch)
treeaec918236cde276dc72b8db6229b9e093b60eec3
parentaf63ec925e7e7f6eb19dde5f51c8ebec44a10607 (diff)
utime: Use utimensat if arch does not have the utime syscall
Signed-off-by: Markos Chandras <markos.chandras@imgtec.com> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
-rw-r--r--libc/sysdeps/linux/common/utime.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/libc/sysdeps/linux/common/utime.c b/libc/sysdeps/linux/common/utime.c
index ab63a24b2..886d23a49 100644
--- a/libc/sysdeps/linux/common/utime.c
+++ b/libc/sysdeps/linux/common/utime.c
@@ -10,7 +10,28 @@
#include <sys/syscall.h>
#include <utime.h>
-#ifdef __NR_utime
+#if defined __NR_utimensat && !defined __NR_utime
+# include <fcntl.h>
+# include <stddef.h>
+
+int utime(const char *file, const struct utimbuf *times)
+{
+ struct timespec tspecs[2], *ts;
+
+ if (times) {
+ ts = tspecs;
+ ts[0].tv_sec = times->actime;
+ ts[0].tv_nsec = 0;
+ ts[1].tv_sec = times->modtime;
+ ts[1].tv_nsec = 0;
+ } else {
+ ts = NULL;
+ }
+
+ return utimensat(AT_FDCWD, file, ts, 0);
+}
+
+#elif defined(__NR_utime)
_syscall2(int, utime, const char *, file, const struct utimbuf *, times)
#elif defined __NR_utimes /* alpha || ia64 */
# define __need_NULL
@@ -30,7 +51,9 @@ int utime(const char *file, const struct utimbuf *times)
return utimes(file, times ? timevals : NULL);
}
#endif
-#if defined __NR_utime || defined __NR_utimes
+
+#if (defined __NR_utimensat && !defined __NR_utime) || \
+ defined __NR_utime || defined __NR_utimes
link_warning(utime, "the use of OBSOLESCENT `utime' is discouraged, use `utimes'")
libc_hidden_def(utime)
#endif