]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blobdiff - util/subst.c
Merge branch 'maint' into next
[thirdparty/e2fsprogs.git] / util / subst.c
index 32d5293207c77c4aca74ba5a628fcebcaf2614a7..f36adb4d81a5903badfe2d9ebc23bc8d815a3e0c 100644 (file)
@@ -5,13 +5,20 @@
  *
  */
 
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#else
+#define HAVE_SYS_TIME_H
+#endif
 #include <stdio.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
 #include <ctype.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -289,6 +296,23 @@ static int compare_file(FILE *old_f, FILE *new_f)
        return retval;
 }
 
+void set_utimes(const char *filename, int fd, const struct timeval times[2])
+{
+#ifdef HAVE_FUTIMES
+       if (futimes(fd, times) < 0)
+               perror("futimes");
+#elif HAVE_UTIMES
+       if (utimes(filename, times) < 0)
+               perror("utimes");
+#else
+       struct utimbuf ut;
+
+       ut.actime = times[0].tv_sec;
+       ut.modtime = times[1].tv_sec;
+       if (utime(filename, &ut) < 0)
+               perror("utime");
+#endif
+}
 
 
 int main(int argc, char **argv)
@@ -403,13 +427,7 @@ int main(int argc, char **argv)
                                        tv[0] = tv[1];
                                else if (verbose)
                                        printf("Using original atime\n");
-#ifdef HAVE_FUTIMES
-                               if (futimes(fileno(old), tv) < 0)
-                                       perror("futimes");
-#else
-                               if (utimes(outfn, tv) < 0)
-                                       perror("utimes");
-#endif
+                               set_utimes(outfn, fileno(old), tv);
                        }
                        fclose(out);
                        if (unlink(newfn) < 0)