Hacker News new | ask | show | jobs
by quotemstr 3026 days ago
> Sure, you can do this, but don't.

It was instructive. That said, there's nothing wrong in general with a class that owns a file descriptor, and making this class copy constructible as a legitimate design decision.

> Also worth noting that close (2), which presumably you'd call from the destructor, can fail with EIO or EINTR.

IO errors from close(2) should be ignored. If you care about durability, call fsync before you close. Even if close "fails" with an IO error, the underlying FD is still closed. EINTR does not actually happen.

See extensive discussion http://austingroupbugs.net/view.php?id=529