re-apply fixes needed for mingw
(http://sourceforge.net/p/mingw-w64/mailman/mingw-w64-public/thread/AANLkTinrq34UOHsUS7mZt82wepv_SvttNedd4xwm-JqU@mail.gmail.com/)