Date: Thu, 15 Jul 1999 11:53:37 -0400 From: Zhihui Zhang <zzhang@cs.binghamton.edu> To: James Bailie <jazzturk@home.com> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: fseek() over bounds of file Message-ID: <378E0401.D4262650@cs.binghamton.edu>
next in thread | raw e-mail | index | archive | help
> > 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?378E0401.D4262650>