This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

readv - incorrect behavior?

Hi list.

I've encountered a problem with the readv system call under Cygwin of the

	int readv(int fd, const struct iovec *vector, int count);

It appears that readv is reading past the end of the file described by fd
and instead reading until each buffer in the iovec is filled.  This is not
limited to disk files, as I originally came across this problem when reading
from a pty's file descriptor.

The attached program and input file demonstrate the error.  Please note, in
the example I opened the file with the command

        test_fd = open("",O_RDWR);

however, the same behavior is observed opening the file as

        test_fd = open("",O_RDWR | O_TEXT);


        test_fd = open("",O_RDWR | O_BINARY);

The output I got from running this program is as follows:

$ ./readv_test
Total Bytes: 25
âoâa    â

You should notice that although there are only 16 bytes in the file, readv
returns the summed length of the two buffers in the iovec, 25.  In the test
case I pad the buffers with 'X's, so it is clear that readv is copying data
into them from somewhere.

More confusing still, replacing the readv call with

	bytes_read = read(test_fd, arr1, 20);

works flawlessly.

It appears to me that in, readv simply calls read.  I will admit
that my understanding of how these c++ libraries are called from a c program
is limited.

I've included output from cygcheck -s, though I just updated my installation
with setup a minute ago.

Matt Hirsch

P.S. The only real discussion I found in the mailing lists related to the
readv call was with regard to a patch submitted by Conrad Scott.  The
current code seems to differ in some details to Conrad's patch.  Has this
been updated more recently than that?  Granted, I'm not subscribed to the
developer's mailing list... ;)  I haven't tried this with any old versions
of Cygwin.

Attachment: readv_test.c
Description: Binary data

Description: Binary data

Attachment: cygcheck
Description: Binary data

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]