Skip to content

Instantly share code, notes, and snippets.

@wereii
Last active May 29, 2021 14:38
Show Gist options
  • Save wereii/6711de7e21667f0cf6d19e685524b560 to your computer and use it in GitHub Desktop.
Save wereii/6711de7e21667f0cf6d19e685524b560 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <raylib.h>
int main(){
FILE * pFile;
long lSize;
unsigned char * buffer;
size_t result;
pFile = fopen("hi.z", "rb");
if (pFile == NULL) {
fputs("File error",stderr);
exit(1);
} else {
puts("File 'hi.z' open");
}
fseek(pFile, 0, SEEK_END);
lSize = ftell(pFile);
printf("Content size is %ld\n", lSize);
rewind(pFile);
int buff_siz = lSize + 1;
buffer = malloc(sizeof(char) * buff_siz);
if (buffer == NULL) {
fputs("Memory error", stderr);
exit(2);
}
memset(buffer, 0, sizeof(char) * buff_siz);
result = fread(buffer, 1, lSize, pFile);
if (result != lSize) {
fputs("Reading error", stderr);
exit(3);
} else {
puts("Reading file ok");
};
int len;
unsigned char* decomp;
decomp = DecompressData(buffer, lSize, &len);
// useless, decomp is never null even on fails
if (decomp != NULL) {
printf("Decomp size: %d\n", len);
printf("%s\n", dec); // segfaults
} else {
puts("Fail\n");
}
fclose(pFile);
free(buffer);
free(dec);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment