linebuf for non _GNU_SOURCE: rewrite and tested on msvc