Print this page
13111 Want futimes() and lutimes() functions
Change-ID: I3be82d4242255a4100f8c35db373eb9140402fc4

@@ -22,10 +22,14 @@
 /*
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
+/*
+ * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
+ */
+
 #include "lint.h"
 #include <string.h>
 #include <utime.h>
 #include <fcntl.h>
 #include <sys/stat.h>

@@ -65,12 +69,12 @@
                 tsp = ts;
         }
         return (utimensat(AT_FDCWD, path, tsp, 0));
 }
 
-int
-utimes(const char *path, const struct timeval times[2])
+static int
+utimes_impl(const char *path, const struct timeval times[2], int flag)
 {
         struct timeval ltimes[2];
         timespec_t ts[2];
         timespec_t *tsp;
 

@@ -84,13 +88,25 @@
                 ts[0].tv_nsec = ltimes[0].tv_usec * 1000;
                 ts[1].tv_sec = ltimes[1].tv_sec;
                 ts[1].tv_nsec = ltimes[1].tv_usec * 1000;
                 tsp = ts;
         }
-        return (utimensat(AT_FDCWD, path, tsp, 0));
+        return (utimensat(AT_FDCWD, path, tsp, flag));
 }
 
+int
+utimes(const char *path, const struct timeval times[2])
+{
+        return (utimes_impl(path, times, 0));
+}
+
+int
+lutimes(const char *path, const struct timeval times[2])
+{
+        return (utimes_impl(path, times, AT_SYMLINK_NOFOLLOW));
+}
+
 #pragma weak _futimesat = futimesat
 int
 futimesat(int fd, const char *path, const struct timeval times[2])
 {
         struct timeval ltimes[2];

@@ -112,6 +128,12 @@
 
         if (path == NULL)
                 return (futimens(fd, tsp));
 
         return (utimensat(fd, path, tsp, 0));
+}
+
+int
+futimes(int fd, const struct timeval times[2])
+{
+        return (futimesat(fd, NULL, times));
 }