[git commit] utime: Use utimensat if arch does not have the utime syscall

Bernhard Reutner-Fischer rep.dot.nop at gmail.com
Wed Feb 20 12:45:12 UTC 2013


commit: http://git.uclibc.org/uClibc/commit/?id=c7d36adfc2f4b6660602f3f5ed8079b4830158c2
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/master

Signed-off-by: Markos Chandras <markos.chandras at imgtec.com>

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
---
 libc/sysdeps/linux/common/utime.c |   27 +++++++++++++++++++++++++--
 1 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/libc/sysdeps/linux/common/utime.c b/libc/sysdeps/linux/common/utime.c
index ab63a24..886d23a 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


More information about the uClibc-cvs mailing list