Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 2 Jul 2011 11:04:19 -0700
From:      Artem Belevich <art@freebsd.org>
To:        =?ISO-8859-1?Q?Martin_M=F6ller?= <moeller.akt@googlemail.com>
Cc:        "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org>
Subject:   Re: Question about lseek/fseek
Message-ID:  <BANLkTimP0qBf7yuYtFdjFh33pQu7UG4brA@mail.gmail.com>
In-Reply-To: <CA34F05F.682%moeller.akt@googlemail.com>
References:  <Acw4v/UqpMFYAZLNTEulXOpM6pbKgg==> <CA34F05F.682%moeller.akt@googlemail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, Jul 2, 2011 at 6:57 AM, Martin M=F6ller
<moeller.akt@googlemail.com> wrote:
> Hi Hackers,
>
> why does these function allow seeking beyond the EOF of a file in
> O_RDONLY/=B2rb=B2 mode ?

Perhaps because the standard explicitly says that it's allowed:
http://pubs.opengroup.org/onlinepubs/009695399/functions/lseek.html

> How does these function then signal the EOF correctly ?

It does not. It only sets offset for a given file descriptor. It's
read's job to signal EOF.

> Seeking beyond the EOF makes sense for me in write-mode but not in read-o=
nly
> mode !

Given that lseek does not change file size (I.e. it does not ever
modify the file), there's no reason to prohibit seek beyond end of
file even in read-only mode.

Now, if you would try to read after seeking beyond EOF, then the
read() should complain that there's no data.

--Artem

>
> With Regards,
> Martin
> _______________________________________________
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org=
"
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BANLkTimP0qBf7yuYtFdjFh33pQu7UG4brA>