How to create directory with right permissions using C on Posix

You seem to be misunderstanding what umask is used for. It sets/retrieves the process's file mode creation mask, which in turn is used to turn off bits in the file mode you specify in calls like mkdir, like this (pseduo-code):

real_mode = requested_mode & ~umask

So in your code, since you pass in the value of the umask itself, you end up specifying permissions as zero, which is exactly what you see.

Instead, you should specify the permissions you want in the call to mkdir, like this:

mkdir("trial", 0755)

Tags:

C

Posix

Mkdir

Umask