write2 modified for MSVC C89 compliance