diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2021-01-27 22:06:49 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2021-01-27 22:06:49 +0100 |
| commit | 06950aab233de6a2f47293d59575bb42f6131660 (patch) | |
| tree | 62f6eed4a6d35414f656d22b9ac7420849018a11 /src/unique_fd.cc | |
| parent | 1ef9c463f1efc1adfb62e42ab3dd17e8c6394373 (diff) | |
Complete rewrite using C++ and with shared state support
Diffstat (limited to 'src/unique_fd.cc')
| -rw-r--r-- | src/unique_fd.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/unique_fd.cc b/src/unique_fd.cc new file mode 100644 index 0000000..a289f0e --- /dev/null +++ b/src/unique_fd.cc @@ -0,0 +1,17 @@ +#include "common.hh" + +#include "unique_fd.hh" + +#include <unistd.h> + +void unique_fd::reset(int fd) { + if (fd_ >= 0) + close(fd_); + fd_ = fd; +} + +unique_fd unique_fd::dup() { + if (fd_ >= 0) + return unique_fd(::dup(fd_)); + return unique_fd(); +} |
