view src/common.c @ 58:fcd4b9fe957b

[gui.c]: show version and type in a box
author Paper <37962225+mrpapersonic@users.noreply.github.com>
date Thu, 21 Jul 2022 00:46:18 -0400
parents 652343b56a60
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;
}