Search code examples
cfileubuntu-12.04umaskmkstemp

changing file permissions of default mkstemp


I call the following code in C:

 fileCreatefd = mkstemp(fileName);

I see that the file is created with permissions 600 (-rw-------). I want to create this temp file as -rw-rw-rw-

I tried playing around with umask but that only applies a mask over the file permissions -- at least thats my understanding. So how can i create a file with permissions 666?

Thanks


Solution

  • You cannot create it 0666 with mkstemp. You can change the permissions afterwards, if that is sufficient for your application, with fchmod.

    fileCreatefd = mkstemp(fileName);
    fchmod(fileCreatefd, 0666)