This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
Re: Bug in pread/pwrite ?
On Thu, 8 Mar 2007, Christopher Faylor wrote:
The pread() that Cygwin does uses is in fhandler_disk_file.cc.
Thanks, now i know where the culprit is and understand why
I had a problem with my proposed patch ;-)
All of that aside, I don't see how ignoring an lseek() failure
could be considered to be a good thing.
I have done more research since, have a look to this glibc
pread implementation:
ssize_t
__libc_pread (int fd, void *buf, size_t nbyte, off_t offset)
{
/* Since we must not change the file pointer preserve the value so that
we can restore it later. */
int save_errno;
ssize_t result;
off_t old_offset = __libc_lseek (fd, 0, SEEK_CUR);
if (old_offset == (off_t) -1)
return -1;
/* Set to wanted position. */
if (__libc_lseek (fd, offset, SEEK_SET) == (off_t) -1)
return -1;
/* Write out the data. */
result = __libc_read (fd, buf, nbyte);
/* Now we have to restore the position. If this fails we have to
return this as an error. But if the writing also failed we
return this error. */
save_errno = errno;
if (__libc_lseek (fd, old_offset, SEEK_SET) == (off_t) -1)
{
if (result == -1)
__set_errno (save_errno);
return -1;
}
__set_errno (save_errno);
return result;
}
For the full file:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/sysdeps/posix/pread.c?rev=1.6&content-type=text/x-cvsweb-markup&cvsroot=glibc
glibc implementation seems correct in ignoring lseek
failure if read has been successfull.
Regards,
Christophe
--
,-~~-.___. ._.
/ | ' \ | |"""""""""| Christophe GRENIER
( ) 0 | | | grenier@cgsecurity.org
\_/-, ,----' | | |
==== !_!--v---v--"
/ \-'~; |""""""""| TestDisk & PhotoRec
/ __/~| ._-""|| | Data Recovery
=( _____|_|____||________| http://www.cgsecurity.org