Commits

Evan Gates  committed e1ae5df

rewind cols*rows bytes instead of the whole file on SIGWINCH

  • Participants
  • Parent commits 1b7d447

Comments (0)

Files changed (1)

 
 void sigwinch(int unused)
 {
-	rewind(in);
+	long pos;
 
 	if (ioctl(STDERR, TIOCGWINSZ, &ws) < 0)
 		warn("failed ioctl");
 
+	pos = ftell(in);
+	fseek(in, MAX(0, pos - (ws.ws_col * ws.ws_row)), SEEK_SET);
+
 	while (fgets(buf, sizeof(buf), in))
 		print_line(buf);
 	fflush(stdout);