This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: fstat gives wrong mode after chmod and fchmod
- From: Yitzchak Scott-Thoennes <sthoenna at efn dot org>
- To: cygwin at cygwin dot com
- Date: Wed, 21 Sep 2005 20:31:12 -0700
- Subject: Re: fstat gives wrong mode after chmod and fchmod
- References: <20050918222256.GA3420@efn.org>
On Sun, Sep 18, 2005 at 03:22:56PM -0700, Yitzchak Scott-Thoennes wrote:
> 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
Does anyone else see this?
> #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/
>
--
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/