Date: Fri, 11 Apr 2003 19:00:27 -0700 (PDT) From: David Taylor <davidt@yadt.co.uk> To: freebsd-bugs@FreeBSD.org Subject: Re: misc/50825: lseek to negative file positions screws up flags Message-ID: <200304120200.h3C20R04012702@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR misc/50825; it has been noted by GNATS.
From: David Taylor <davidt@yadt.co.uk>
To: Erdgeist <erdgeist@erdgeist.org>
Cc: FreeBSD-gnats-submit@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@yadt.co.uk
"The future just ain't what it used to be"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200304120200.h3C20R04012702>
