From owner-freebsd-bugs@FreeBSD.ORG Fri Apr 11 19:00:28 2003 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9D32637B401 for ; Fri, 11 Apr 2003 19:00:28 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4249543F75 for ; Fri, 11 Apr 2003 19:00:28 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h3C20SUp012703 for ; Fri, 11 Apr 2003 19:00:28 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h3C20R04012702; Fri, 11 Apr 2003 19:00:27 -0700 (PDT) Date: Fri, 11 Apr 2003 19:00:27 -0700 (PDT) Message-Id: <200304120200.h3C20R04012702@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: David Taylor Subject: Re: misc/50825: lseek to negative file positions screws up flags X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: David Taylor List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Apr 2003 02:00:28 -0000 The following reply was made to PR misc/50825; it has been noted by GNATS. From: David Taylor To: Erdgeist 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 > #include > > 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"