diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1998-11-10 22:10:22 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1998-11-10 22:10:22 +0000 |
commit | c2bc9602cb9464a3f5e1ced421010804aa57971d (patch) | |
tree | 8e4b5f05246afa0970a725f9313213cb32eaba02 /lib | |
parent | fdecfc31b41321f306854cbb78a2837dbf3f3231 (diff) |
fix append mode; mason@primenet.com.au
Diffstat (limited to 'lib')
-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); } |