#include "stdio.h" #include "unistd.h" #include "sys/types.h" #include "sys/stat.h" #include "fcntl.h" #include "stdlib.h" #include "string.h" int main(int argc, char *argv[]) { int fd; char buf[32]; char write_buf[] = "write_success"; char filename[32] = "/dev/test"; fd = open(filename, O_RDWR); if(fd < 0){ printf("file %s open failed!\r\n", argv[1]); return -1; } read(fd,buf,sizeof(buf)); write(fd,write_buf,sizeof(write_buf)); printf("%s\n",buf); printf("open *******\n"); close(fd); return 0; }