]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fs-util: modernize touch_file a bit 32547/head
authorMike Yuan <me@yhndnzj.com>
Mon, 29 Apr 2024 08:23:00 +0000 (16:23 +0800)
committerMike Yuan <me@yhndnzj.com>
Mon, 29 Apr 2024 08:33:17 +0000 (16:33 +0800)
src/basic/fs-util.c

index 43836f082ff65b931dd8166624bf800b119e4105..b3d5e8a07d2da922291f3d4a4ab2ac1ffa07b7b5 100644 (file)
@@ -415,17 +415,14 @@ int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gi
         ret = fchmod_and_chown(fd, mode, uid, gid);
 
         if (stamp != USEC_INFINITY) {
-                struct timespec ts[2];
+                struct timespec ts;
+                timespec_store(&ts, stamp);
 
-                timespec_store(&ts[0], stamp);
-                ts[1] = ts[0];
-                r = futimens_opath(fd, ts);
+                r = futimens_opath(fd, (const struct timespec[2]) { ts, ts });
         } else
-                r = futimens_opath(fd, NULL);
-        if (r < 0 && ret >= 0)
-                return r;
+                r = futimens_opath(fd, /* ts = */ NULL);
 
-        return ret;
+        return RET_GATHER(ret, r);
 }
 
 int symlink_idempotent(const char *from, const char *to, bool make_relative) {