makefile and test.c
texrg opened this issue · 0 comments
texrg commented
Please add file with main() function and makefile like this
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a3f6503
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,10 @@
+*.tmp
+*.o
+*.*~
+*.d
+*.dSYM
+*.swp
+
+test
+*.tar
+*.txt
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..ef8d87e
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,20 @@
+CC = gcc
+BIN = test
+
+# Flags
+CFLAGS += -std=c99 -Wall -pedantic -pedantic-errors -O2
+
+SRC = $(BIN).c
+OBJ = $(SRC:.c=.o)
+
+$(BIN): ./src/microtar.o $(BIN).c
+ rm -f $(BIN) $(OBJS)
+ $(CC) $(SRC) -I./src $(CFLAGS) -o $(BIN) $(LIBS) ./src/microtar.o
+
+./src/microtar.o: ./src/microtar.c ./src/microtar.h
+ $(CC) $(CFLAGS) -c -o ./src/microtar.o ./src/microtar.c
+
+.PHONY: clean
+
+clean:
+ rm -f ./$(BIN) ./*.tar ./*.txt ./src/*.o
diff --git a/test.c b/test.c
new file mode 100644
index 0000000..0a906dc
--- /dev/null
+++ b/test.c
@@ -0,0 +1,29 @@
+#include <string.h>
+#include "microtar.h"
+
+int main(void)
+{
+
+mtar_t tar;
+/* utf-8 chars */
+const char *str1 = "Hello world, Witaj świecie";
+const char *str2 = "Goodbye world, żegnam";
+
+/* Open archive for writing */
+mtar_open(&tar, "test.tar", "w");
+
+/* Write strings to files `test1.txt` and `test2.txt` */
+/* no setup data */
+mtar_write_file_header(&tar, "test1.txt", strlen(str1));
+mtar_write_data(&tar, str1, strlen(str1));
+mtar_write_file_header(&tar, "test2.txt", strlen(str2));
+mtar_write_data(&tar, str2, strlen(str2));
+
+/* Finalize -- this needs to be the last thing done before closing */
+mtar_finalize(&tar);
+
+/* Close archive */
+mtar_close(&tar);
+
+return 0;
+}