diff --git a/Makefile b/Makefile index c30a732..584c692 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ SRC := src CC ?= gcc AR ?= ar CFLAGS ?= -O2 -Wall -Wextra -CFLAGS := ${CFLAGS} -I. -D_IN_MINITAR +CFLAGS := ${CFLAGS} -I. DESTDIR ?= /usr/local OBJS := $(OBJ)/tar.o \ diff --git a/README.md b/README.md index 25cbc92..464405e 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,11 @@ This function returns NULL on end-of-file (when all entries have been read). Frees the heap-allocated `struct minitar_entry` and the file contents stored inside it. The pointer passed to `minitar_free_entry()` should be the return value of a previous call to `minitar_read_entry()`. +### minitar_rewind +`void minitar_rewind(struct minitar* mp)` + +Rewinds the `struct minitar` back to the beginning of the archive file, which means that the next call to `minitar_read_entry()` will return the first entry instead of the entry after the last read entry. + ### minitar_close `int minitar_close(struct minitar* mp)` diff --git a/minitar.h b/minitar.h index a99b3f4..e8ad393 100644 --- a/minitar.h +++ b/minitar.h @@ -1,9 +1,9 @@ #ifndef MINITAR_H #define MINITAR_H -#include #include #ifdef _IN_MINITAR +#include struct minitar { FILE* stream; @@ -42,6 +42,7 @@ struct minitar_entry struct minitar* minitar_open(const char* pathname); struct minitar_entry* minitar_read_entry(struct minitar* mp); void minitar_free_entry(struct minitar_entry* entry); +void minitar_rewind(struct minitar* mp); int minitar_close(struct minitar* mp); #endif \ No newline at end of file diff --git a/src/tar.c b/src/tar.c index b833203..b7cb056 100644 --- a/src/tar.c +++ b/src/tar.c @@ -1,3 +1,4 @@ +#define _IN_MINITAR #include "tar.h" #include "minitar.h" #include @@ -62,6 +63,11 @@ struct minitar_entry* minitar_read_entry(struct minitar* mp) return result; } +void minitar_rewind(struct minitar* mp) +{ + rewind(mp->stream); +} + void minitar_free_entry(struct minitar_entry* entry) { free(entry->ptr); diff --git a/src/util.c b/src/util.c index dd9747b..6fbe10d 100644 --- a/src/util.c +++ b/src/util.c @@ -1,4 +1,5 @@ -#define _POSIX_C_SOURCE 200809L +#define _POSIX_C_SOURCE 200809L // for strndup +#define _IN_MINITAR #include "minitar.h" #include "tar.h" #include