13 #ifndef __STOUT_OS_READ_HPP__
14 #define __STOUT_OS_READ_HPP__
24 #if defined(__sun) || defined(__WINDOWS__)
26 #endif // __sun || __WINDOWS__
52 char* buffer =
new char[
size];
55 while (offset < size) {
59 int error = WSAGetLastError();
72 }
else if (length == 0) {
76 std::string result(buffer, offset);
87 std::string result(buffer, size);
95 #if defined(__sun) || defined(__WINDOWS__)
98 std::ifstream
file(path.c_str());
99 if (!
file.is_open()) {
103 return std::string((std::istreambuf_iterator<char>(
file)),
104 (std::istreambuf_iterator<char>()));
109 FILE*
file = ::fopen(path.c_str(),
"r");
110 if (file ==
nullptr) {
120 char* buffer =
new char[BUFSIZ];
124 size_t read = ::fread(buffer, 1, BUFSIZ, file);
126 if (::ferror(file)) {
135 result.append(buffer, read);
137 if (read != BUFSIZ) {
147 #endif // __sun || __WINDOWS__
151 #endif // __STOUT_OS_READ_HPP__
SSIZE_T ssize_t
Definition: windows.hpp:192
Try< Bytes > size(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:100
Definition: errorbase.hpp:49
Definition: result.hpp:40
bool is_restartable_error(int error)
Definition: socket.hpp:33
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:50
std::string error(const std::string &msg, uint32_t code)
int int_fd
Definition: int_fd.hpp:35