From owner-freebsd-questions Wed Mar 11 10:46:35 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id KAA02778 for freebsd-questions-outgoing; Wed, 11 Mar 1998 10:46:35 -0800 (PST) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from gdi.uoregon.edu (gdi.uoregon.edu [128.223.170.30]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id KAA02651 for ; Wed, 11 Mar 1998 10:46:17 -0800 (PST) (envelope-from dwhite@gdi.uoregon.edu) Received: from localhost (dwhite@localhost) by gdi.uoregon.edu (8.8.7/8.8.8) with SMTP id KAA15953; Wed, 11 Mar 1998 10:46:13 -0800 (PST) (envelope-from dwhite@gdi.uoregon.edu) Date: Wed, 11 Mar 1998 10:46:13 -0800 (PST) From: Doug White Reply-To: Doug White To: Matthew Hagerty cc: freebsd-questions@FreeBSD.ORG Subject: Re: open(), fopen(), and flock() In-Reply-To: <3.0.3.32.19980310163441.031536ec@smtp.net-link.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Tue, 10 Mar 1998, Matthew Hagerty wrote: > Could someone tell me if you can use flock() to lock a file opened with > fopen()? No; flock() wants a file descriptor; see the man page. Use open(), flock() it, then fdopen() the descriptor if you want to use the f* functions. I don't think fdopen() eats the file descriptor though, so you should be able to flock() the descriptor all you want even after you fdopen() it. > Is there some reason to use fopen() over open() or vice/versa? Is there > even any locking mechanisms in ANSI-C? fopen() lets you use the f* functions that take FILE* as arguments (fprintf(), fscanf(), etc.) and lets you do file repositioning easily (rewind() & friends). Otherwise you have to use read()/write() directly, and they are kinda messy for complex file operations. They're kinda messy in general. :) I don't know about any standardized file locking operations; that sort of thing would fall under POSIX. Doug White | University of Oregon Internet: dwhite@resnet.uoregon.edu | Residence Networking Assistant http://gladstone.uoregon.edu/~dwhite | Computer Science Major To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message