]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
copy: simplify futimens() invocation 18462/head
authorLennart Poettering <lennart@poettering.net>
Mon, 1 Feb 2021 16:01:14 +0000 (17:01 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 3 Feb 2021 22:25:02 +0000 (23:25 +0100)
src/basic/copy.c

index c2c337c1a1b04d6b3a3f76acf08d4b9b13422acf..aede5be9910d9957f4bd8e22314ca236de45155f 100644 (file)
@@ -593,7 +593,6 @@ static int fd_copy_regular(
                 void *userdata) {
 
         _cleanup_close_ int fdf = -1, fdt = -1;
-        struct timespec ts[2];
         int r, q;
 
         assert(from);
@@ -635,9 +634,7 @@ static int fd_copy_regular(
         if (fchmod(fdt, st->st_mode & 07777) < 0)
                 r = -errno;
 
-        ts[0] = st->st_atim;
-        ts[1] = st->st_mtim;
-        (void) futimens(fdt, ts);
+        (void) futimens(fdt, (struct timespec[]) { st->st_atim, st->st_mtim });
         (void) copy_xattr(fdf, fdt);
 
         q = close(fdt);
@@ -918,11 +915,6 @@ static int fd_copy_directory(
         }
 
         if (created) {
-                struct timespec ut[2] = {
-                        st->st_atim,
-                        st->st_mtim
-                };
-
                 if (fchown(fdt,
                            uid_is_valid(override_uid) ? override_uid : st->st_uid,
                            gid_is_valid(override_gid) ? override_gid : st->st_gid) < 0)
@@ -932,7 +924,7 @@ static int fd_copy_directory(
                         r = -errno;
 
                 (void) copy_xattr(dirfd(d), fdt);
-                (void) futimens(fdt, ut);
+                (void) futimens(fdt, (struct timespec[]) { st->st_atim, st->st_mtim });
         }
 
         return r;
@@ -1187,7 +1179,6 @@ int copy_file_atomic_full(
 }
 
 int copy_times(int fdf, int fdt, CopyFlags flags) {
-        struct timespec ut[2];
         struct stat st;
 
         assert(fdf >= 0);
@@ -1196,10 +1187,7 @@ int copy_times(int fdf, int fdt, CopyFlags flags) {
         if (fstat(fdf, &st) < 0)
                 return -errno;
 
-        ut[0] = st.st_atim;
-        ut[1] = st.st_mtim;
-
-        if (futimens(fdt, ut) < 0)
+        if (futimens(fdt, (struct timespec[2]) { st.st_atim, st.st_mtim }) < 0)
                 return -errno;
 
         if (FLAGS_SET(flags, COPY_CRTIME)) {