utimens, utimensat: work around Solaris UTIME_OMIT bug
[gnulib.git] / lib / utimensat.c
index 0110400..0c52b24 100644 (file)
@@ -48,7 +48,7 @@ int
 rpl_utimensat (int fd, char const *file, struct timespec const times[2],
                int flag)
 {
-# ifdef __linux__
+# if defined __linux__ || defined __sun
   struct timespec ts[2];
 # endif
 
@@ -57,7 +57,7 @@ rpl_utimensat (int fd, char const *file, struct timespec const times[2],
   if (0 <= utimensat_works_really)
     {
       int result;
-# ifdef __linux__
+# if defined __linux__ || defined __sun
       struct stat st;
       /* As recently as Linux kernel 2.6.32 (Dec 2009), several file
          systems (xfs, ntfs-3g) have bugs with a single UTIME_OMIT,
@@ -65,8 +65,12 @@ rpl_utimensat (int fd, char const *file, struct timespec const times[2],
          UTIME_NOW.  Work around it with a preparatory [l]stat prior
          to calling utimensat; fortunately, there is not much timing
          impact due to the extra syscall even on file systems where
-         UTIME_OMIT would have worked.  FIXME: Simplify this in 2012,
-         when file system bugs are no longer common.  */
+         UTIME_OMIT would have worked.
+
+         The same bug occurs in Solaris 11.1 (Apr 2013).
+
+         FIXME: Simplify this for Linux in 2016 and for Solaris in
+         2024, when file system bugs are no longer common.  */
       if (times && (times[0].tv_nsec == UTIME_OMIT
                     || times[1].tv_nsec == UTIME_OMIT))
         {
@@ -99,7 +103,7 @@ rpl_utimensat (int fd, char const *file, struct timespec const times[2],
           return -1;
         }
 #  endif
-# endif /* __linux__ */
+# endif
       result = utimensat (fd, file, times, flag);
       /* Linux kernel 2.6.25 has a bug where it returns EINVAL for
          UTIME_NOW or UTIME_OMIT with non-zero tv_sec, which