Initial groundwork

This commit is contained in:
apio 2022-11-05 18:52:51 +01:00
parent 10159e1acc
commit 61b122fcf5
5 changed files with 72 additions and 1 deletions

3
.gitignore vendored
View File

@ -52,3 +52,6 @@ Module.symvers
Mkfile.old
dkms.conf
obj/
libmtar.a
.vscode/

View File

@ -1,4 +1,4 @@
Copyright (c) <year> <owner>
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:

35
Makefile Normal file
View File

@ -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

13
minitar.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef MINITAR_H
#define MINITAR_H
#include <stdio.h>
struct minitar
{
FILE* stream;
};
struct minitar* minitar_open(const char* pathname);
int minitar_close(struct minitar* mp);
#endif

20
src/tar.c Normal file
View File

@ -0,0 +1,20 @@
#include <stdlib.h>
#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;
}