Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-ID: <950B6B3FADEC484C8D0AE17EEE55E1FA2E02F9@draco.analogic.com> From: "Hirsch, Matthew" To: "'cygwin AT cygwin DOT com'" Subject: readv - incorrect behavior? Date: Mon, 28 Jul 2003 16:33:57 -0400 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C35547.922CE2C0" Note-from-DJ: This may be spam ------_=_NextPart_000_01C35547.922CE2C0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi list. I've encountered a problem with the readv system call under Cygwin of = the form 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 =3D open("testfile.foo",O_RDWR); however, the same behavior is observed opening the file as test_fd =3D open("testfile.foo",O_RDWR | O_TEXT); or test_fd =3D open("testfile.foo",O_RDWR | O_BINARY); The output I got from running this program is as follows: $ ./readv_test Total Bytes: 25 Vectors: 12345 *789012345 =E2=99=A0o=E2=98=BAa =E2=96=BA 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 =3D read(test_fd, arr1, 20); works flawlessly. It appears to me that in fhandler.cc, 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. Thanks! 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. ------_=_NextPart_000_01C35547.922CE2C0 Content-Type: application/octet-stream; name="readv_test.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="readv_test.c" #include /*printf*/=0A= #include /*readv. iovec*/=0A= #include /*O_RDWR, open*/=0A= #include /*close*/=0A= =0A= int main()=0A= {=0A= =0A= int test_fd, bytes_read, i;=0A= struct iovec iov[2];=0A= char arr0[5];=0A= char arr1[20];=0A= =0A= //for clarity, fill buffers with 'X's=0A= for(i=3D0;i<20;i++)=0A= arr1[i]=3D'X';=0A= =0A= for(i=3D0;i<5;i++)=0A= arr0[i]=3D'X';=0A= =0A= iov[0].iov_len =3D 5;=0A= iov[0].iov_base =3D arr0;=0A= iov[1].iov_len =3D 20;=0A= iov[1].iov_base =3D arr1;=0A= =0A= test_fd =3D open("testfile.foo",O_RDWR);=0A= =0A= bytes_read =3D readv(test_fd, iov, 2);=0A= =0A= printf("Total Bytes: %d\n",bytes_read);=0A= =0A= printf("Vectors:\n\t");=0A= for(i=3D0;i<(bytes_read<5?bytes_read:5);i++)=0A= printf("%c",arr0[i]);=0A= printf("\n\t");=0A= bytes_read -=3D 5;=0A= for(i=3D0;i