From 61b122fcf5f7e6941b4a89d4ba87a11471f7c520 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 5 Nov 2022 18:52:51 +0100 Subject: [PATCH] Initial groundwork --- .gitignore | 3 +++ LICENSE | 2 +- Makefile | 35 +++++++++++++++++++++++++++++++++++ minitar.h | 13 +++++++++++++ src/tar.c | 20 ++++++++++++++++++++ 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 Makefile create mode 100644 minitar.h create mode 100644 src/tar.c diff --git a/.gitignore b/.gitignore index cd531cf..b6f194b 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,6 @@ Module.symvers Mkfile.old dkms.conf +obj/ +libmtar.a +.vscode/ \ No newline at end of file diff --git a/LICENSE b/LICENSE index 5f662b3..ea56272 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) +Copyright (c) 2022, apio Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c218036 --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +OUTPUT ?= . +LIBNAME ?= libmtar +OBJDIR ?= obj +SRC := src + +CC ?= gcc +AR ?= ar +CFLAGS ?= -O2 -Wall -Wextra +CFLAGS := ${CFLAGS} -I. +DESTDIR ?= /usr/local/lib + +OBJS := $(OBJDIR)/tar.o + +build: $(OBJS) + @echo -- Creating $(LIBNAME).a + @mkdir -p $(OUTPUT) + $(AR) rcs $(OUTPUT)/$(LIBNAME).a $(OBJS) + +$(OBJDIR)/%.o: $(SRC)/%.c + @echo -- Compiling $^ + @mkdir -p $(@D) + $(CC) $(CFLAGS) -o $@ -c $^ + +install: + @echo -- Installing $(LIBNAME).a + @mkdir -p $(DESTDIR) + cp $(OUTPUT)/$(LIBNAME).a $(DESTDIR) + +clean: + rm -f $(OBJDIR)/*.o + rm -f $(OUTPUT)/$(LIBNAME).a + +uninstall: + @echo -- Removing $(LIBNAME).a + rm -f $(DESTDIR)/$(LIBNAME).a \ No newline at end of file diff --git a/minitar.h b/minitar.h new file mode 100644 index 0000000..9a09e69 --- /dev/null +++ b/minitar.h @@ -0,0 +1,13 @@ +#ifndef MINITAR_H +#define MINITAR_H +#include + +struct minitar +{ + FILE* stream; +}; + +struct minitar* minitar_open(const char* pathname); +int minitar_close(struct minitar* mp); + +#endif \ No newline at end of file diff --git a/src/tar.c b/src/tar.c new file mode 100644 index 0000000..6e91662 --- /dev/null +++ b/src/tar.c @@ -0,0 +1,20 @@ +#include +#include "minitar.h" + +struct minitar* minitar_open(const char* path) +{ + FILE* fp = fopen(path, "r"); + if(!fp) return NULL; + struct minitar* mp = malloc(sizeof(struct minitar)); + if(!mp) { fclose(fp); return NULL; } + mp->stream = fp; + return mp; +} + +int minitar_close(struct minitar* mp) +{ + int rc = fclose(mp->stream); + free(mp); + if(rc) return rc; + return 0; +} \ No newline at end of file