fstat gives wrong mode after chmod and fchmod

Yitzchak Scott-Thoennes sthoenna@efn.org
Sun Sep 18 23:00:00 GMT 2005


I'm seeing this on the 20050916 but as far as I know it's not a
regression.  A new perl test (actually using an existing file opened
for read access) turned this up.

The following gives:
after fchmod to 0 and chmod to 0666, stat: 666  fstat: 444

#include <fcntl.h>
#include <sys/stat.h>
#include <stdio.h>

int main(int argc, char **argv)
{
   int fd;
   struct stat statbuf, fstatbuf;

   if ( ( fd = open("foo", O_CREAT|O_EXCL|O_WRONLY, 0666) ) < 0 ) {
      perror("open failed");
      return 1;
   }

   if ( fchmod(fd, 0) ) {
      perror("fchmod failed");
      return 1;
   }

   if ( chmod("foo", 0666) ) {
      perror("chmod failed");
      return 1;
   }

   if ( stat("foo", &statbuf) ) {
      perror("stat failed");
      return 1;
   }

   if ( fstat(fd, &fstatbuf) ) {
      perror("fstat failed");
      return 1;
   }

   printf("after fchmod to 0 and chmod to 0666, stat: %o  fstat: %o\n",
          statbuf.st_mode & 0777,  fstatbuf.st_mode & 0777);
          
   return 0;
}

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



More information about the Cygwin mailing list