Mercurial > msvpvf
annotate src/common.c @ 65:03b1a105d70e
actions: CC_FLAGS->CFLAGS
author | Paper <37962225+mrpapersonic@users.noreply.github.com> |
---|---|
date | Fri, 05 Aug 2022 23:47:32 -0400 |
parents | fcd4b9fe957b |
children | 8f90d5addda9 |
rev | line source |
---|---|
47
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
1 #include <stdio.h> |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
2 #include <stdint.h> |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
3 |
58
fcd4b9fe957b
[gui.c]: show version and type in a box
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
48
diff
changeset
|
4 void set_data(unsigned char* magic, uint16_t version, FILE* target) { |
47
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
5 int i; |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
6 fseek(target, 0x46, SEEK_SET); |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
7 fputc(version, target); |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
8 for (i=0; i<=sizeof(*magic); ++i) { |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
9 fseek(target, 0x18+i, SEEK_SET); |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
10 fputc(magic[i], target); |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
11 } |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
12 } |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
13 |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
14 int copy_file(char* source_file, char* target_file) { |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
15 char ch[4096]; |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
16 FILE *source, *target; |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
17 |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
18 source = fopen(source_file, "rb"); |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
19 |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
20 if (source == NULL) |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
21 return 1; |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
22 |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
23 target = fopen(target_file, "wb"); |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
24 |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
25 if (target == NULL) { |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
26 fclose(source); |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
27 return 1; |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
28 } |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
29 |
48
652343b56a60
Remove the need for <inttypes.h> and <stdbool.h>
Paper <mrpapersonic@gmail.com>
parents:
47
diff
changeset
|
30 while (!feof(source)) { |
47
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
31 size_t b = fread(ch, 1, sizeof(ch), source); |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
32 if (b) |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
33 fwrite(ch, 1, b, target); |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
34 } |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
35 |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
36 fclose(target); |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
37 fclose(source); |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
38 return 0; |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
39 } |