diff options
author | ache <ache@FreeBSD.org> | 2006-10-15 16:24:31 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2006-10-15 16:24:31 +0000 |
commit | ce03393cc57955d09225468a7721769130484c5c (patch) | |
tree | f4659cf878ab138a8aa37ac6650b535d5b2a3c4c /lib | |
parent | e4ea7afca1c5f0dfc95a190335570a00b4a9bcfc (diff) | |
download | FreeBSD-src-ce03393cc57955d09225468a7721769130484c5c.zip FreeBSD-src-ce03393cc57955d09225468a7721769130484c5c.tar.gz |
Do real seek
Catch ftruncate errors
PR: 104295
Submitted by: ru (seek)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/stdio/freopen.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c index 476f3ef..bbf039a 100644 --- a/lib/libc/stdio/freopen.c +++ b/lib/libc/stdio/freopen.c @@ -113,9 +113,17 @@ freopen(file, mode, fp) return (NULL); } } - if (oflags & O_TRUNC) - ftruncate(fp->_file, 0); - if (_fseeko(fp, 0, oflags & O_APPEND ? SEEK_END : SEEK_SET, + if (oflags & O_TRUNC) { + if (ftruncate(fp->_file, (off_t)0) < 0) { + sverrno = errno; + fclose(fp); + FUNLOCKFILE(fp); + errno = sverrno; + return (NULL); + } + } + fp->_flags |= __SNPT; /* real seek */ + if (_fseeko(fp, (off_t)0, oflags & O_APPEND ? SEEK_END : SEEK_SET, 0) < 0 && errno != ESPIPE) { sverrno = errno; fclose(fp); |