microtar from mem.. -6 bad checksum
Closed this issue · 0 comments
otse commented
Hi. Nice C thing. I wrote my mem_ variants from the file_ variants.
The tar->stream was only used in these four callbacks, so I thought this would work, but I get a -6 bad checksum.
static int mem_write(mtar_t *tar, const void *data, unsigned size)
{
//unsigned res = fwrite(data, 1, size, (FILE *)tar->stream);
//return (res == size) ? MTAR_ESUCCESS : MTAR_EWRITEFAIL;
return MTAR_EWRITEFAIL;
}
static int mem_read(mtar_t *tar, void *data, unsigned size)
{
unsigned char *buf = (unsigned char *)tar->stream;
data = &buf[tar->pos];
return MTAR_ESUCCESS;
}
static int mem_seek(mtar_t *tar, unsigned offset)
{
return MTAR_ESUCCESS;
}
static int mem_close(mtar_t *tar)
{
return MTAR_ESUCCESS;
}
int mtar_open_mem(mtar_t *tar, void *data)
{
int err;
mtar_header_t h;
// Init tar struct and functions
memset(tar, 0, sizeof(*tar));
tar->write = mem_write;
tar->read = mem_read;
tar->seek = mem_seek;
tar->close = mem_close;
tar->stream = data;
err = mtar_read_header(tar, &h);
if (err != MTAR_ESUCCESS)
{
mtar_close(tar);
return err;
}
// Return ok
return MTAR_ESUCCESS;
}```