#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2021 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_STORAGE_FILESYSTEM_POSIX_POSIXFILEAPI_H #define NUCLEX_STORAGE_FILESYSTEM_POSIX_POSIXFILEAPI_H #include "Nuclex/Storage/Config.h" #if !defined(NUCLEX_STORAGE_WIN32) #include // for std::string #include // for std::uint8_t #include // for FILE, ::fopen(), etc. namespace Nuclex { namespace Storage { namespace FileSystem { // ------------------------------------------------------------------------------------------- // /// 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); /// 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); /// 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 ); /// Moves the file cursor for the specified file /// File whose file cursor will be moved /// Location the file cursor will be moved to public: static void Seek(FILE *file, std::uint64_t location); /// Retrieves the current position of the file cursor /// File whose cursor position will be retrieved /// The current position of the file cursor in the specified file>/returns> public: static std::uint64_t Tell(FILE *file); }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Storage::FileSystem #endif // !defined(NUCLEX_STORAGE_WIN32) #endif // NUCLEX_STORAGE_FILESYSTEM_POSIX_POSIXFILEAPI_H