2 Copyright (C) 2022 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 libdcp is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libdcp. If not, see <http://www.gnu.org/licenses/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
39 #include <boost/filesystem/path.hpp>
45 /** A wrapper for stdio files that gives RAII and allows us to open files with
46 * UTF-8 names on Windows.
51 /** @param path Path to open
52 * @param mode mode flags, as for fopen(3)
54 File(boost::filesystem::path, std::string mode);
57 File& operator=(File&& other);
61 File(File const&) = delete;
62 File& operator=(File const&) = delete;
64 operator bool() const;
66 /** fwrite() wrapper */
67 size_t write(const void *ptr, size_t size, size_t nmemb);
68 /** fread() wrapper */
69 size_t read(void *ptr, size_t size, size_t nmemb);
72 /** fgets() wrapper */
73 char *gets(char *s, int size);
74 /** fputs() wrapper */
75 int puts(char const *s);
76 /** fseek/fseeki64 wrapper */
77 int seek(int64_t offset, int whence);
78 /** ftell/ftelli64 wrapper */
83 void checked_write(void const * ptr, size_t size);
84 void checked_read(void* ptr, size_t size);
86 /** Close the file; it is not necessary to call this as the
87 * destructor will do it if required.
91 boost::filesystem::path path() const {
95 /** Take ownership of the underlying FILE*;
96 * the File object will not closed it after this call.
104 /** @return Error returned by the fopen / _wfopen call;
105 * errno on POSIX, GetLastError() on Windows.
107 int open_error() const {
112 boost::filesystem::path _path;
113 FILE* _file = nullptr;