1 #ifndef OSMIUM_UTIL_FILE_HPP 2 #define OSMIUM_UTIL_FILE_HPP 40 #include <system_error> 42 #include <sys/types.h> 45 # ifndef WIN32_LEAN_AND_MEAN 46 # define WIN32_LEAN_AND_MEAN // Prevent winsock.h inclusion; avoid winsock2.h conflict 74 const auto size = ::_filelengthi64(fd);
76 throw std::system_error{errno, std::system_category(),
"Could not get file size"};
78 return static_cast<std::size_t
>(size);
82 if (::fstat(fd, &s) != 0) {
83 throw std::system_error{errno, std::system_category(),
"Could not get file size"};
85 return static_cast<std::size_t
>(s.st_size);
102 if (::_stati64(name, &s) != 0) {
103 throw std::system_error{errno, std::system_category(), std::string{
"Could not get file size of file '"} + name +
"'"};
108 if (::stat(name, &s) != 0) {
109 throw std::system_error{errno, std::system_category(), std::string{
"Could not get file size of file '"} + name +
"'"};
112 return static_cast<std::size_t
>(s.st_size);
138 if (::_chsize_s(fd, static_cast_with_assert<__int64>(new_size)) != 0) {
140 if (::ftruncate(fd, static_cast_with_assert<off_t>(new_size)) != 0) {
142 throw std::system_error{errno, std::system_category(),
"Could not resize file"};
154 return si.dwPageSize;
157 return static_cast<std::size_t
>(::sysconf(_SC_PAGESIZE));
170 const auto offset = _lseeki64(fd, 0, SEEK_CUR);
172 const auto offset = ::lseek(fd, 0, SEEK_CUR);
177 return static_cast<std::size_t
>(offset);
186 return _isatty(fd) != 0;
196 #endif // OSMIUM_UTIL_FILE_HPP std::size_t file_size(int fd)
Definition: file.hpp:70
bool isatty(int fd)
Definition: file.hpp:183
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
std::size_t get_pagesize()
Definition: file.hpp:149
std::size_t file_offset(int fd)
Definition: file.hpp:167
void resize_file(int fd, std::size_t new_size)
Definition: file.hpp:135