Add a way to override the panic function
This commit is contained in:
parent
bdb500b290
commit
f2fdf726ce
10
src/util.c
10
src/util.c
@ -8,12 +8,17 @@
|
|||||||
#include <stdnoreturn.h>
|
#include <stdnoreturn.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
noreturn void minitar_panic(const char* message)
|
__attribute__((weak)) noreturn void minitar_handle_panic(const char* message)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "minitar: %s\n", message);
|
fprintf(stderr, "minitar: %s\n", message);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
noreturn void minitar_panic(const char* message)
|
||||||
|
{
|
||||||
|
minitar_handle_panic(message);
|
||||||
|
}
|
||||||
|
|
||||||
void minitar_parse_tar_header(struct tar_header* hdr, struct minitar_entry_metadata* metadata)
|
void minitar_parse_tar_header(struct tar_header* hdr, struct minitar_entry_metadata* metadata)
|
||||||
{
|
{
|
||||||
if (!strlen(hdr->prefix))
|
if (!strlen(hdr->prefix))
|
||||||
@ -67,8 +72,9 @@ int minitar_validate_header(struct tar_header* hdr)
|
|||||||
|
|
||||||
int minitar_read_header(struct minitar* mp, struct tar_header* hdr)
|
int minitar_read_header(struct minitar* mp, struct tar_header* hdr)
|
||||||
{
|
{
|
||||||
size_t rc = fread(hdr, sizeof *hdr, 1, mp->stream);
|
size_t rc = fread(hdr, 1, sizeof *hdr, mp->stream);
|
||||||
if (rc == 0 && feof(mp->stream)) return 0;
|
if (rc == 0 && feof(mp->stream)) return 0;
|
||||||
|
if (rc < sizeof *hdr) minitar_panic("Valid tar files should be split in 512-byte blocks");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user