Browse Source

update

master
zhaohe 3 years ago
commit
640d693922
  1. 21
      README.md
  2. 6
      build.sh
  3. BIN
      release/v1/arm32-gcc-linaro-5.4.1.x86_64_arm-linux-gnueabihf/sumcheck
  4. BIN
      release/v1/arm32-gcc-linaro-5.4.1.x86_64_arm-linux-gnueabihf/zsplit
  5. BIN
      release/v1/x64_ubuntu2004/sumcheck
  6. BIN
      release/v1/x64_ubuntu2004/zsplit
  7. 56
      sumcheck.c
  8. 67
      zsplit.c

21
README.md

@ -0,0 +1,21 @@
# 文件分离程序
```
概述:
这个程序主要解决一些嵌入式系统没有 split指令,无法对大文件进行分离打包
Usage:
zsplit 文件名字
@执行完之后会自动将文件分离成100M为单位大小的文件
sumcheck
@对文件求一个sum8的和,和的结果用u32保存
```
# 编译
```
export CC=gcc
./build.sh
```

6
build.sh

@ -0,0 +1,6 @@
#!/bin/bash
CC=/home/zwsd/Desktop/workspace/project_meditation_capsule/HappySwitchSoundBox/toolchain/gcc-linaro-5.4.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
${CC} sumcheck.c -o sumcheck
${CC} zsplit.c -o zsplit

BIN
release/v1/arm32-gcc-linaro-5.4.1.x86_64_arm-linux-gnueabihf/sumcheck

BIN
release/v1/arm32-gcc-linaro-5.4.1.x86_64_arm-linux-gnueabihf/zsplit

BIN
release/v1/x64_ubuntu2004/sumcheck

BIN
release/v1/x64_ubuntu2004/zsplit

56
sumcheck.c

@ -0,0 +1,56 @@
#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;
}

67
zsplit.c

@ -0,0 +1,67 @@
#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("create %s(%d)\n", get_packet_name(argv[1], fileindex), readlen);
int tofd = open(get_packet_name(argv[1], fileindex), O_TRUNC | O_RDWR | O_CREAT,666);
int writenum = write(tofd, data, readlen);
if (writenum != readlen)
{
printf("Error: write fail,writenum!=readlen,%d != %d\n", writenum, readlen);
exit(0);
}
close(tofd);
fileindex++;
}
printf("sumcheck %d\n", sumcheck);
return 0;
}
Loading…
Cancel
Save