LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   umask...inheritance of file attributes problem (https://www.linuxquestions.org/questions/linux-general-1/umask-inheritance-of-file-attributes-problem-8576/)

iam3 11-11-2001 08:44 AM

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


All times are GMT -5. The time now is 12:59 AM.