why my chmod fail all the time

i wrote a little program which made use of the chmod system call
to change my file permissions.Here is my code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>

int main(int argc,char* argv[])
{
	
	if( (chmod(argv[1],S_IWUSR)) == 0)
		printf("change mode operation succeded\n");
	
	
	return 0;
}

i initially set the file permission to 000 by the chmod command in the terminal
then i ran my programm which took command line arguments,howerver,everytime after the execution,i checked out the new permission,it was solely 777(regardless of the mode_t parameter i sepecified).

is there anything wrong with my programme or it is because of the umask system variable ,if it is,how to see it and fix it.

Thanks in advance!
Last edited on
Are you changing the mode of something you own? If you aren't root, you won't be able to change other people's files.
Yes, i logged in as a root user,besides i was the one who created that file.
PLUS, the printf statement is executed .
Last edited on
That's weird. I can't say why that would happen.
i finally figured it out. I think it is because of the location of the file .

I used my virtual machine(Vmware , the os is Fedora12) to do this experiment and the file to
be tested locates at /mnt/hgfs/LinuxProgramming which is a place used to place shared folders.

I tried to create the file to be tested on a another place like /root and this time i succeeded.

It turns out the file permission is User-write only as i expected.
Last edited on
Topic archived. No new replies allowed.