Add minitar_rewind()

This commit is contained in:
apio 2022-11-06 11:22:27 +01:00
parent c05a8e1b07
commit 8507f57bc1
5 changed files with 16 additions and 3 deletions

View File

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

View File

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

View File

@ -1,9 +1,9 @@
#ifndef MINITAR_H
#define MINITAR_H
#include <stdio.h>
#include <sys/types.h>
#ifdef _IN_MINITAR
#include <stdio.h>
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

View File

@ -1,3 +1,4 @@
#define _IN_MINITAR
#include "tar.h"
#include "minitar.h"
#include <stdlib.h>
@ -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);

View File

@ -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 <stdarg.h>