Make tnc_buffer() only return bytes actually read

This commit is contained in:
XANTRONIX Development 2015-07-15 21:45:46 -05:00
parent e7b1c2cf54
commit 6a427c4097

View file

@ -68,14 +68,14 @@ void patty_kiss_tnc_close(patty_kiss_tnc *tnc) {
}
static ssize_t tnc_buffer(patty_kiss_tnc *tnc) {
size_t fillsz = tnc->bufsz - tnc->buflen;
size_t fillsz = tnc->bufsz - tnc->buflen;
ssize_t readlen = 0;
/*
* If the buffer needs to be filled, then fill it.
*/
if (fillsz) {
void *dest = ((unsigned char *)tnc->buf) + tnc->buflen;
ssize_t readlen;
if ((readlen = read(tnc->fd, dest, fillsz)) < 0) {
errno = EIO;
@ -86,7 +86,7 @@ static ssize_t tnc_buffer(patty_kiss_tnc *tnc) {
tnc->buflen += readlen;
}
return tnc->buflen;
return readlen;
error_io:
return -1;