创建指定大小的文件

#include <dirent.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

void main(int argc, char **argv)
{
int fd = 0;
int fsize = 0;
char *fname = NULL;

fname = argv[1];
fsize = atoi(argv[2]);

fd = open(fname,O_RDWR|O_CREAT|O_APPEND,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
if (fd < 0)
{
perror("open error.");
return;
}
ftruncate(fd, fsize);
close(fd);
}



原文地址:https://www.cnblogs.com/tiantao/p/2398588.html