diff options
author | 1998-11-10 22:10:21 +0000 | |
---|---|---|
committer | 1998-11-10 22:10:21 +0000 | |
commit | 63dd02704cf222bf041d05c0c13932f8ff51e5a1 (patch) | |
tree | b3c0027f6f31a1b5413b5d4c607022e47f6a15c6 /lib/libc/stdio/freopen.c | |
parent | hash & cache hostnames; garath@code.ridgefield.org (diff) | |
download | wireguard-openbsd-63dd02704cf222bf041d05c0c13932f8ff51e5a1.tar.xz wireguard-openbsd-63dd02704cf222bf041d05c0c13932f8ff51e5a1.zip |
fix append mode; mason@primenet.com.au
Diffstat (limited to 'lib/libc/stdio/freopen.c')
-rw-r--r-- | lib/libc/stdio/freopen.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c index ddf92115f1c..35f92d47cf1 100644 --- a/lib/libc/stdio/freopen.c +++ b/lib/libc/stdio/freopen.c @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: freopen.c,v 1.3 1996/08/19 08:32:45 tholo Exp $"; +static char rcsid[] = "$OpenBSD: freopen.c,v 1.4 1998/11/10 22:10:21 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -151,5 +151,16 @@ freopen(file, mode, fp) fp->_write = __swrite; fp->_seek = __sseek; fp->_close = __sclose; + + /* + * When opening in append mode, even though we use O_APPEND, + * we need to seek to the end so that ftell() gets the right + * answer. If the user then alters the seek pointer, or + * the file extends, this will fail, but there is not much + * we can do about this. (We could set __SAPP and check in + * fseek and ftell.) + */ + if (oflags & O_APPEND) + (void) __sseek((void *)fp, (fpos_t)0, SEEK_END); return (fp); } |