#include #include #include #include #include #include #include static ssize_t hexdump_line(off_t offset, void *buf, size_t len, int tty, FILE *stream) { size_t i; if (printf("%08zx: ", offset) < 0) { goto error_io; } for (i=0; i 0 && (i % ZX81_HEXDUMP_STRIDE_GROUP) == 0) { if (fputc(' ', stream) < 0) { goto error_io; } } if (fprintf(stream, "%02x", ((uint8_t *)buf)[offset+i]) < 0) { goto error_io; } } if (fputs(" ", stream) < 0) { goto error_io; } for (i=0; i= 0xa0 && c <= 0xbf) { if (zx81_fputc(c - 0xa0, tty, stream) < 0) { goto error_io; } } else { if (fputc('.', stream) < 0) { goto error_io; } } } if (fputc('\n', stream) < 0) { goto error_io; } return fflush(stream); error_io: return -1; } ssize_t zx81_hexdump(int fd, FILE *stream) { void *buf; ssize_t total = 0; int tty = isatty(fileno(stdout)); struct stat st; if (fstat(fd, &st) < 0) { goto error_fstat; } if ((buf = malloc(st.st_blksize)) == NULL) { goto error_malloc; } while (1) { ssize_t len, i; off_t offset = 0; if ((len = read(fd, buf, st.st_blksize)) < 0) { goto error_read; } else if (len == 0) { break; } for (i=0; i