fsync bug

Eric Blake eblake@redhat.com
Thu Sep 22 14:33:00 GMT 2011

fsync() is required to work on read-only fds (in theory, you can sync 
the atime metadata, which is a write operation triggered by a read-only 
fd).  But cygwin rejects this program, which works on Linux:

$ cat foo.c
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fcntl.h>
int main (void)
   int fd = open("file", O_CREAT|O_EXCL|O_WRONLY, 0600);
   if (fd < 0)
     return 1;
   if (close(fd))
     return 2;
   fd = open("file", O_RDONLY);
   if (fd < 0)
     return 3;
   if (fsync(fd))
     return 4;
   if (unlink("file"))
     return 5;
   return 0;
$ rm -f file && ./foo; echo $?

Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

More information about the Cygwin mailing list