MFC r305406,r305409,r305412
1) Fix errors handling.
2) Prevent out of bounds access to ws[-1] (passed buffer) which happens
when the first mb sequence is incomplete and there are not enougn chars in
the read buffer. ws[-1] may lead to memory faults or false results, in
case the memory here contains '\n'.
3) Fix n == 1 case. Here should be no physical read (fill buffer) attempt
(we read n - 1 chars with the room for NUL, see fgets()),
and no NULL return.
git-svn-id: svn://svn.freebsd.org/base/stable/10@305577
ccf9f872-aa2e-dd11-9fc8-
001c23d0bc1f