The definition of the UNIX open() function when used with the O_CREAT flag is that it requires a third argument named mode in order to set the files' privileges.
What if that mode is not specified?
int file;
static const char filename[] = "test.test";
if ((file = open(filename, O_RDWR | O_CREAT | O_TRUNC)) == 1)
{
perror("Error opening file.");
exit(EXIT_FAILURE);
}
close(file);
What happens with the file that is created using those flags? On my system I get:
-r--r-s--- 1 hyperboreean hyperboreean 0 2009-02-25 01:40 test.test
A theory is that the open function looks on the stack and checks for the mode parameter and ends up using a random integer it finds.
What does the standard say about this?