利用lseek()函数创建一个固定大小的文件

来源:互联网 发布:瞻博网络薪资 编辑:程序博客网 时间:2024/05/05 21:31
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>int main(int argc,char ** argv){    int fd;    fd = open(argv[1], O_CREAT|O_TRUNC|O_RDWR,S_IRUSR|S_IWUSR);    if( fd < 0 )    {        perror("open()");        exit(1);    }    lseek(fd,499,SEEK_SET);    write(fd,"1",1);    close(fd);    exit(0);}

1 0
原创粉丝点击