我创建了一个文件夹,在我打开该文件夹内的文件后,在其上写入。碰巧在那之后我尝试打开文件但我没有权限因此我必须手动更改它。
/* str1 has tha name of the folder */
/* str the bytes I want to write in the file inside the folder*/
...
mkdir(str1,0777);
if (filefd < 0) {
strncpy(auxstr, str, MAX_MSG + 1);
strcat(str1,"\\");
strcat(str1, auxstr);
filefd = open (str1, O_RDWR | O_CREAT | O_TRUNC);
nbytes -= (strlen(str) + 1);
memcpy(auxstr, &str[strlen(str)+1], nbytes);
memcpy(str, auxstr, nbytes);
}
/*write to the file */
if ((nwritten = write(filefd, str, nbytes)) != nbytes) {
printf ("can't write on file\n");
break;
}
为了获得打开创建的文件的权限,我应该更改什么?
非常感谢,
:秒
with = 0_CREATE 我仍然有没有权限读取文件的问题。我必须手动设置它们
而且我已经有 0_CREAT 在公开
打开(str1,O_RDWR | O_CREAT | O_TRUNC);