Mercurial > msvpvf
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/common.c Sat May 21 18:41:54 2022 -0400 @@ -0,0 +1,39 @@ +#include <stdio.h> +#include <stdint.h> + +void set_data(unsigned char magic[], uint16_t version, FILE* target) { + int i; + fseek(target, 0x46, SEEK_SET); + fputc(version, target); + for (i=0; i<=sizeof(*magic); ++i) { + fseek(target, 0x18+i, SEEK_SET); + fputc(magic[i], target); + } +} + +int copy_file(char* source_file, char* target_file) { + char ch[4096]; + FILE *source, *target; + + source = fopen(source_file, "rb"); + + if (source == NULL) + return 1; + + target = fopen(target_file, "wb"); + + if (target == NULL) { + fclose(source); + return 1; + } + + while (fgetc(source) != EOF) { + size_t b = fread(ch, 1, sizeof(ch), source); + if (b) + fwrite(ch, 1, b, target); + } + + fclose(target); + fclose(source); + return 0; +}