Skip to content
Advertisement

unexpected result(-wS-wx–T) on file permission with open() function in C

I wrote this program to open a file. Everything was OK until I saw this permission(-wS-wx–T) with ls -lh

open.c

JavaScript

I compiled the program featly, didn’t take any error or warning.

JavaScript

I haven’t ever seen kind of permission. What are ‘S’ and ‘T’ meaning in the file permissions section? (NOTE: I took the answer to this question in the comments.)

Advertisement

Answer

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):

The mode argument specifies the file mode bits be applied when a new file is created. This argument must be supplied when O_CREAT or O_TMPFILE is specified in flags; if neither O_CREAT nor O_TMPFILE is 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).

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement