More advanced character device with read, write, open and release

This commit is contained in:
Imbus 2025-05-10 12:51:32 +02:00
parent bb9bce27f6
commit 83db8ec77e
3 changed files with 177 additions and 0 deletions

41
chardev/test.c Normal file
View file

@ -0,0 +1,41 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
int main(int argc, char **argv) {
int fd;
if (argc < 2) {
printf("I need the file to open as an argument!\n");
return 0;
}
fd = open(argv[1], O_RDONLY);
if (fd < 0) {
perror("open");
return fd;
}
close (fd);
fd = open(argv[1], O_RDWR | O_SYNC);
if (fd < 0) {
perror("open");
return fd;
}
close (fd);
fd = open(argv[1], O_WRONLY | O_NONBLOCK);
if (fd < 0) {
perror("open");
return fd;
}
close (fd);
return 0;
}