minitar/minitar.h
apio d123c49946 Do not automatically read an entry's contents, leave it up to the user
This API change modifies minitar_read_entry to skip over the file's contents and instead store the current read position in the entry.

struct minitar_entry no longer has a ptr field, but has a position field (of type fpos_t) for internal use.

minitar_free_entry no longer frees entry->ptr.

A new function has been added, minitar_read_contents().
It reads a certain number of bytes from an entry (which is capped to the entry's size) into a user-provided buffer.
This function can be called at any time provided it is called with a valid archive stream and entry.
This is achieved by calling fgetpos() to store the start of the entry's contents in the entry's position field while reading it.
Then minitar_read_contents() will store the current position, rewind to the entry's position, read the chosen number of bytes from the archive, and then rewind back to the current position.

Since this is a breaking change, it needs a major version bump. Since there was no version, I bumped it to 1.0.0 :)
2022-11-21 20:20:37 +01:00

60 lines
1.2 KiB
C

#ifndef MINITAR_H
#define MINITAR_H
#include <stdio.h>
#include <sys/types.h>
#ifdef _IN_MINITAR
struct minitar
{
FILE* stream;
};
#else
struct minitar;
#endif
enum minitar_file_type
{
MTAR_REGULAR,
MTAR_CHRDEV,
MTAR_BLKDEV,
MTAR_DIRECTORY
};
struct minitar_entry_metadata
{
char name[257];
mode_t mode;
uid_t uid;
gid_t gid;
size_t size;
time_t mtime;
enum minitar_file_type type;
char uname[32];
char gname[32];
};
struct minitar_entry
{
struct minitar_entry_metadata metadata;
fpos_t position;
};
#ifdef __cplusplus
extern "C"
{
#endif
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);
struct minitar_entry* minitar_find_by_name(struct minitar* mp, const char* name);
struct minitar_entry* minitar_find_any_of(struct minitar* mp, enum minitar_file_type type);
int minitar_close(struct minitar* mp);
size_t minitar_read_contents(struct minitar* mp, struct minitar_entry* entry, char* buf, size_t max);
#ifdef __cplusplus
}
#endif
#endif