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, | ||||
|                               tabby_printer_packet *header, | ||||
|                               void *body, | ||||
|                               uint16_t *checksum); | ||||
|                               void *body); | ||||
| 
 | ||||
| /*
 | ||||
|  * 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, | ||||
|                               tabby_printer_packet *header, | ||||
|                               void *body, | ||||
|                               uint16_t *sum) { | ||||
|                               void *body) { | ||||
|     ssize_t len; | ||||
| 
 | ||||
|     size_t i = 0, | ||||
|  | @ -35,9 +34,9 @@ int tabby_printer_packet_recv(int fd, | |||
| 
 | ||||
|     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) { | ||||
|         if (i == 0) { | ||||
|  | @ -72,12 +71,12 @@ int tabby_printer_packet_recv(int fd, | |||
|         } else if (b < header->size) { | ||||
|             ((uint8_t *)body)[b++] = value; | ||||
|         } else if (b == header->size) { | ||||
|             *sum = value; | ||||
|             sum = value; | ||||
|             b++; | ||||
|         } else if (b == header->size + 1) { | ||||
|             *sum |= value << 8; | ||||
|             sum |= value << 8; | ||||
| 
 | ||||
|             if (checksum(header, body) != *sum) { | ||||
|             if (checksum(header, body) != sum) { | ||||
|                 errno = EIO; | ||||
| 
 | ||||
|                 goto error_io; | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue