fix some posix file i/o bugs