diff options
| author | christos <christos@NetBSD.org> | 2007-08-20 03:44:17 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2007-08-20 03:44:17 +0000 |
| commit | 3f074821a5e00c312009c22375a1ebff9fa86fbe (patch) | |
| tree | 164091c4cd770ac01cf8fabedfbbf632ba8f014f /usr.bin/script/script.c | |
| parent | 4e3006c66334f85102f31d7ce7f430eecff368d9 (diff) | |
Apparently seeking forward on a FIFO does not work (why?). Read instead.
Patch from Jukka Salmi.
Diffstat (limited to 'usr.bin/script/script.c')
| -rw-r--r-- | usr.bin/script/script.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/usr.bin/script/script.c b/usr.bin/script/script.c index 17b079123ef..da48b677464 100644 --- a/usr.bin/script/script.c +++ b/usr.bin/script/script.c @@ -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; |
