This is the mail archive of the cygwin 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]

Re: Cygwin's writev() non-standard behavior


On 04/23/2014 08:06 AM, qq qq wrote:
> writev() does not accept count 0 but it should

POSIX says:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/writev.html

If fildes refers to a regular file and all of the iov_len members in the
array pointed to by iov are 0, writev() shall return 0 and have no other
effect. For other file types, the behavior is unspecified.

> 
> $ cat test.c
> #include <stdio.h>
> #include <errno.h>
> #include <stdlib.h>
> #include <string.h>
> #include <sys/uio.h>
> 
> int main()
> {
>   struct iovec vec;
> 
>   memset(&vec, 0, sizeof(vec));
>   if (writev(1, &vec, 0) < 0)

But in your case, fd 1 is a terminal...

> Cygwin:
> $ gcc -Wall test.c
> $ ./a.exe
> writev: Invalid argument

so your argument is flawed - you have triggered undefined behavior.
That said, if you can reproduce it with ./a.exe > file, you have proven
a bug; furthermore, cygwin should emulate Linux behavior, even if POSIX
doesn't define the behavior.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


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