core: Ensure that ap_*getline*() return NUL terminated lines on any error. This was done only on buffer full, so be consistent, and fail early if the given buffer can't even hold the NUL bytes (negative or nul size).