Create a file foo and foo2 with the same time access and permissions using system programming. I am quite clueless about this, I had to create foo and foo2 outside, and now I am unsure whether this is the correct way to do it or not. This is what I have tried:
#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;
}