#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2023 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_SUPPORT_PLATFORM_POSIXFILEAPI_H #define NUCLEX_SUPPORT_PLATFORM_POSIXFILEAPI_H #include "Nuclex/Support/Config.h" #if !defined(NUCLEX_SUPPORT_WINDOWS) #include // for std::string #include // for std::uint8_t #include // for FILE, ::fopen(), etc. namespace Nuclex { namespace Support { namespace Platform { // ------------------------------------------------------------------------------------------- // /// Wraps the Posix file system API /// /// /// This is a helper class that wraps Posix calls with error checking and conversion /// between C strings and C++ strings so that this boilerplate code does not have /// to be repeated over and over in other places. /// /// class PosixFileApi { /// Opens the specified file for shared reading /// Path of the file that will be opened /// A pointer representing the opened file public: static FILE *OpenFileForReading(const std::string &path); /// Creates or opens the specified file for exclusive writing /// Path of the file that will be opened /// A pointer representing the opened file public: static FILE *OpenFileForWriting(const std::string &path); /// Reads data from the specified file /// File from which data will be read /// Buffer into which the data will be put /// Number of bytes that will be read from the file /// The number of bytes that were actually read public: static std::size_t Read( FILE *file, std::uint8_t *buffer, std::size_t count ); /// Writes data into the specified file /// File into which data will be written /// Buffer containing the data that will be written /// Number of bytes that will be written into the file /// The number of bytes that were actually written public: static std::size_t Write( FILE *file, const std::uint8_t *buffer, std::size_t count ); /// Flushes all buffered output to the hard drive /// File for whose buffered output will be flushed public: static void Flush(FILE *file); /// Closes the specified file /// File pointer returned by the open method /// /// Whether to throw an exception if the file cannot be closed /// public: static void Close(FILE *file, bool throwOnError = true); }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Support::Platform #endif // !defined(NUCLEX_SUPPORT_WINDOWS) #endif // NUCLEX_SUPPORT_PLATFORM_POSIXFILEAPI_H