test_write.c
来自「内核空间地址向用户空间地址的映射实例」· C语言 代码 · 共 29 行
C
29 行
#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>int main(int argc,char **argv){ int fd = 0; int pid = 0; char buffer[20] = {'\0'}; char write_buffer[20] = {'\0'}; strcpy(write_buffer,"zhanglinbao"); fd = open("/dev/hello",O_RDWR | O_CREAT | O_TRUNC); //fd = open("/dev/hello",O_RDONLY); printf("fd=%d\n",fd); if(fd < 0) { perror("/dev/hello"); return -1; } write(fd,write_buffer,sizeof(write_buffer)-1); close(fd); return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?