diff options
author | Max Kellermann <max@musicpd.org> | 2018-10-31 17:10:52 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-10-31 17:10:52 +0100 |
commit | c60cf944f55a59dd668ebb3627476629e6e967c7 (patch) | |
tree | 6150bd8b4a8b53930e4a4fcfa1602fd0d45fbffe | |
parent | 4b8ee586381ead890ad64110cf13aae151ce102a (diff) |
fs/io/FileOutputStream: add macro HAVE_O_TMPFILE
-rw-r--r-- | src/fs/io/FileOutputStream.cxx | 12 | ||||
-rw-r--r-- | src/fs/io/FileOutputStream.hxx | 6 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/fs/io/FileOutputStream.cxx b/src/fs/io/FileOutputStream.cxx index f76a44e5d..c1cb69840 100644 --- a/src/fs/io/FileOutputStream.cxx +++ b/src/fs/io/FileOutputStream.cxx @@ -138,7 +138,7 @@ FileOutputStream::Cancel() noexcept #include <unistd.h> #include <errno.h> -#ifdef __linux__ +#ifdef HAVE_O_TMPFILE #ifndef O_TMPFILE /* supported since Linux 3.11 */ #define __O_TMPFILE 020000000 @@ -159,12 +159,12 @@ OpenTempFile(FileDescriptor &fd, Path path) return fd.Open(directory.c_str(), O_TMPFILE|O_WRONLY, 0666); } -#endif /* __linux__ */ +#endif /* HAVE_O_TMPFILE */ inline void FileOutputStream::OpenCreate(bool visible) { -#ifdef __linux__ +#ifdef HAVE_O_TMPFILE /* try Linux's O_TMPFILE first */ is_tmpfile = !visible && OpenTempFile(fd, GetPath()); if (!is_tmpfile) { @@ -175,7 +175,7 @@ FileOutputStream::OpenCreate(bool visible) 0666)) throw FormatErrno("Failed to create %s", GetPath().c_str()); -#ifdef __linux__ +#ifdef HAVE_O_TMPFILE } #else (void)visible; @@ -218,7 +218,7 @@ FileOutputStream::Commit() { assert(IsDefined()); -#ifdef __linux__ +#ifdef HAVE_O_TMPFILE if (is_tmpfile) { unlink(GetPath().c_str()); @@ -251,7 +251,7 @@ FileOutputStream::Cancel() noexcept switch (mode) { case Mode::CREATE: -#ifdef __linux__ +#ifdef HAVE_O_TMPFILE if (!is_tmpfile) #endif unlink(GetPath().c_str()); diff --git a/src/fs/io/FileOutputStream.hxx b/src/fs/io/FileOutputStream.hxx index 1b5507223..08ffef2d6 100644 --- a/src/fs/io/FileOutputStream.hxx +++ b/src/fs/io/FileOutputStream.hxx @@ -46,6 +46,10 @@ #include <windows.h> #endif +#ifdef __linux__ +#define HAVE_O_TMPFILE +#endif + class Path; class FileOutputStream final : public OutputStream { @@ -57,7 +61,7 @@ class FileOutputStream final : public OutputStream { FileDescriptor fd = FileDescriptor::Undefined(); #endif -#ifdef __linux__ +#ifdef HAVE_O_TMPFILE /** * Was O_TMPFILE used? If yes, then linkat() must be used to * create a link to this file. |