以下例程是将文件(file_extend)扩展1000字节:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
/****************************************************
*****************************************************/
int main(int argc, char* args[])
{
int fd1 = 0;
fd1 = open("file_extend",O_RDWR);
if(-1==fd1)
{
perror("open file_extend");
exit(1);
}
lseek(fd1,1000,SEEK_END);
write(fd1,"A",1);
close(fd1);
return(0);
}