Use uint8_t instead of unsigned char in src/kiss.c

This commit is contained in:
XANTRONIX Development 2020-05-26 23:41:39 -04:00 committed by XANTRONIX Industrial
parent 4d9c45ad94
commit de0c0ef844

View file

@ -1,5 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <inttypes.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
@ -84,7 +85,7 @@ ssize_t patty_kiss_tnc_buffer(patty_kiss_tnc *tnc) {
* 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 = ((uint8_t *)tnc->buf) + tnc->buflen;
if ((readlen = read(tnc->fd, dest, fillsz)) < 0) { if ((readlen = read(tnc->fd, dest, fillsz)) < 0) {
errno = EIO; errno = EIO;
@ -116,7 +117,7 @@ ssize_t patty_kiss_tnc_decode(patty_kiss_tnc *tnc, void *frame, size_t *len, int
* and whatnot. * and whatnot.
*/ */
for (i=0, b=0; i<tnc->buflen; i++) { for (i=0, b=0; i<tnc->buflen; i++) {
unsigned char c = ((unsigned char *)tnc->buf)[i]; uint8_t c = ((uint8_t *)tnc->buf)[i];
/* /*
* If the first byte is not a frame end, then that's a bad thing. * If the first byte is not a frame end, then that's a bad thing.
@ -153,9 +154,9 @@ ssize_t patty_kiss_tnc_decode(patty_kiss_tnc *tnc, void *frame, size_t *len, int
if (flags & KISS_ESCAPE) { if (flags & KISS_ESCAPE) {
if (c == PATTY_KISS_TFEND) { if (c == PATTY_KISS_TFEND) {
((unsigned char *)frame)[b++] = PATTY_KISS_FEND; ((uint8_t *)frame)[b++] = PATTY_KISS_FEND;
} else if (c == PATTY_KISS_TFESC) { } else if (c == PATTY_KISS_TFESC) {
((unsigned char *)frame)[b++] = PATTY_KISS_FESC; ((uint8_t *)frame)[b++] = PATTY_KISS_FESC;
} else { } else {
errno = EIO; errno = EIO;
@ -176,7 +177,7 @@ ssize_t patty_kiss_tnc_decode(patty_kiss_tnc *tnc, void *frame, size_t *len, int
break; break;
} }
((unsigned char *)frame)[b++] = c; ((uint8_t *)frame)[b++] = c;
} }
} }
@ -215,7 +216,7 @@ void patty_kiss_tnc_flush(patty_kiss_tnc *tnc, size_t len) {
* Move everything from the buffer not processed up to this point, to the * Move everything from the buffer not processed up to this point, to the
* beginning of the buffer. * beginning of the buffer.
*/ */
memmove(tnc->buf, ((unsigned char *)tnc->buf) + len, tnc->buflen - len); memmove(tnc->buf, ((uint8_t *)tnc->buf) + len, tnc->buflen - len);
/* /*
* Then, decrement the buffer length by the number of bytes already * Then, decrement the buffer length by the number of bytes already
@ -270,7 +271,7 @@ error_io:
return -1; return -1;
} }
static inline ssize_t write_byte(int fd, unsigned char c) { static inline ssize_t write_byte(int fd, uint8_t c) {
return write(fd, &c, sizeof(c)); return write(fd, &c, sizeof(c));
} }
@ -278,8 +279,8 @@ static inline ssize_t write_command(int fd, int command, int port) {
return write_byte(fd, ((port & 0x0f) << 4) | (command & 0x0f)); return write_byte(fd, ((port & 0x0f) << 4) | (command & 0x0f));
} }
static unsigned char escape_fend[2] = { PATTY_KISS_FESC, PATTY_KISS_TFEND }; static uint8_t escape_fend[2] = { PATTY_KISS_FESC, PATTY_KISS_TFEND };
static unsigned char escape_fesc[2] = { PATTY_KISS_FESC, PATTY_KISS_TFESC }; static uint8_t escape_fesc[2] = { PATTY_KISS_FESC, PATTY_KISS_TFESC };
ssize_t patty_kiss_tnc_send(patty_kiss_tnc *tnc, const void *buf, size_t len, int port) { ssize_t patty_kiss_tnc_send(patty_kiss_tnc *tnc, const void *buf, size_t len, int port) {
size_t i, start = 0, end = 0; size_t i, start = 0, end = 0;
@ -293,8 +294,8 @@ ssize_t patty_kiss_tnc_send(patty_kiss_tnc *tnc, const void *buf, size_t len, in
} }
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
unsigned char c = ((unsigned char *)buf)[i]; uint8_t c = ((uint8_t *)buf)[i];
unsigned char *escape = NULL; uint8_t *escape = NULL;
switch (c) { switch (c) {
case PATTY_KISS_FEND: { case PATTY_KISS_FEND: {
@ -317,7 +318,7 @@ ssize_t patty_kiss_tnc_send(patty_kiss_tnc *tnc, const void *buf, size_t len, in
} }
if (escape) { if (escape) {
if (write(tnc->fd, ((unsigned char *)buf) + start, end - start) < 0) { if (write(tnc->fd, ((uint8_t *)buf) + start, end - start) < 0) {
goto error_io; goto error_io;
} }
@ -332,7 +333,7 @@ ssize_t patty_kiss_tnc_send(patty_kiss_tnc *tnc, const void *buf, size_t len, in
} }
if (end - start) { if (end - start) {
if (write(tnc->fd, ((unsigned char *)buf) + start, end - start) < 0) { if (write(tnc->fd, ((uint8_t *)buf) + start, end - start) < 0) {
goto error_io; goto error_io;
} }
} }