comparison src/common.c @ 47:7cb4ca7cf257

Use a common.c file to hold concurrent functions Also I fixed that 1.4 KB bug I think
author Paper <mrpapersonic@gmail.com>
date Sat, 21 May 2022 18:41:54 -0400
parents
children 652343b56a60
comparison
equal deleted inserted replaced
46:7cb9fad3f5ee 47:7cb4ca7cf257
1 #include <stdio.h>
2 #include <stdint.h>
3
4 void set_data(unsigned char magic[], uint16_t version, FILE* target) {
5 int i;
6 fseek(target, 0x46, SEEK_SET);
7 fputc(version, target);
8 for (i=0; i<=sizeof(*magic); ++i) {
9 fseek(target, 0x18+i, SEEK_SET);
10 fputc(magic[i], target);
11 }
12 }
13
14 int copy_file(char* source_file, char* target_file) {
15 char ch[4096];
16 FILE *source, *target;
17
18 source = fopen(source_file, "rb");
19
20 if (source == NULL)
21 return 1;
22
23 target = fopen(target_file, "wb");
24
25 if (target == NULL) {
26 fclose(source);
27 return 1;
28 }
29
30 while (fgetc(source) != EOF) {
31 size_t b = fread(ch, 1, sizeof(ch), source);
32 if (b)
33 fwrite(ch, 1, b, target);
34 }
35
36 fclose(target);
37 fclose(source);
38 return 0;
39 }