他人の空似自作物置場

touhouSE_old.zip/touhouSE_src/lib.c

#include <stdio.h>
#include <windows.h>

char AppDir[256];

FILE *fopen2(char *fn,char *type){
	FILE *fp;
	char str[256],*s;

	fp = fopen(fn,type);
	if(fp != NULL)return fp;
	strcpy(str,fn);
	s = str;
	while(*s != '\0'){
		if(*s == '\\' || *s == '/'){
			*s = '\0';
			CreateDirectory(str,NULL);
			*s = '/';
		}
		s++;
	}
	return fopen(fn,type);
}

void SetAppDir(void){
	int i;

	GetModuleFileName(NULL,AppDir,256);
	i = strlen(AppDir)-1;
	while(AppDir[i] != '\\' && AppDir[i] != '/' && i > 0)i--;
	AppDir[i] = '\0';
	SetCurrentDirectory(AppDir);
}
unsigned int endian(unsigned int a){
	return ((unsigned char *)&a)[3] + ((unsigned char *)&a)[2]*0x100 + ((unsigned char *)&a)[1]*0x10000 + ((unsigned char *)&a)[0]*0x1000000;
}
unsigned short endian16(unsigned short a){
	return ((unsigned char *)&a)[1] + ((unsigned char *)&a)[0]*0x100;
}

unsigned long crc_table[256];
int crc_table_computed = 0;
void make_crc_table(void){
	unsigned long c;
	int n, k;

	for (n = 0; n < 256; n++) {
		c = (unsigned long)n;
		for(k = 0; k < 8; k++) {
			if (c & 1)
			c = 0xedb88320L ^ (c >> 1);
			else
			c = c >> 1;
		}
		crc_table[n] = c;
	}
	crc_table_computed = 1;
}
unsigned long crc(unsigned char *buf,int len){
	unsigned long c = 0xffffffffL;
	int n;

	if(!crc_table_computed)make_crc_table();

	for (n = 0; n < len; n++) {
		c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
	}
	return c ^ 0xffffffffL;
}