umask...inheritance of file attributes problem
Hei,
The program I have used:
*******************************************
main () {
FILE *fp;
struct stat statbuf;
if ((fp = fopen("newfile","w")) == NULL)
{
perror("fopen");
return error;
}
fprintf(fp,"This is an example file.");
fclose(fp);
// Now check permissions
if (stat("newfile",&statbuf) == -1)
{
perror("stat");
return error;
}
printf("The file perms on the file are %o\n",statbuf.st_mode & 07777);
chmod("newfile",0755);
if (stat("newfile",&statbuf) == -1)
{
perror("stat");
return error;
}
printf("The file perms on the file are now %o\n",statbuf.st_mode &
07777);
}
*******************************************
Output that I got:
bash-2.05$ umask 022
bash-2.05$ appl
The file perms on the file are 666
The file perms on the file are now 755
bash-2.05$ ls -l newfile-rwxr-xr-x 1 hussait2 student 24 Nov 11
14:26 newfile
bash-2.05$
bash-2.05$ rm newfile
bash-2.05$ umask 077
bash-2.05$ appl
The file perms on the file are 666
The file perms on the file are now 755
bash-2.05$ ls -l newfile-rwxr-xr-x 1 hussait2 student 24 Nov 11
14:26 newfile
Why does it always print 666 and not according to the value of umask. In
unix default is 666 but I do change the value of umask from shell. But it
does not affect it, WHY?
Student
|