使用系统编程创建具有相同访问权限和权限的文件foo和foo2。我对此一无所知,我不得不在外面创建foo和foo2,现在我不确定这是否是正确的方法。这就是我尝试过的:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<string.h>
#include <fcntl.h>
int main()
{
int fd = open("./foo", O_RDWR);
int fd2 = open("./foo2", O_RDWR);
if(fd == -1)
{
printf("nError creating foo.");
}
else if(fd2 == -1)
{
printf("nError creating foo2.");
}
else
{
printf("nFile descripter 1: %d", fd);
printf("nFile descripter 2: %d", fd2);
}
return 0;
}
在创建文件时,C命令是open()
,如手册页中所述(需要一些库,请注意(:
https://www.man7.org/linux/man-pages/man2/open.2.html
如果用户希望创建或覆盖文件,他可以使用creat()
,实际上它只不过是带有以下标志的open()
:O_CREAT|O_WRONLY|O_TRUNC
至于时间获取,其他居住者可能会更有帮助;贾伯沃基的链接可能会有所帮助。