summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2019-02-19 12:16:41 +0100
committerMax Kellermann <max@musicpd.org>2019-02-19 12:16:41 +0100
commitdb144a43ad4b926cd9259f9353b9df2177710739 (patch)
tree7af21bc89d616b9ce3bbc0bcfc21696c8eb14420
parent5965f62b5693594ecdf6f16bc8e00c3bedd4da73 (diff)
system/Open: add OpenWriteOnly(), OpenDirectory()
-rw-r--r--src/system/Open.cxx34
-rw-r--r--src/system/Open.hxx14
2 files changed, 48 insertions, 0 deletions
diff --git a/src/system/Open.cxx b/src/system/Open.cxx
index ab8008c38..e7bea24a2 100644
--- a/src/system/Open.cxx
+++ b/src/system/Open.cxx
@@ -43,6 +43,30 @@ OpenReadOnly(const char *path)
return fd;
}
+UniqueFileDescriptor
+OpenWriteOnly(const char *path, int flags)
+{
+ UniqueFileDescriptor fd;
+ if (!fd.Open(path, O_WRONLY|flags))
+ throw FormatErrno("Failed to open '%s'", path);
+
+ return fd;
+}
+
+#ifndef _WIN32
+
+UniqueFileDescriptor
+OpenDirectory(const char *path, int flags)
+{
+ UniqueFileDescriptor fd;
+ if (!fd.Open(path, O_DIRECTORY|O_RDONLY|flags))
+ throw FormatErrno("Failed to open '%s'", path);
+
+ return fd;
+}
+
+#endif
+
#ifdef __linux__
UniqueFileDescriptor
@@ -76,6 +100,16 @@ OpenReadOnly(FileDescriptor directory, const char *name, int flags)
}
UniqueFileDescriptor
+OpenWriteOnly(FileDescriptor directory, const char *name, int flags)
+{
+ UniqueFileDescriptor fd;
+ if (!fd.Open(directory, name, O_WRONLY|flags))
+ throw FormatErrno("Failed to open '%s'", name);
+
+ return fd;
+}
+
+UniqueFileDescriptor
OpenDirectory(FileDescriptor directory, const char *name, int flags)
{
UniqueFileDescriptor fd;
diff --git a/src/system/Open.hxx b/src/system/Open.hxx
index af4e50bf5..8607a7975 100644
--- a/src/system/Open.hxx
+++ b/src/system/Open.hxx
@@ -36,6 +36,17 @@ class UniqueFileDescriptor;
UniqueFileDescriptor
OpenReadOnly(const char *path);
+UniqueFileDescriptor
+OpenWriteOnly(const char *path, int flags=0);
+
+
+#ifndef _WIN32
+
+UniqueFileDescriptor
+OpenDirectory(const char *name, int flags=0);
+
+#endif
+
#ifdef __linux__
UniqueFileDescriptor
@@ -48,6 +59,9 @@ UniqueFileDescriptor
OpenReadOnly(FileDescriptor directory, const char *name, int flags=0);
UniqueFileDescriptor
+OpenWriteOnly(FileDescriptor directory, const char *name, int flags=0);
+
+UniqueFileDescriptor
OpenDirectory(FileDescriptor directory, const char *name, int flags=0);
#endif