No need to pass checksum to tabby_printer_packet_recv() caller
This commit is contained in:
parent
a7ba26c6db
commit
7562ab6870
2 changed files with 7 additions and 9 deletions
|
@ -36,8 +36,7 @@ typedef struct _tabby_printer_packet {
|
||||||
*/
|
*/
|
||||||
int tabby_printer_packet_recv(int fd,
|
int tabby_printer_packet_recv(int fd,
|
||||||
tabby_printer_packet *header,
|
tabby_printer_packet *header,
|
||||||
void *body,
|
void *body);
|
||||||
uint16_t *checksum);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For sending printer data packets to a Game Boy Printer
|
* For sending printer data packets to a Game Boy Printer
|
||||||
|
|
|
@ -26,8 +26,7 @@ static uint16_t checksum(tabby_printer_packet *header, void *body) {
|
||||||
|
|
||||||
int tabby_printer_packet_recv(int fd,
|
int tabby_printer_packet_recv(int fd,
|
||||||
tabby_printer_packet *header,
|
tabby_printer_packet *header,
|
||||||
void *body,
|
void *body) {
|
||||||
uint16_t *sum) {
|
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
|
||||||
size_t i = 0,
|
size_t i = 0,
|
||||||
|
@ -35,9 +34,9 @@ int tabby_printer_packet_recv(int fd,
|
||||||
|
|
||||||
uint8_t value;
|
uint8_t value;
|
||||||
|
|
||||||
memset(header, '\0', sizeof(*header));
|
uint16_t sum = 0;
|
||||||
|
|
||||||
*sum = 0;
|
memset(header, '\0', sizeof(*header));
|
||||||
|
|
||||||
while ((len = read(fd, &value, 1)) >= 0) {
|
while ((len = read(fd, &value, 1)) >= 0) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
|
@ -72,12 +71,12 @@ int tabby_printer_packet_recv(int fd,
|
||||||
} else if (b < header->size) {
|
} else if (b < header->size) {
|
||||||
((uint8_t *)body)[b++] = value;
|
((uint8_t *)body)[b++] = value;
|
||||||
} else if (b == header->size) {
|
} else if (b == header->size) {
|
||||||
*sum = value;
|
sum = value;
|
||||||
b++;
|
b++;
|
||||||
} else if (b == header->size + 1) {
|
} else if (b == header->size + 1) {
|
||||||
*sum |= value << 8;
|
sum |= value << 8;
|
||||||
|
|
||||||
if (checksum(header, body) != *sum) {
|
if (checksum(header, body) != sum) {
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
|
|
||||||
goto error_io;
|
goto error_io;
|
||||||
|
|
Loading…
Add table
Reference in a new issue