Skip to content

Instantly share code, notes, and snippets.

@Daaaav

Daaaav/main.c Secret

Created May 20, 2022 01:35
Show Gist options
  • Save Daaaav/ac0df88b883ac4318bc1c03d233f322c to your computer and use it in GitHub Desktop.
Save Daaaav/ac0df88b883ac4318bc1c03d233f322c to your computer and use it in GitHub Desktop.
Test PHYSFS zip enumerator
#include <stdio.h>
#include <stdlib.h>
#include <physfs.h>
int main(int argc, char *argv[])
{
if (argc < 2)
{
puts("Please give a zip name to test");
return 0;
}
if (!PHYSFS_init(argv[0]))
{
puts("Cannot init!");
return 0;
}
if (!PHYSFS_mount(argv[1], NULL, 1))
{
puts("Cannot mount that!");
return 0;
}
char** fileList = PHYSFS_enumerateFiles("");
if (fileList == NULL)
{
printf("Cannot enumerate files! %s\n",
PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())
);
return 0;
}
for (char** item = fileList; *item != NULL; item++)
{
printf("File %s: ", *item);
PHYSFS_File* handle = PHYSFS_openRead(*item);
if (handle == NULL)
{
printf("Failure opening file. %s\n",
PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())
);
}
else
{
PHYSFS_sint64 length = PHYSFS_fileLength(handle);
char* mem = malloc(length);
PHYSFS_sint64 read = PHYSFS_readBytes(handle, mem, length);
if (read == -1)
{
printf("Failure reading file. %s\n",
PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())
);
}
else
{
printf("%lld/%lld bytes\n", read, length);
}
free(mem);
PHYSFS_close(handle);
}
}
PHYSFS_freeList(fileList);
PHYSFS_deinit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment