chiark / gitweb /
Get rid of some more unused defines and dirs
[elogind.git] / src / shared / copy.c
index b681f6f109126b1856cfc0d6a23a4af2eac9981a..775a33985613a33c7d5b1e9a51dba1bf236c03ad 100644 (file)
@@ -285,7 +285,7 @@ static int fd_copy_directory(
                 else if (S_ISBLK(buf.st_mode) || S_ISCHR(buf.st_mode))
                         q = fd_copy_node(dirfd(d), de->d_name, &buf, fdt, de->d_name);
                 else
-                        q = -ENOTSUP;
+                        q = -EOPNOTSUPP;
 
                 if (q == -EEXIST && merge)
                         q = 0;
@@ -317,7 +317,7 @@ int copy_tree_at(int fdf, const char *from, int fdt, const char *to, bool merge)
         else if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode))
                 return fd_copy_node(fdf, from, &st, fdt, to);
         else
-                return -ENOTSUP;
+                return -EOPNOTSUPP;
 }
 
 int copy_tree(const char *from, const char *to, bool merge) {
@@ -359,8 +359,8 @@ int copy_file_fd(const char *from, int fdt, bool try_reflink) {
         return r;
 }
 
-int copy_file(const char *from, const char *to, int flags, mode_t mode, int chattr_flags) {
-        int fdt, r;
+int copy_file(const char *from, const char *to, int flags, mode_t mode, unsigned chattr_flags) {
+        int fdt = -1, r;
 
         assert(from);
         assert(to);
@@ -389,8 +389,8 @@ int copy_file(const char *from, const char *to, int flags, mode_t mode, int chat
         return 0;
 }
 
-int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace, int chattr_flags) {
-        _cleanup_free_ char *t;
+int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace, unsigned chattr_flags) {
+        _cleanup_free_ char *t = NULL;
         int r;
 
         assert(from);
@@ -404,9 +404,15 @@ int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace
         if (r < 0)
                 return r;
 
-        if (renameat2(AT_FDCWD, t, AT_FDCWD, to, replace ? 0 : RENAME_NOREPLACE) < 0) {
-                unlink_noerrno(t);
-                return -errno;
+        if (replace) {
+                r = renameat(AT_FDCWD, t, AT_FDCWD, to);
+                if (r < 0)
+                        r = -errno;
+        } else
+                r = rename_noreplace(AT_FDCWD, t, AT_FDCWD, to);
+        if (r < 0) {
+                (void) unlink_noerrno(t);
+                return r;
         }
 
         return 0;
@@ -415,7 +421,7 @@ int copy_file_atomic(const char *from, const char *to, mode_t mode, bool replace
 int copy_times(int fdf, int fdt) {
         struct timespec ut[2];
         struct stat st;
-        usec_t crtime;
+        usec_t crtime = 0;
 
         assert(fdf >= 0);
         assert(fdt >= 0);