More advanced character device with read, write, open and release
This commit is contained in:
parent
bb9bce27f6
commit
83db8ec77e
3 changed files with 177 additions and 0 deletions
41
chardev/test.c
Normal file
41
chardev/test.c
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue