13 #ifndef __STOUT_OS_READ_HPP__ 14 #define __STOUT_OS_READ_HPP__ 24 #if defined(__sun) || defined(__WINDOWS__) 26 #endif // __sun || __WINDOWS__ 57 char* buffer =
new char[
size];
60 while (offset < size) {
81 }
else if (length == 0) {
85 std::string result(buffer, offset);
96 std::string result(buffer, size);
107 std::ifstream
file(path.c_str());
108 if (!
file.is_open()) {
112 return std::string((std::istreambuf_iterator<char>(
file)),
113 (std::istreambuf_iterator<char>()));
116 #elif defined(__WINDOWS__) 125 std::ifstream
file(longpath.data());
126 if (!
file.is_open()) {
127 return Error(
"Failed to open file");
130 return std::string((std::istreambuf_iterator<char>(
file)),
131 (std::istreambuf_iterator<char>()));
136 FILE*
file = ::fopen(path.c_str(),
"r");
137 if (file ==
nullptr) {
147 char* buffer =
new char[BUFSIZ];
151 size_t read = ::fread(buffer, 1, BUFSIZ, file);
153 if (::ferror(file)) {
162 result.append(buffer, read);
164 if (read != BUFSIZ) {
174 #endif // __sun || __WINDOWS__ 178 #endif // __STOUT_OS_READ_HPP__ SSIZE_T ssize_t
Definition: windows.hpp:186
Definition: errorbase.hpp:36
Try< Bytes > size(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:130
Definition: error.hpp:108
Definition: errorbase.hpp:50
Definition: posix_signalhandler.hpp:23
bool is_restartable_error(int error)
Definition: socket.hpp:65
URI file(const std::string &path)
Creates a file URI with the given path on the local host.
Definition: file.hpp:33
Result< std::string > read(int_fd fd, size_t size)
Definition: read.hpp:55
std::string error(const std::string &msg, uint32_t code)
const int code
Definition: errorbase.hpp:63
std::wstring longpath(const std::string &path)
Definition: longpath.hpp:38
int int_fd
Definition: int_fd.hpp:35