io.c: make IO#reopen("pathname") atomic

* io.c (rb_io_reopen): create a new, temporary FD via rb_sysopen and
  call rb_cloexec_dup2 on it to atomically replace the file fptr->fd
  points to.  This leaves no possible window where fptr->fd is invalid
  to userspace (even for any threads running w/o GVL).  based on the
  patch by Eric Wong <normalperson@yhbt.net> at [ruby-core:57943].
  [Bug #9036]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e