delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/09/18/18:23:17

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Sun, 18 Sep 2005 15:22:56 -0700
From: Yitzchak Scott-Thoennes <sthoenna AT efn DOT org>
To: cygwin AT cygwin DOT com
Subject: fstat gives wrong mode after chmod and fchmod
Message-ID: <20050918222256.GA3420@efn.org>
Mime-Version: 1.0
User-Agent: Mutt/1.4.2.1i
X-IsSubscribed: yes

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019