From: Mike Yuan Date: Sat, 19 Oct 2024 16:56:50 +0000 (+0200) Subject: basic/fs-util: move unlink_tempfilep() to tmpfile-util X-Git-Tag: v257-rc1~147^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d845254b7f90e96318fc4f3a48fc9f583cb89c2e;p=thirdparty%2Fsystemd.git basic/fs-util: move unlink_tempfilep() to tmpfile-util --- diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 35cebfc849a..16250e1e94c 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -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; diff --git a/src/basic/fs-util.h b/src/basic/fs-util.h index 93af685eef2..028c86a3b2e 100644 --- a/src/basic/fs-util.h +++ b/src/basic/fs-util.h @@ -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, diff --git a/src/basic/tmpfile-util.c b/src/basic/tmpfile-util.c index 3a3f7dcc0ff..5addd8e8a91 100644 --- a/src/basic/tmpfile-util.c +++ b/src/basic/tmpfile-util.c @@ -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; diff --git a/src/basic/tmpfile-util.h b/src/basic/tmpfile-util.h index 8c917c06805..408f80e1472 100644 --- a/src/basic/tmpfile-util.h +++ b/src/basic/tmpfile-util.h @@ -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);