libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / tools / fixup_tos_boot_checksum / fixup_tos_boot_checksum.c
blob60f8109936a0910e6c53e2ca61a314b26f2ca9ba
1 #include <fcntl.h>
2 #include <stdio.h>
3 #include <stdint.h>
4 #include <unistd.h>
6 uint8_t sector[512];
8 int main(int argc, char **argv)
10 int fd, i;
11 uint16_t sum;
12 uint8_t *p = sector;
13 fd = open(argv[1], O_RDWR);
14 if (fd < 0) {
15 return 1;
17 if (read(fd, sector, 512-2) < 512-2) {
18 perror("read");
19 return 1;
21 for (sum = 0, i = 0; i < (512-2)/2; i++) {
22 uint16_t v;
23 v = *p++ << 8;
24 v += *p++;
25 sum += v;
27 sum = 0x1234 - sum /*+ 1*/;
28 //sum = 0xaa55;
29 // big endian
30 *p++ = (uint8_t)(sum >> 8);
31 *p++ = (uint8_t)sum;
32 //lseek(fd, 0LL, SEEK_SET);
33 write(fd, &sector[512-2], 2);
34 close(fd);
35 return 0;