//驗證lseek和write的關系
//無論以何種方式打開文件,lseek都可以在文件中seek到任意的位置
//write寫的方式和open函數的方式有直接的關系
//如果open函數打開的時候不用O_APPEND參數,先seek到任意位置,可以在文件中的某個位置
//然后write,則沖調文件里之前的內容
//如果open函數打開的時候用O_APPEND參數,無論seek到任意位置,write都是從文件的末尾開始寫的
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
char buf[] = "$$$$$$$$$$";
int main( void )
{
int fd;
if( ( fd = open("file",O_RDWR|O_APPEND ) ) < 0 )
{
printf("Open Error!\n");
exit(1);
}
if( lseek( fd, 10, SEEK_SET ) ==-1 )
{
printf( "Seek Error!\n" );
exit(1);
}
write(fd,buf,10);
exit(0);
}