I coded this program to open a file. Everything was OK when I saw this permission(-wS-wx--T) with
#define FILE "open_1.txt"
fd = open(FILE, O_RDWR | O_CREAT);
if(fd == -1)
printf("[error] There is a error\n");
perror("Error printed by perror");
printf("[succeeded] The process was succeeded\n");
[succeeded] The process was succeeded
$ ls -lh
-rwxrwxr-x 1 arien arien 8.5K Feb 1 23:38 open
--wS-wx--T 1 arien arien 0 Feb 1 23:39 open_1.txt
If you include
O_CREAT in the flags passed to
open() then you must use the three-arg form of the function, which takes a numeric file mode as the third argument. This requirement is documented in the Linux manual page for the function (emphasis added):
modeargument specifies the file mode bits be applied when a new file is created. This argument must be supplied when
O_TMPFILEis specified in
flags; if neither
O_TMPFILEis specified, then mode is ignored.
What mode you actually want is unclear, but perhaps
S_IRUSR | S_IWUSR | S_IRGRP would be suitable (==
0640; read and write for the owner, read only for the owner's group, no permission for anyone else).