From: Package Salvaging Team <team+salvage@tracker.debian.org>
Date: Sat, 25 Jan 2025 15:35:56 +0100
Subject: Handle SIGWINCH

Auther: Joey Hess <joeyh@debian.org>
Reported-By: Joey Hess <joeyh@debian.org>
Bug-Debian: http://bugs.debian.org/564931
Last-Update: 2025-01-25
---
 ttyplay.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/ttyplay.c b/ttyplay.c
index 41e69e4..6b519fe 100644
--- a/ttyplay.c
+++ b/ttyplay.c
@@ -191,9 +191,13 @@ double ttynowait(struct timeval prev, struct timeval cur, double speed)
 
 int ttyread(FILE *fp, Header *h, char **buf)
 {
+    fpos_t pos;
+    int can_seek = fgetpos(fp, &pos) == 0;
+    clearerr(fp);
+
     if (read_header(fp, h) == 0)
     {
-        return 0;
+        goto err;
     }
 
     *buf = malloc(h->len);
@@ -205,9 +209,21 @@ int ttyread(FILE *fp, Header *h, char **buf)
 
     if (fread_wrapper(*buf, 1, h->len, fp) == 0)
     {
-        perror("fread");
+        goto err;
     }
     return 1;
+
+err:
+    if (ferror(fp)) {
+       perror("fread");
+    }
+    else {
+       /* Short read. Seek back to before header, to set up for retry. */
+       if (can_seek) {
+           fsetpos(fp, &pos);
+       }
+    }
+    return 0;
 }
 
 
