forked from bonsai/harakit
dj(1): fix potential skip/seek bug in non-std io
This commit is contained in:
parent
aff658d611
commit
6548a448c7
8
src/dj.c
8
src/dj.c
@ -133,7 +133,9 @@ Io_fdopen(struct Io *io, char *fn){
|
||||
}
|
||||
|
||||
/* Seeks io->seek bytes through *io's file descriptor, subtracting the number
|
||||
* of sought bytes from io->seek. This procedure leaves garbage in io->buf. */
|
||||
* of sought bytes from io->seek. This procedure leaves garbage in io->buf.
|
||||
* Read/written bytes here aren't counted in the statistics because successful
|
||||
* seeking is guaranteed. */
|
||||
static void
|
||||
Io_fdseek(struct Io *io){
|
||||
|
||||
@ -143,8 +145,10 @@ Io_fdseek(struct Io *io){
|
||||
assert(io->fd != STDERR_FILENO || io->fl == write_flags);
|
||||
|
||||
if(io->seek == 0
|
||||
|| (!fdisstd(io->fd) && lseek(io->fd, io->seek, SEEK_SET) != -1))
|
||||
|| (!fdisstd(io->fd) && lseek(io->fd, io->seek, SEEK_SET) != -1)){
|
||||
io->seek = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if(io->fl == write_flags)
|
||||
memset(io->buf, '\0', io->bs);
|
||||
|
Loading…
Reference in New Issue
Block a user