misc/50825: lseek to negative file positions screws up flags
David Taylor
davidt at yadt.co.uk
Fri Apr 11 19:00:28 PDT 2003
The following reply was made to PR misc/50825; it has been noted by GNATS.
From: David Taylor <davidt at yadt.co.uk>
To: Erdgeist <erdgeist at erdgeist.org>
Cc: FreeBSD-gnats-submit at FreeBSD.org
Subject: Re: misc/50825: lseek to negative file positions screws up flags
Date: Sat, 12 Apr 2003 02:49:37 +0100
On Fri, 11 Apr 2003, Erdgeist wrote:
> >Description:
> Doing a lseek to a position before the file results in corrupted
> File flags.
Actually, if you remove the lseek(); line from the test program below, the
file mode will still be screwed up.
> >How-To-Repeat:
> #include <unistd.h>
> #include <fcntl.h>
>
> int main( ) {
> int a = open( "testfile", O_CREAT | O_RDWR );
^^^^^^^ ^^^
The problem is this:
int
open(const char *path, int flags, ...);
The flags argument may indicate the file is to be cre-ated if it does
not exist (by specifying the O_CREAT flag). In this case open()
requires a third argument mode_t mode, and the file is created
with mode mode as described in chmod(2) and modified by the process'
umask value (see umask(2)).
Replacing the above line with:
int a = open( "testfile", O_CREAT | O_RDWR, 0666 );
results in the program working as it should.
> lseek( a, -10, SEEK_CUR);
> close( a );
> return 0;
> }
--
David Taylor
davidt at yadt.co.uk
"The future just ain't what it used to be"
More information about the freebsd-bugs
mailing list