/* Hopefully there aren't arches with PAGE_SIZE > 64k */
#define G_mapsize (64*1024)
-/* "12ef5670 (nn )*16 abcdef_1_3_5_7_9\n" */
-#define LINEBUF_SIZE (8 + 1 + 3*16 + 16 + 1 /*paranoia:*/ + 14)
+/* "12ef5670 (xx )*16 _1_3_5_7_9abcdef\n"NUL */
+#define LINEBUF_SIZE (8 + 1 + 3*16 + 16 + 1 + 1 /*paranoia:*/ + 13)
static int format_line(char *hex, uint8_t *data, off_t offset)
{
pagesize = getpagesize(); /* constant on most arches */
pos = G.current_byte - G.addr;
if (pos >= pagesize) {
- /* Move offset up until current position is in 1st page */
+ /* move offset up until current position is in 1st page */
do {
G.offset += pagesize;
if (G.offset == 0) { /* whoops */
pagesize = getpagesize(); /* constant on most arches */
pos = G.current_byte - G.addr;
- /* Move offset down until current position is in last page */
+ /* move offset down until current position is in last page */
pos += pagesize;
while (pos < G_mapsize) {
pos += pagesize;
INIT_G();
- getopt32(argv, "");
- argv += optind;
-
get_terminal_width_height(-1, NULL, &G.height);
+ if (1) {
+ /* reduce number of write() syscalls while PgUp/Down: fully buffered output */
+ unsigned sz = (G.height | 0xf) * LINEBUF_SIZE;
+ setvbuf(stdout, xmalloc(sz), _IOFBF, sz);
+ }
+
+ getopt32(argv, "^" "" "\0" "=1"/*one arg*/);
+ argv += optind;
G.fd = xopen(*argv, O_RDWR);
G.size = xlseek(G.fd, 0, SEEK_END);