这个程序主要解决一些嵌入式系统没有 split指令,无法对大文件进行分离打包
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

56 lines
1000 B

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
const char *get_packet_name(const char *filename, int num)
{
static char buf[256] = {0};
sprintf(buf, "%s.%d", filename, num);
return buf;
}
int main(int argc, char const *argv[])
{
//打开输入文件
int fd = open(argv[1], O_RDONLY);
if (fd < 0)
{
perror("openfail");
exit(-1);
}
int fileindex = 1;
uint32_t sumcheck = 0;
uint8_t *data = malloc(100 * 1024 * 1024);
if (data == NULL)
{
perror("malloc fail");
exit(-1);
}
while (1)
{
int readlen = read(fd, data, 100 * 1024 * 1024);
if (readlen <= 0)
{
printf("write end\n");
break;
}
for (size_t i = 0; i < readlen; i++)
{
sumcheck += data[i];
}
}
printf("sumcheck %d\n", sumcheck);
return 0;
}