From c2bc9602cb9464a3f5e1ced421010804aa57971d Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Tue, 10 Nov 1998 22:10:22 +0000 Subject: fix append mode; mason@primenet.com.au --- lib/libc/stdio/freopen.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 @@ -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); } -- cgit v1.2.3