Use open syscall to write and create a file ,there’s no attributes with the file. fedora16 gcc-4.6.3
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
int main()
{
char * str= "helloworld";
int fd = open("test.db",O_WRONLY|O_CREAT|O_TRUNC|O_APPEND);
write(fd,str,10);
close(fd);
return 0;
}
ll test.db
———-. 1 jiamo jiamo 14 Apr 17 11:34 test.db
While it don’t create file with the default file attributes such like touch test.db
umask : 0002
if drop the O_TRUNC
int fd = open("test1.db",O_WRONLY|O_CREAT|O_APPEND)
the file attributs is :
—-rwx—. 1 jiamo jiamo 14 Apr 17 12:29 test1.db
Add the required permissions to the open() syscall:
From the documentation: