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

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