mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-15 00:37:13 +02:00

- Consistent use of ssize_t to avoid issues on 32 bit platforms and also mac with (long long int as ssize_t)
30 lines
769 B
C++
30 lines
769 B
C++
#pragma once
|
|
#include <cstdio>
|
|
#include <filesystem>
|
|
|
|
namespace aare {
|
|
|
|
/**
|
|
* \brief RAII wrapper for FILE pointer
|
|
*/
|
|
class FilePtr {
|
|
FILE *fp_{nullptr};
|
|
|
|
public:
|
|
FilePtr() = default;
|
|
FilePtr(const std::filesystem::path& fname, const std::string& mode);
|
|
FilePtr(const FilePtr &) = delete; // we don't want a copy
|
|
FilePtr &operator=(const FilePtr &) = delete; // since we handle a resource
|
|
FilePtr(FilePtr &&other);
|
|
FilePtr &operator=(FilePtr &&other);
|
|
FILE *get();
|
|
ssize_t tell();
|
|
void seek(ssize_t offset, int whence = SEEK_SET) {
|
|
if (fseek(fp_, offset, whence) != 0)
|
|
throw std::runtime_error("Error seeking in file");
|
|
}
|
|
std::string error_msg();
|
|
~FilePtr();
|
|
};
|
|
|
|
} // namespace aare
|