]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/fs-util: move unlink_tempfilep() to tmpfile-util
authorMike Yuan <me@yhndnzj.com>
Sat, 19 Oct 2024 16:56:50 +0000 (18:56 +0200)
committerMike Yuan <me@yhndnzj.com>
Tue, 22 Oct 2024 17:19:39 +0000 (19:19 +0200)
src/basic/fs-util.c
src/basic/fs-util.h
src/basic/tmpfile-util.c
src/basic/tmpfile-util.h

index 35cebfc849a6c9450f6a0c98cdfbb9cb76a6c8d3..16250e1e94ca683d12c3582dd4bd7b94f2a1eea0 100644 (file)
@@ -694,17 +694,6 @@ int access_fd(int fd, int mode) {
         return 0;
 }
 
-void unlink_tempfilep(char (*p)[]) {
-        assert(p);
-
-        /* If the file is created with mkstemp(), it will (almost always)
-         * change the suffix. Treat this as a sign that the file was
-         * successfully created. We ignore both the rare case where the
-         * original suffix is used and unlink failures. */
-        if (!endswith(*p, ".XXXXXX"))
-                (void) unlink(*p);
-}
-
 int unlinkat_deallocate(int fd, const char *name, UnlinkDeallocateFlags flags) {
         _cleanup_close_ int truncate_fd = -EBADF;
         struct stat st;
index 93af685eef2aac2def7cdaa5cc892f2af3e71e15..028c86a3b2e8dad3c374cfe26d85e4c27a71dad9 100644 (file)
@@ -112,8 +112,6 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(char*, unlink_and_free);
 
 int access_fd(int fd, int mode);
 
-void unlink_tempfilep(char (*p)[]);
-
 typedef enum UnlinkDeallocateFlags {
         UNLINK_REMOVEDIR = 1 << 0,
         UNLINK_ERASE     = 1 << 1,
index 3a3f7dcc0ff1c7b1e106b3b26d309a234a92c6b9..5addd8e8a91c29c6f316604f0ff51cd98aba7c3c 100644 (file)
@@ -118,6 +118,17 @@ int fmkostemp_safe(char *pattern, const char *mode, FILE **ret_f) {
         return 0;
 }
 
+void unlink_tempfilep(char (*p)[]) {
+        assert(p);
+
+        /* If the file is created with mkstemp(), it will (almost always) change the suffix.
+         * Treat this as a sign that the file was successfully created. We ignore both the rare case
+         * where the original suffix is used and unlink failures. */
+
+        if (!endswith(*p, ".XXXXXX"))
+                (void) unlink(*p);
+}
+
 static int tempfn_build(const char *p, const char *pre, const char *post, bool child, char **ret) {
         _cleanup_free_ char *d = NULL, *fn = NULL, *nf = NULL, *result = NULL;
         size_t len_pre, len_post, len_add;
index 8c917c0680538ccabbda69fb0c15e6e63a260a76..408f80e1472f885a7cd7f6f241f37ffd22d07434 100644 (file)
@@ -18,6 +18,8 @@ static inline int fopen_temporary_child(const char *path, FILE **ret_file, char
 int mkostemp_safe(char *pattern);
 int fmkostemp_safe(char *pattern, const char *mode, FILE**_f);
 
+void unlink_tempfilep(char (*p)[]);
+
 int tempfn_xxxxxx(const char *p, const char *extra, char **ret);
 int tempfn_random(const char *p, const char *extra, char **ret);
 int tempfn_random_child(const char *p, const char *extra, char **ret);