代码:
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#define FILENAME "a.c"
#define READBUFFERSIZE 128
int main()
{
int fd=open(FILENAME,O_RDWR | O_CREAT);
char write_buffer[]="hello world";
write(fd,write_buffer,sizeof(write_buffer));
close(fd);
int fd0=open(FILENAME,O_RDONLY);
char read_buffer[READBUFFERSIZE]={0};
read(fd0,read_buffer,127);
printf("%s\n",read_buffer);
close(fd0);
return 0;
}