return 0;
}
-int mkfifo_atomic(const char *path, mode_t mode) {
+int mkfifoat_atomic(int atfd, const char *path, mode_t mode) {
_cleanup_free_ char *t = NULL;
int r;
assert(path);
+ /* We're only interested in the (random) filename. */
r = tempfn_random(path, NULL, &t);
if (r < 0)
return r;
- if (mkfifo(t, mode) < 0)
- return -errno;
-
- if (rename(t, path) < 0) {
- unlink_noerrno(t);
+ if (mkfifoat(atfd, t, mode) < 0)
return -errno;
- }
-
- return 0;
-}
-
-int mkfifoat_atomic(int dirfd, const char *path, mode_t mode) {
- _cleanup_free_ char *t = NULL;
- int r;
- assert(path);
-
- if (path_is_absolute(path))
- return mkfifo_atomic(path, mode);
-
- /* We're only interested in the (random) filename. */
- r = tempfn_random_child("", NULL, &t);
- if (r < 0)
+ r = RET_NERRNO(renameat(atfd, t, atfd, path));
+ if (r < 0) {
+ (void) unlinkat(atfd, t, 0);
return r;
-
- if (mkfifoat(dirfd, t, mode) < 0)
- return -errno;
-
- if (renameat(dirfd, t, dirfd, path) < 0) {
- unlink_noerrno(t);
- return -errno;
}
return 0;
return symlinkat_atomic_full(from, AT_FDCWD, to, false);
}
int mknod_atomic(const char *path, mode_t mode, dev_t dev);
-int mkfifo_atomic(const char *path, mode_t mode);
int mkfifoat_atomic(int dir_fd, const char *path, mode_t mode);
+static inline int mkfifo_atomic(const char *path, mode_t mode) {
+ return mkfifoat_atomic(AT_FDCWD, path, mode);
+}
int get_files_in_directory(const char *path, char ***list);