Check file handle in C using system calls

This commit is contained in:
Fabio Scotto di Santolo
2025-06-23 17:38:46 +02:00
parent 00a33abc23
commit 85ef4163db
10 changed files with 407 additions and 0 deletions

30
chp2/fopenflags.c Normal file
View File

@@ -0,0 +1,30 @@
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
int main(void)
{
int fd;
fd = open("test.txt", O_CREAT | O_EXCL);
if (fd == -1)
perror("First open");
close(fd);
fd = open("test.txt", O_CREAT | O_EXCL);
if (fd == -1)
perror("Second open");
close(fd);
fd = open("test.txt", O_CREAT | O_EXCL);
if (fd == -1)
perror("Third open");
close(fd);
fd = open("test.txt", O_CREAT);
if (fd == -1)
perror("Fourth open");
close(fd);
return 0;
}