int main(int argc, const char *argv[])
{
int wfd = open("./open.txt",O_WRONLY | O_CREAT | O_TRUNC,0664);
char *wstr = "valorant";
write(wfd,wstr,strlen(wstr));
int rfd = open("./open.txt",O_RDONLY);
char rstr[20] = {0};
while(1)
{
int res = read(rfd,rstr,1);
if(res == 0)
{
break;
}
putchar(rstr[0]);
}
putchar(10);
close(wfd);
close(rfd);
return 0;
}
struct stat buf;
if(stst("3.c",&buf)==-1)
{
perror("");
return -1);
}
mode_t mode = buf.st_mode;
if((mode | S_IWUSR) == mode)
{
printf("\n");
chmod("./3.c",mode& =~ S_IWUSR);
system("ls - l 3.c");
}
else
{
printf("\n");
chmod("./3.c",mode& |= S_IWUSR);
system("ls - l 3.c");
}
return 0;