Files
2026-06-25 00:09:09 +08:00

21 lines
474 B
C

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
int main() {
int testdev = open("/dev/mydev", O_RDWR);
if (testdev == -1) {
printf("can not open file\n");
exit(0);
}
char buf[50] = "pear to dev!";
write(testdev, buf, 50);
printf("write: %s\n", buf);
strcpy(buf, "apple to dev!");
read(testdev, buf, 50);
printf("read: %s\n", buf);
close(testdev);
return 0;
}