diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2014-02-04 23:18:54 -0800 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2014-02-06 11:18:37 -0800 |
commit | 9215c35975be745628e8188473154c7e476add55 (patch) | |
tree | 14d4f5d51381f8a59803233c24dfafc846ddf583 /src/io/read.cpp | |
parent | 9544985ccbb20d7f8377c63a4e59d1ff97b844ac (diff) | |
download | tmwa-9215c35975be745628e8188473154c7e476add55.tar.gz tmwa-9215c35975be745628e8188473154c7e476add55.tar.bz2 tmwa-9215c35975be745628e8188473154c7e476add55.tar.xz tmwa-9215c35975be745628e8188473154c7e476add55.zip |
Wrap remaining FDs in a class
Diffstat (limited to 'src/io/read.cpp')
-rw-r--r-- | src/io/read.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/io/read.cpp b/src/io/read.cpp index 146ba81..fe2c765 100644 --- a/src/io/read.cpp +++ b/src/io/read.cpp @@ -32,31 +32,31 @@ namespace io { - ReadFile::ReadFile(int f) + ReadFile::ReadFile(FD f) : fd(f), start(0), end(0) { } ReadFile::ReadFile(ZString name) - : fd(open(name.c_str(), O_RDONLY | O_CLOEXEC)), start(0), end(0) + : fd(FD::open(name, O_RDONLY | O_CLOEXEC)), start(0), end(0) { } ReadFile::~ReadFile() { - close(fd); - fd = -1; + fd.close(); + fd = FD(); } bool ReadFile::get(char& c) { if (start == end) { - if (fd == -1) + if (fd == FD()) return false; - ssize_t rv = read(fd, &buf, sizeof(buf)); + ssize_t rv = fd.read(&buf, sizeof(buf)); if (rv == 0 || rv == -1) { - close(fd); - fd = -1; + fd.close(); + fd = FD(); return false; } start = 0; @@ -117,6 +117,6 @@ namespace io bool ReadFile::is_open() { - return fd != -1; + return fd != FD(); } } // namespace io |