Initial groundwork
This commit is contained in:
parent
10159e1acc
commit
61b122fcf5
3
.gitignore
vendored
3
.gitignore
vendored
@ -52,3 +52,6 @@ Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
obj/
|
||||
libmtar.a
|
||||
.vscode/
|
2
LICENSE
2
LICENSE
@ -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
35
Makefile
Normal 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
13
minitar.h
Normal 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
20
src/tar.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user