diff options
Diffstat (limited to 'woip/c/blocks.c')
-rw-r--r-- | woip/c/blocks.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/woip/c/blocks.c b/woip/c/blocks.c new file mode 100644 index 0000000..6ac2cf7 --- /dev/null +++ b/woip/c/blocks.c @@ -0,0 +1,40 @@ +#include <sys/mman.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include "debug.h" +#include "safe.h" + +#define MAXLINE 1024 +#define MAXBLOCK 10000 + +uint64_t store[MAXBLOCK]; + +uint64_t *load_block_map(char *file) { + int nblocks; + void *ptr; + FILE *fp = xfopen(file, "r"); + + fread(&nblocks, sizeof(nblocks), 1, fp); + ptr = xmmap(NULL, nblocks * sizeof(uint64_t), PROT_READ, MAP_SHARED, fileno(fp), 0); + + return ptr + sizeof(nblocks); +} + +#ifdef INCLUDE_MAIN +int main(int argc, char **argv) { + char line[MAXLINE]; + int pos = 0; + + while(fgets(line, MAXLINE, stdin)) + store[pos++] = (uint64_t) strtoll(line, NULL, 10); + + FILE *bFile = xfopen(argv[1], "w"); + + fwrite(&pos, sizeof(pos), 1, bFile); + fwrite(store, sizeof(uint64_t), pos, bFile); + fclose(bFile); + + return 0; +} +#endif |