From c7d36adfc2f4b6660602f3f5ed8079b4830158c2 Mon Sep 17 00:00:00 2001 From: Markos Chandras Date: Thu, 11 Oct 2012 10:51:33 +0100 Subject: utime: Use utimensat if arch does not have the utime syscall Signed-off-by: Markos Chandras Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/common/utime.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'libc/sysdeps/linux/common/utime.c') 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 #include -#ifdef __NR_utime +#if defined __NR_utimensat && !defined __NR_utime +# include +# include + +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 -- cgit v1.2.3