char buf[] = "try";
staticint flag = 1; //If 1, file never opened. If 0, file already opened during run
if(flag){
if((fd = open(PATH_IPCS, O_CREAT | O_RDWR | O_TRUNC)) != -1){
TEST_ERROR
printf("File descriptor opened, value: %d\n", fd);
write(fd, buf, sizeof(buf));
flag--;
}else{
printf("Can't open the file\n");
TEST_ERROR
}
}else{
if((fd = open(PATH_IPCS, O_CREAT | O_RDWR | O_APPEND)) != -1){
printf("File descriptor already opened, value: %d\n", fd);
write(fd, buf, sizeof(buf));
}else{
printf("Can't open the file\n");
TEST_ERROR
}
}
maybe is the Append? I don't know..
When i open the file, is saved as: trytrytrytry
All in the same line..
P.S If someone of you can help me to optimize these line.. i can't find another way to check if file has already opened (because if yes, i can't overwrite the file, but just append)
THanks all..