tarw.h
Minimalist header-only library for generating TAR files
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#include <stdlib.h> #include <stdio.h> #define TARW_IMPLEMENTATION #include "tarw.h" int main(void) { const char *output_path = "./test.tar"; FILE *sink = fopen(output_path, "wb"); if (sink == NULL) { fprintf(stderr, "ERROR: could not open \"%s\"\n", output_path); return EXIT_FAILURE; } TarWriter w = { .sink = sink, .owner = "user", .group = "group", .owner_id = 1000, .group_id = 1000, }; if (!tarw_write_directory(w, "test/", 0755)) goto error; const char *msg = "Hello from C!\n"; if (!tarw_write_file(w, "test/a", 0644, msg, strlen(msg))) goto error; return EXIT_SUCCESS; error: fprintf(stderr, "ERROR: could write all bytes to \"%s\"\n", output_path); return EXIT_FAILURE; }