2023-01-12 20:04:52 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022-2023, apio.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*
|
|
|
|
* minitar.h: The minitar header.
|
|
|
|
*/
|
|
|
|
|
2022-11-05 17:52:51 +00:00
|
|
|
#ifndef MINITAR_H
|
|
|
|
#define MINITAR_H
|
2023-01-12 19:02:13 +00:00
|
|
|
#include <stddef.h>
|
2022-11-21 19:20:37 +00:00
|
|
|
#include <stdio.h>
|
2022-11-05 19:10:48 +00:00
|
|
|
#include <sys/types.h>
|
2022-11-05 17:52:51 +00:00
|
|
|
|
|
|
|
struct minitar
|
|
|
|
{
|
|
|
|
FILE* stream;
|
|
|
|
};
|
|
|
|
|
2022-11-05 19:10:48 +00:00
|
|
|
enum minitar_file_type
|
|
|
|
{
|
|
|
|
MTAR_REGULAR,
|
2023-01-26 21:12:42 +00:00
|
|
|
MTAR_DIRECTORY,
|
2023-01-27 21:46:18 +00:00
|
|
|
MTAR_SYMLINK,
|
|
|
|
MTAR_HARDLINK,
|
2022-11-05 19:10:48 +00:00
|
|
|
};
|
|
|
|
|
2023-01-12 18:20:32 +00:00
|
|
|
struct minitar_entry_internal
|
|
|
|
{
|
|
|
|
fpos_t _mt_position;
|
|
|
|
};
|
|
|
|
|
2022-11-05 19:10:48 +00:00
|
|
|
struct minitar_entry_metadata
|
|
|
|
{
|
2022-11-23 17:32:10 +00:00
|
|
|
char path[257];
|
|
|
|
char name[128];
|
2023-01-26 21:12:42 +00:00
|
|
|
char link[101];
|
2022-11-05 19:10:48 +00:00
|
|
|
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;
|
2023-01-12 18:20:32 +00:00
|
|
|
struct minitar_entry_internal _internal;
|
2022-11-05 19:10:48 +00:00
|
|
|
};
|
|
|
|
|
2022-11-06 11:35:30 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
2022-12-25 13:33:47 +00:00
|
|
|
int minitar_open(const char* pathname, struct minitar* out);
|
|
|
|
int minitar_read_entry(struct minitar* mp, struct minitar_entry* out);
|
2022-11-06 11:35:30 +00:00
|
|
|
void minitar_rewind(struct minitar* mp);
|
2022-12-25 13:33:47 +00:00
|
|
|
int minitar_find_by_name(struct minitar* mp, const char* name, struct minitar_entry* out);
|
|
|
|
int minitar_find_by_path(struct minitar* mp, const char* path, struct minitar_entry* out);
|
|
|
|
int minitar_find_any_of(struct minitar* mp, enum minitar_file_type type, struct minitar_entry* out);
|
2023-01-12 19:03:42 +00:00
|
|
|
size_t minitar_read_contents(struct minitar* mp, const struct minitar_entry* entry, char* buf, size_t max);
|
2022-11-30 10:20:36 +00:00
|
|
|
int minitar_close(struct minitar* mp);
|
2022-11-06 11:35:30 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2022-11-05 17:52:51 +00:00
|
|
|
|
2022-12-31 11:51:47 +00:00
|
|
|
#endif
|