I'm not trying to dodge it, I was trying to see if you would come to the realisation as I did.
What happens to this code when f() throws?
That's why we use objects with destructors.Code:template <typename Func> void unbuffered_io_call(Func f) { termio curr, old; ::ioctl(0, TCGETA, &curr); old = curr; curr.c_lflag = 0; curr.c_iflag = 0; curr.c_cc[VMIN] = 1; curr.c_cc[VTIME] = 0; ::ioctl(0, TCSETA, &curr); f(); ::ioctl(0, TCSETA, &old_); }
Bookmarks