Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions io.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int read_header(FILE *fp, Header *h)
{
int buf[3];

if (fread_wrapper(buf, sizeof(int), 3, fp) == 0)
if (fread_wrapper(buf, sizeof(int), 3, fp) != 3)
{
return 0;
}
Expand Down Expand Up @@ -128,10 +128,10 @@ int write_header(FILE *fp, Header *h)
}


static char *progname = "";
static const char *progname = "";
void set_progname(const char *name)
{
progname = strdup(name);
progname = name;
}


Expand Down
25 changes: 21 additions & 4 deletions ttyplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ double ttywait(struct timeval prev, struct timeval cur, double speed)
diff.tv_sec = diff.tv_usec = 0;
}

FD_ZERO(&readfs);
FD_SET(STDIN_FILENO, &readfs);

/*
Expand All @@ -130,9 +131,9 @@ double ttywait(struct timeval prev, struct timeval cur, double speed)
*/
struct timeval orig_diff = diff;

select(1, &readfs, NULL, NULL, &diff);
int r = select(1, &readfs, NULL, NULL, &diff);
diff = orig_diff; /* Restore the original diff value. */
if (FD_ISSET(0, &readfs)) /* a user hits a character? */
if (r > 0 && FD_ISSET(0, &readfs)) /* a user hits a character? */
{
char c;
if (read(STDIN_FILENO, &c, 1) == 1)
Expand Down Expand Up @@ -184,9 +185,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);
Expand All @@ -198,9 +203,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;
}


Expand Down
12 changes: 10 additions & 2 deletions ttyrec.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,11 @@ int main(int argc, char **argv)
legacy = 1;
params = malloc(sizeof(char *) * 4);
command = shell;
params[0] = strrchr(shell, '/') + 1;
params[0] = strrchr(shell, '/');
if (params[0])
params[0] += 1;
else
params[0] = shell;
params[1] = "-c";
params[2] = strdup(optarg);
params[3] = NULL;
Expand Down Expand Up @@ -613,7 +617,11 @@ int main(int argc, char **argv)
{
command = shell;
params = malloc(sizeof(char *) * 3);
params[0] = strrchr(shell, '/') + 1;
params[0] = strrchr(shell, '/');
if (params[0])
params[0] += 1;
else
params[0] = shell;
params[1] = "-i";
params[2] = NULL;
}
Expand Down