Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support bigger than 4GB file #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/microtar.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ static unsigned checksum(const mtar_raw_header_t* rh) {
}


static int tread(mtar_t *tar, void *data, unsigned size) {
static int tread(mtar_t *tar, void *data, size_t size) {
int err = tar->read(tar, data, size);
tar->pos += size;
return err;
}


static int twrite(mtar_t *tar, const void *data, unsigned size) {
static int twrite(mtar_t *tar, const void *data, size_t size) {
int err = tar->write(tar, data, size);
tar->pos += size;
return err;
Expand Down Expand Up @@ -153,17 +153,17 @@ const char* mtar_strerror(int err) {
}


static int file_write(mtar_t *tar, const void *data, unsigned size) {
unsigned res = fwrite(data, 1, size, tar->stream);
static int file_write(mtar_t *tar, const void *data, size_t size) {
size_t res = fwrite(data, 1, size, tar->stream);
return (res == size) ? MTAR_ESUCCESS : MTAR_EWRITEFAIL;
}

static int file_read(mtar_t *tar, void *data, unsigned size) {
unsigned res = fread(data, 1, size, tar->stream);
static int file_read(mtar_t *tar, void *data, size_t size) {
size_t res = fread(data, 1, size, tar->stream);
return (res == size) ? MTAR_ESUCCESS : MTAR_EREADFAIL;
}

static int file_seek(mtar_t *tar, unsigned offset) {
static int file_seek(mtar_t *tar, long offset) {
int res = fseek(tar->stream, offset, SEEK_SET);
return (res == 0) ? MTAR_ESUCCESS : MTAR_ESEEKFAIL;
}
Expand Down Expand Up @@ -213,7 +213,7 @@ int mtar_close(mtar_t *tar) {
}


int mtar_seek(mtar_t *tar, unsigned pos) {
int mtar_seek(mtar_t *tar, long pos) {
int err = tar->seek(tar, pos);
tar->pos = pos;
return err;
Expand Down Expand Up @@ -287,7 +287,7 @@ int mtar_read_header(mtar_t *tar, mtar_header_t *h) {
}


int mtar_read_data(mtar_t *tar, void *ptr, unsigned size) {
int mtar_read_data(mtar_t *tar, void *ptr, size_t size) {
int err;
/* If we have no remaining data then this is the first read, we get the size,
* set the remaining data and seek to the beginning of the data */
Expand Down Expand Up @@ -329,7 +329,7 @@ int mtar_write_header(mtar_t *tar, const mtar_header_t *h) {
}


int mtar_write_file_header(mtar_t *tar, const char *name, unsigned size) {
int mtar_write_file_header(mtar_t *tar, const char *name, size_t size) {
mtar_header_t h;
/* Build header */
memset(&h, 0, sizeof(h));
Expand All @@ -354,7 +354,7 @@ int mtar_write_dir_header(mtar_t *tar, const char *name) {
}


int mtar_write_data(mtar_t *tar, const void *data, unsigned size) {
int mtar_write_data(mtar_t *tar, const void *data, size_t size) {
int err;
/* Write data */
err = twrite(tar, data, size);
Expand Down
22 changes: 11 additions & 11 deletions src/microtar.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ typedef struct {
typedef struct mtar_t mtar_t;

struct mtar_t {
int (*read)(mtar_t *tar, void *data, unsigned size);
int (*write)(mtar_t *tar, const void *data, unsigned size);
int (*seek)(mtar_t *tar, unsigned pos);
int (*read)(mtar_t *tar, void *data, size_t size);
int (*write)(mtar_t *tar, const void *data, size_t size);
int (*seek)(mtar_t *tar, long pos);
int (*close)(mtar_t *tar);
void *stream;
unsigned pos;
unsigned remaining_data;
unsigned last_header;
FILE *stream;
size_t pos;
size_t remaining_data;
size_t last_header;
};


Expand All @@ -70,17 +70,17 @@ const char* mtar_strerror(int err);
int mtar_open(mtar_t *tar, const char *filename, const char *mode);
int mtar_close(mtar_t *tar);

int mtar_seek(mtar_t *tar, unsigned pos);
int mtar_seek(mtar_t *tar, long pos);
int mtar_rewind(mtar_t *tar);
int mtar_next(mtar_t *tar);
int mtar_find(mtar_t *tar, const char *name, mtar_header_t *h);
int mtar_read_header(mtar_t *tar, mtar_header_t *h);
int mtar_read_data(mtar_t *tar, void *ptr, unsigned size);
int mtar_read_data(mtar_t *tar, void *ptr, size_t size);

int mtar_write_header(mtar_t *tar, const mtar_header_t *h);
int mtar_write_file_header(mtar_t *tar, const char *name, unsigned size);
int mtar_write_file_header(mtar_t *tar, const char *name, size_t size);
int mtar_write_dir_header(mtar_t *tar, const char *name);
int mtar_write_data(mtar_t *tar, const void *data, unsigned size);
int mtar_write_data(mtar_t *tar, const void *data, size_t size);
int mtar_finalize(mtar_t *tar);

#ifdef __cplusplus
Expand Down