If you're okay with the zlib license, Nach made some modifications to zlib and let me use it for my emu ... it extracts ZIP files. You're more than welcome to use it. Extractor looks like this:
Code:
uint8_t* ZipReader::read(unsigned length) {
uint8_t *data = 0;
if(!filesize) return 0;
if(length <= filesize) {
//read the entire file into RAM
data = new(zeromemory) uint8_t[filesize];
unzReadCurrentFile(zipfile, data, filesize);
} else if(length > filesize) {
//read the entire file into RAM, pad the rest with 0x00s
data = new(zeromemory) uint8_t[length];
unzReadCurrentFile(zipfile, data, filesize);
}
return data;
}
ZipReader::ZipReader(const char *fn) : filesize(0), zipready(false) {
unz_file_info cFileInfo; //Create variable to hold info for a compressed file
char cFileName[sizeof(cname)];
if(zipfile = unzOpen(fn)) { //Open zip file
for(int cFile = unzGoToFirstFile(zipfile); cFile == UNZ_OK; cFile = unzGoToNextFile(zipfile)) {
//Gets info on current file, and places it in cFileInfo
unzGetCurrentFileInfo(zipfile, &cFileInfo, cFileName, sizeof(cname), 0, 0, 0, 0);
if((cFileInfo.uncompressed_size <= MAXROM+512) && (cFileInfo.uncompressed_size > filesize)) {
strcpy(cname, cFileName);
filesize = cFileInfo.uncompressed_size;
}
}
if(filesize) {
unzLocateFile(zipfile, cname, 1);
unzOpenCurrentFile(zipfile);
zipready = true;
}
}
}
ZipReader::~ZipReader() {
if(zipfile) {
unzCloseCurrentFile(zipfile);
unzClose(zipfile);
}
}
The zlib library itself is all in pure C89, and you could thus write your interface to it the same way, but it's pretty bulky at ~513kb.