现来看二个程序。
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<string.h>
#include<unistd.h>
#include<sys/types.h>
int main()
{
int fd;
if((fd=open("test",O_RDWR|))<0)
{
perror("open");
return -1;
}
lseek(fd,-3,SEEK_END);
char buffer[32]="hello";
sleep(10);
write(fd,buffer,strlen(buffer));
close(fd);
return 0;
}
另一个程序
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<string.h>
#include<unistd.h>
#include<sys/types.h>
int main()
{
int fd;
if((fd=open("test",O_RDWR|))<0)
{
perror("open");