diff options
author | Max Kellermann <max@musicpd.org> | 2017-08-10 19:32:17 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2017-08-10 19:34:52 +0200 |
commit | df5cc3f0f6abda2854ef3074d98cc241f805e36e (patch) | |
tree | 319e9c52602269731c22d5bb102bc800f76c6ff1 /src/unix | |
parent | eb0ff32efb9f5220d1d7baf01078540e1e4d027e (diff) |
fs/FileSystem: OpenFile() returns UniqueFileDescriptor
Diffstat (limited to 'src/unix')
-rw-r--r-- | src/unix/PidFile.hxx | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/unix/PidFile.hxx b/src/unix/PidFile.hxx index 0cb476755..80e073c22 100644 --- a/src/unix/PidFile.hxx +++ b/src/unix/PidFile.hxx @@ -38,7 +38,7 @@ public: if (path.IsNull()) return; - fd = OpenFile(path, O_WRONLY|O_CREAT|O_TRUNC, 0666); + fd = OpenFile(path, O_WRONLY|O_CREAT|O_TRUNC, 0666).Steal(); if (fd < 0) { const std::string utf8 = path.ToUTF8(); FormatFatalSystemError("Failed to create pid file \"%s\"", @@ -90,14 +90,14 @@ gcc_pure static inline pid_t ReadPidFile(Path path) noexcept { - int fd = OpenFile(path, O_RDONLY, 0); - if (fd < 0) + auto fd = OpenFile(path, O_RDONLY, 0); + if (!fd.IsDefined()) return -1; pid_t pid = -1; char buffer[32]; - auto nbytes = read(fd, buffer, sizeof(buffer) - 1); + auto nbytes = fd.Read(buffer, sizeof(buffer) - 1); if (nbytes > 0) { buffer[nbytes] = 0; @@ -107,7 +107,6 @@ ReadPidFile(Path path) noexcept pid = value; } - close(fd); return pid; } |