spectrum_remload/append_checksum.c

27 lines
435 B
C
Raw Permalink Normal View History

2024-11-10 17:12:49 +00:00
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
int fd;
unsigned char tally = 0;
unsigned char next = 0;
if (argc!=2) return -1;
fd = open(argv[1], O_RDWR|O_APPEND);
if (fd<0) return -2;
while (read(fd, &next, 1)) {
//printf("Tally: %X, next byte: %X\n", tally, next);
tally ^= next;
};
printf("Final tally: %X\n", tally);
write(fd, &tally, 1);
close(fd);
return 0;
}