Using the open() system call

前端 未结 5 1826
说谎
说谎 2020-12-17 17:11

I\'m writing a program that writes output to a file. If this file doesn\'t exist, I want to create it.

Currently, I\'m using the following flags when calling open: O

5条回答
  •  生来不讨喜
    2020-12-17 17:42

    Just use the optional third argument to open:

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

    so like this:

    open("blahblah", O_CREAT | O_WRONLY, S_IRUSR | S_IWUSER | S_IRGRP | S_IROTH);
    

    See man open(2).

提交回复
热议问题