This patch adds lutimes library call support.

Signed-off-by: Vladimir Zapolskiy <[email protected]>
---
 include/sys/time.h                  |    4 ++-
 libc/sysdeps/linux/common/lutimes.c |   37 +++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletions(-)
 create mode 100644 libc/sysdeps/linux/common/lutimes.c

diff --git a/include/sys/time.h b/include/sys/time.h
index 33f5873..30370f1 100644
--- a/include/sys/time.h
+++ b/include/sys/time.h
@@ -144,11 +144,13 @@ extern int utimes (__const char *__file, __const struct 
timeval __tvp[2])
      __THROW __nonnull ((1));
 libc_hidden_proto(utimes)
 
-#if 0 /*def __USE_BSD*/
+#ifdef __USE_BSD
 /* Same as `utimes', but does not follow symbolic links.  */
 extern int lutimes (__const char *__file, __const struct timeval __tvp[2])
      __THROW __nonnull ((1));
+#endif
 
+#if 0
 /* Same as `utimes', but takes an open file descriptor instead of a name.  */
 extern int futimes (int __fd, __const struct timeval __tvp[2]) __THROW;
 #endif
diff --git a/libc/sysdeps/linux/common/lutimes.c 
b/libc/sysdeps/linux/common/lutimes.c
new file mode 100644
index 0000000..a2a6131
--- /dev/null
+++ b/libc/sysdeps/linux/common/lutimes.c
@@ -0,0 +1,37 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * lutimes() implementation for uClibc
+ *
+ * Copyright (C) 2010 Vladimir Zapolskiy <[email protected]>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+#include <sys/syscall.h>
+#include <time.h>
+
+#ifdef __NR_lutimes
+_syscall2(int, lutimes, const char *, file, const struct timeval *, tvp)
+#else
+#include <sys/time.h>
+
+int lutimes(const char *file, const struct timeval tvp[2])
+{
+       struct timespec ts[2];
+
+       if (tvp != NULL)
+       {
+               if (tvp[0].tv_usec < 0 || tvp[0].tv_usec >= 1000000
+                   || tvp[1].tv_usec < 0 || tvp[1].tv_usec >= 1000000)
+               {
+                       __set_errno(EINVAL);
+                       return -1;
+               }
+
+               TIMEVAL_TO_TIMESPEC(&tvp[0], &ts[0]);
+               TIMEVAL_TO_TIMESPEC(&tvp[1], &ts[1]);
+       }
+
+       return utimensat(AT_FDCWD, file, tvp ? ts : NULL, AT_SYMLINK_NOFOLLOW);
+}
+#endif
-- 
1.7.0.3

_______________________________________________
uClibc mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/uclibc

Reply via email to