Apparently seeking forward on a FIFO does not work (why?). Read instead.

Patch from Jukka Salmi.
This commit is contained in:
christos 2007-08-20 03:44:17 +00:00
parent 4e3006c663
commit 3f074821a5

View File

@ -1,4 +1,4 @@
/* $NetBSD: script.c,v 1.13 2007/08/19 10:31:13 christos Exp $ */
/* $NetBSD: script.c,v 1.14 2007/08/20 03:44:17 christos Exp $ */
/*
* Copyright (c) 1980, 1992, 1993
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1992, 1993\n\
#if 0
static char sccsid[] = "@(#)script.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: script.c,v 1.13 2007/08/19 10:31:13 christos Exp $");
__RCSID("$NetBSD: script.c,v 1.14 2007/08/20 03:44:17 christos Exp $");
#endif /* not lint */
#include <sys/types.h>
@ -90,6 +90,7 @@ void finish(int);
int main(int, char **);
void scriptflush(int);
void record(FILE *, char *, size_t, int);
void consume(FILE *, off_t, char *, int);
void playback(FILE *);
int
@ -303,6 +304,25 @@ record(FILE *fscript, char *buf, size_t cc, int direction)
err(1, "writev");
}
void
consume(FILE *fscript, off_t len, char *buf, int reg)
{
size_t l;
if (reg) {
if (fseek(fscript, len, SEEK_CUR) == -1)
err(1, NULL);
}
else {
while (len > 0) {
l = MIN(DEF_BUF, len);
if (fread(buf, sizeof(char), l, fscript) != l)
err(1, "cannot read buffer");
len -= l;
}
}
}
#define swapstamp(stamp) do { \
if (stamp.scr_direction > 0xff) { \
stamp.scr_len = bswap64(stamp.scr_len); \
@ -352,15 +372,15 @@ playback(FILE *fscript)
case 's':
(void)printf("Script started on %s", ctime(&clock));
tsi = tso;
fseek(fscript, stamp.scr_len, SEEK_CUR);
(void)consume(fscript, stamp.scr_len, buf, reg);
break;
case 'e':
(void)printf("\nScript done on %s", ctime(&clock));
fseek(fscript, stamp.scr_len, SEEK_CUR);
(void)consume(fscript, stamp.scr_len, buf, reg);
break;
case 'i':
/* throw input away */
fseek(fscript, stamp.scr_len, SEEK_CUR);
(void)consume(fscript, stamp.scr_len, buf, reg);
break;
case 'o':
tsi.tv_sec = tso.tv_sec - tsi.tv_sec;