Add ::take().
authorCarl Hetherington <cth@carlh.net>
Wed, 13 Apr 2022 21:30:26 +0000 (23:30 +0200)
committerCarl Hetherington <cth@carlh.net>
Thu, 5 May 2022 19:46:30 +0000 (21:46 +0200)
src/file.cc
src/file.h

index 8759c7c176ff131b146aef66ca09ff1b677bc690..f7c865b221141b3735d0d10ee68c5aa0327ae539 100644 (file)
@@ -134,6 +134,15 @@ File::checked_read(void* ptr, size_t size)
 }
 
 
+FILE*
+File::take()
+{
+       auto give = _file;
+       _file = nullptr;
+       return give;
+}
+
+
 /** Windows can't "by default" cope with paths longer than 260 characters, so if you pass such a path to
  *  any boost::filesystem method it will fail.  There is a "fix" for this, which is to prepend
  *  the string \\?\ to the path.  This will make it work, so long as:
index e0564cae438f7231f2f27227cfed4767f38a9880..7dae44a61ec29ad9ddcf9b3fa1b8c782025d1dc9 100644 (file)
@@ -72,6 +72,15 @@ public:
         */
        void close();
 
+       boost::filesystem::path path() const {
+               return _path;
+       }
+
+       /** Take ownership of the underlying FILE*;
+        *  the File object will not closed it after this call.
+        */
+       FILE* take();
+
 private:
        boost::filesystem::path _path;
        FILE* _file = nullptr;