From owner-freebsd-questions Thu Jul 15 8:55: 8 1999 Delivered-To: freebsd-questions@freebsd.org Received: from bingnet2.cc.binghamton.edu (mailbox.adm.binghamton.edu [128.226.10.60]) by hub.freebsd.org (Postfix) with ESMTP id 2EE6314E68 for ; Thu, 15 Jul 1999 08:55:03 -0700 (PDT) (envelope-from zzhang@cs.binghamton.edu) Received: from cs.binghamton.edu (bing229.net108.binghamton.edu [128.226.108.229]) by bingnet2.cc.binghamton.edu (8.9.3/8.9.3) with ESMTP id LAA13951; Thu, 15 Jul 1999 11:53:37 -0400 (EDT) Message-ID: <378E0401.D4262650@cs.binghamton.edu> Date: Thu, 15 Jul 1999 11:53:37 -0400 From: Zhihui Zhang Reply-To: Zhihui Zhang Organization: SUNY - Binghamton X-Mailer: Mozilla 4.05 [en] (Win95; I) MIME-Version: 1.0 To: James Bailie Cc: freebsd-questions@FreeBSD.ORG Subject: Re: fseek() over bounds of file Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > fseek() will not only seek past the end of a file, but will also seek > backwards (negative offset) past the beginning of a file. The next file access > fails instead of the call to fseek(). Is there some kind of way to make a hole > in a file by seeking backwards I am unaware of, or is this a bug? Also, > fseek()-ing out of file boundaries, in either direction, succeeds, in the > sense that the call returns zero, if the file has been opened read-only, > which, in my opinion, it shouln't. > As far as I know, fseek() only sets the offset in the field f_offset of the file structure. Whether this offset exists or not will be determined later when you do real I/O. If you read beyond EOF, it will return all zeros. If you write beyond EOF, a disk space will be allocated and the file is enlarged. The use of fseek() provides you the opportunity to create holes anywhere in a file, except at the very end of a file. -Zhihui To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message