Re: Behavior of lseek() on a fd opened with 'RDONLY' flag, when seekinggoes beyond file size.

From: David Newall
Date: Sat Jun 21 2008 - 22:06:42 EST


palani saravanan wrote:
> Does lseek() permits -ve value as offset, with SEEK_SET mode? ...
> errno = 0;
> rd_rc = lseek(rd_fd, -10, SEEK_SET);
> returns rd_rc = -10 and errno remains 0.
>

No, lseek does not permit negative file offsets, and should return
EINVAL in your example. You may have discovered a bug. For reference,
on my system lseek returns -1 and sets errno to EINVAL, as it should.

If you're running a recent kernel it might be worth looking closer into
this; for older kernels it's probably not worth the effort.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/