Open C system call cannot print file contents if file is not opened as sudo

So, I am creating a new file:

 fd = open("tester.txt", O_CREAT | O_RDWR);

then using the write system call, I add some information to it. But when I try to read information from a file, it is impossible to do. Using the terminal , I found that the only way to open the file is to use sudo and the content is successfully written . However, my program cannot be root. So, how can I open a file, write some content to it and not close the C program, output the file.

+4
source share
2 answers

; :

fd = open("tester.txt", O_CREAT | O_RDWR, 0644);

-rw-r--r--, . , .. ---------, root ( chmodding , ).

+6

, O_CREAT open(), . man- open()

int open(const char *pathname, int flags, mode_t mode);

. , O_CREAT ; O_CREAT , .

  fd = open("tester.txt", O_CREAT | O_RDWR, 0664 ); 

, .

+3

Source: https://habr.com/ru/post/1689384/


All Articles