#include #include #include enum { bufsize = 16, }; typedef char byte; struct listing { long id, folder_id, size; char *uuid, *filename, *upload_status, *content_type, *url; char *created_at, *updated_at, *unlock_at, *lock_at, thumbnail_url; char *modified_at, *mime_class, *media_entry_id, *category; byte locked, hidden, hidden_for_user, locked_for_user; }; typedef struct listing Listing; int main() { FILE* infile = fopen("dump", "r"); if (infile == NULL) { fprintf(stderr, "No dump provided. Run dump.sh.\n"); } char buf[bufsize]; char *contents = NULL; int read, size = 0; while ((read = fread(buf, 1, bufsize, infile)) > 0) { size += read; contents = realloc(contents, size); memmove(&contents[size-read], buf, read); } int i, j = 0; char ch; Listing *l = calloc(1, sizeof(Listing)); int l_size = sizeof(Listing); for (i = 0; i < size; i++) { ch = contents[i]; switch (ch) { case '\n': j++; l_size += sizeof(Listing); l = realloc(l, l_size); break; default: } } printf("%d\n", l_size); return 0; }