UMASK function in C UMASK function in C unix unix

UMASK function in C


The file creation mode you specified is in decimal format. File creation modes are typically specified in octal, so you should prefix the number with a leading 0, which tells the compiler it is an octal constant.

creat("a.txt",0666);

Decimal 666 = octal 1232, which matches up with the result you got.

Please refer to your friendly man page (man 2 umask) or to this one.


--w--wx-wT

1 * 512 + 2 * 64 + 3 * 8 + 2 = 666

It did exactly what you asked for. Try using 0666 instead.