aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsafu9 <30684866+safu9@users.noreply.github.com>2018-10-11 01:25:02 +0900
committerStephen F. Booth <me@sbooth.org>2018-10-10 12:25:02 -0400
commit036a0317b928f74de63fb197a29dc8e0e1e8cf4f (patch)
tree25557771309434e4a283bfe86f847030110c1de4
parent8f6fe0b16c59f8dcc0b55ff567829a03b2207cd2 (diff)
Add support for file descriptor to FileStream (#832)
Add support for file descriptor
-rw-r--r--taglib/toolkit/tfilestream.cpp29
-rw-r--r--taglib/toolkit/tfilestream.h5
2 files changed, 34 insertions, 0 deletions
diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp
index 17a09f3d..7e75e396 100644
--- a/taglib/toolkit/tfilestream.cpp
+++ b/taglib/toolkit/tfilestream.cpp
@@ -58,6 +58,11 @@ namespace
#endif
}
+ FileHandle openFile(const int fileDescriptor, bool readOnly)
+ {
+ return InvalidFileHandle;
+ }
+
void closeFile(FileHandle file)
{
CloseHandle(file);
@@ -98,6 +103,11 @@ namespace
return fopen(path, readOnly ? "rb" : "rb+");
}
+ FileHandle openFile(const int fileDescriptor, bool readOnly)
+ {
+ return fdopen(fileDescriptor, readOnly ? "rb" : "rb+");
+ }
+
void closeFile(FileHandle file)
{
fclose(file);
@@ -158,6 +168,25 @@ FileStream::FileStream(FileName fileName, bool openReadOnly)
}
}
+FileStream::FileStream(int fileDescriptor, bool openReadOnly)
+ : d(new FileStreamPrivate(""))
+{
+ // First try with read / write mode, if that fails, fall back to read only.
+
+ if(!openReadOnly)
+ d->file = openFile(fileDescriptor, false);
+
+ if(d->file != InvalidFileHandle)
+ d->readOnly = false;
+ else
+ d->file = openFile(fileDescriptor, true);
+
+ if(d->file == InvalidFileHandle)
+ {
+ debug("Could not open file using file descriptor");
+ }
+}
+
FileStream::~FileStream()
{
if(isOpen())
diff --git a/taglib/toolkit/tfilestream.h b/taglib/toolkit/tfilestream.h
index 96a476d6..aa4d71b3 100644
--- a/taglib/toolkit/tfilestream.h
+++ b/taglib/toolkit/tfilestream.h
@@ -55,6 +55,11 @@ namespace TagLib {
FileStream(FileName file, bool openReadOnly = false);
/*!
+ * Construct a File object and opens the \a file using file descriptor.
+ */
+ FileStream(int fileDescriptor, bool openReadOnly = false);
+
+ /*!
* Destroys this FileStream instance.
*/
virtual ~FileStream();