summaryrefslogtreecommitdiff
path: root/cpp/examples/all_functions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/examples/all_functions.cpp')
-rw-r--r--cpp/examples/all_functions.cpp23
1 files changed, 6 insertions, 17 deletions
diff --git a/cpp/examples/all_functions.cpp b/cpp/examples/all_functions.cpp
index 326ae39..5081e83 100644
--- a/cpp/examples/all_functions.cpp
+++ b/cpp/examples/all_functions.cpp
@@ -15,24 +15,13 @@ public:
}
~FdReader() { close(m_fd); }
size_t read(char *buf, size_t size) {
- size_t total_read = 0;
- while (true) {
- // must call read in a loop to fill buf up as much as possible!
- // (read isn't guaranteed to read len bytes even if it could)
- ssize_t ret = ::read(m_fd, buf, size);
- if (ret < 0) {
- // read error
- throw "read error";
- } else if (ret == 0) {
- // end-of-file
- break;
- } else {
- total_read += ret;
- buf += ret;
- size -= ret;
- }
+ ssize_t ret = ::read(m_fd, buf, size);
+ if (ret < 0) {
+ // read error
+ throw "read error";
+ } else {
+ return ret;
}
- return total_read;
}
private:
int m_fd;