view src/common.c @ 63:a2e979245441 v1.2.3

paper is retarded and caused a segfault episode 1
author Paper <37962225+mrpapersonic@users.noreply.github.com>
date Mon, 01 Aug 2022 21:41:54 -0400
parents fcd4b9fe957b
children 8f90d5addda9
line wrap: on
line source

#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 (!feof(source)) {
		size_t b = fread(ch, 1, sizeof(ch), source);
		if (b)
			fwrite(ch, 1, b, target);
	}

	fclose(target);
	fclose(source);
	return 0;
}