Crossfire Server, Trunk
microtar.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include "microtar.h"
+ Include dependency graph for microtar.c:

Go to the source code of this file.

Data Structures

struct  mtar_raw_header_t
 

Functions

static unsigned checksum (const mtar_raw_header_t *rh)
 
static int file_close (mtar_t *tar)
 
static int file_read (mtar_t *tar, void *data, unsigned size)
 
static int file_seek (mtar_t *tar, unsigned offset)
 
static int file_write (mtar_t *tar, const void *data, unsigned size)
 
static int header_to_raw (mtar_raw_header_t *rh, const mtar_header_t *h)
 
int mtar_close (mtar_t *tar)
 
int mtar_finalize (mtar_t *tar)
 
int mtar_find (mtar_t *tar, const char *name, mtar_header_t *h)
 
int mtar_next (mtar_t *tar)
 
int mtar_open (mtar_t *tar, const char *filename, const char *mode)
 
int mtar_read_data (mtar_t *tar, void *ptr, unsigned size)
 
int mtar_read_header (mtar_t *tar, mtar_header_t *h)
 
int mtar_rewind (mtar_t *tar)
 
int mtar_seek (mtar_t *tar, unsigned pos)
 
const char * mtar_strerror (int err)
 
int mtar_write_data (mtar_t *tar, const void *data, unsigned size)
 
int mtar_write_dir_header (mtar_t *tar, const char *name)
 
int mtar_write_file_header (mtar_t *tar, const char *name, unsigned size)
 
int mtar_write_header (mtar_t *tar, const mtar_header_t *h)
 
static int raw_to_header (mtar_header_t *h, const mtar_raw_header_t *rh)
 
static unsigned round_up (unsigned n, unsigned incr)
 
static int tread (mtar_t *tar, void *data, unsigned size)
 
static int twrite (mtar_t *tar, const void *data, unsigned size)
 
static int write_null_bytes (mtar_t *tar, int n)
 

Function Documentation

◆ checksum()

static unsigned checksum ( const mtar_raw_header_t rh)
static

Definition at line 49 of file microtar.c.

References offsetof, altar_valkyrie::res, and is_valid_types_gen::type.

Referenced by header_to_raw(), raw_to_header(), and save_player().

+ Here is the caller graph for this function:

◆ file_close()

static int file_close ( mtar_t tar)
static

Definition at line 171 of file microtar.c.

References MTAR_ESUCCESS, and mtar_t::stream.

Referenced by mtar_open().

+ Here is the caller graph for this function:

◆ file_read()

static int file_read ( mtar_t tar,
void *  data,
unsigned  size 
)
static

Definition at line 161 of file microtar.c.

References navar-midane_time::data, MTAR_EREADFAIL, MTAR_ESUCCESS, altar_valkyrie::res, and mtar_t::stream.

Referenced by mtar_open().

+ Here is the caller graph for this function:

◆ file_seek()

static int file_seek ( mtar_t tar,
unsigned  offset 
)
static

Definition at line 166 of file microtar.c.

References MTAR_ESEEKFAIL, MTAR_ESUCCESS, altar_valkyrie::res, and mtar_t::stream.

Referenced by mtar_open().

+ Here is the caller graph for this function:

◆ file_write()

static int file_write ( mtar_t tar,
const void *  data,
unsigned  size 
)
static

Definition at line 156 of file microtar.c.

References navar-midane_time::data, MTAR_ESUCCESS, MTAR_EWRITEFAIL, altar_valkyrie::res, and mtar_t::stream.

Referenced by mtar_open().

+ Here is the caller graph for this function:

◆ header_to_raw()

◆ mtar_close()

int mtar_close ( mtar_t tar)

Definition at line 211 of file microtar.c.

References mtar_t::close.

Referenced by assets_pack(), TarLoader::load(), and mtar_open().

+ Here is the caller graph for this function:

◆ mtar_finalize()

int mtar_finalize ( mtar_t tar)

Definition at line 373 of file microtar.c.

References write_null_bytes().

Referenced by assets_pack().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mtar_find()

int mtar_find ( mtar_t tar,
const char *  name,
mtar_header_t h 
)

Definition at line 244 of file microtar.c.

References hall_of_fame::header, MTAR_ENOTFOUND, MTAR_ENULLRECORD, MTAR_ESUCCESS, mtar_next(), mtar_read_header(), mtar_rewind(), and give::name.

+ Here is the call graph for this function:

◆ mtar_next()

int mtar_next ( mtar_t tar)

Definition at line 230 of file microtar.c.

References mtar_read_header(), mtar_seek(), mtar_t::pos, round_up(), and mtar_header_t::size.

Referenced by TarLoader::load(), and mtar_find().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mtar_open()

int mtar_open ( mtar_t tar,
const char *  filename,
const char *  mode 
)

Definition at line 177 of file microtar.c.

References mtar_t::close, file_close(), file_read(), file_seek(), file_write(), npc_dialog::filename, mtar_close(), MTAR_EOPENFAIL, MTAR_ESUCCESS, mtar_read_header(), mtar_t::read, mtar_t::seek, mtar_t::stream, and mtar_t::write.

Referenced by assets_pack().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mtar_read_data()

int mtar_read_data ( mtar_t tar,
void *  ptr,
unsigned  size 
)

Definition at line 290 of file microtar.c.

References mtar_t::last_header, MTAR_ESUCCESS, mtar_read_header(), mtar_seek(), mtar_t::pos, mtar_t::remaining_data, mtar_header_t::size, and tread().

Referenced by bufferreader_init_from_tar_file().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mtar_read_header()

int mtar_read_header ( mtar_t tar,
mtar_header_t h 
)

Definition at line 270 of file microtar.c.

References mtar_t::last_header, mtar_seek(), mtar_t::pos, raw_to_header(), and tread().

Referenced by TarLoader::load(), mtar_find(), mtar_next(), mtar_open(), and mtar_read_data().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mtar_rewind()

int mtar_rewind ( mtar_t tar)

Definition at line 223 of file microtar.c.

References mtar_t::last_header, mtar_seek(), and mtar_t::remaining_data.

Referenced by mtar_find().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mtar_seek()

int mtar_seek ( mtar_t tar,
unsigned  pos 
)

Definition at line 216 of file microtar.c.

References mtar_t::pos, and mtar_t::seek.

Referenced by mtar_next(), mtar_read_data(), mtar_read_header(), and mtar_rewind().

+ Here is the caller graph for this function:

◆ mtar_strerror()

const char* mtar_strerror ( int  err)

◆ mtar_write_data()

int mtar_write_data ( mtar_t tar,
const void *  data,
unsigned  size 
)

Definition at line 357 of file microtar.c.

References navar-midane_time::data, MTAR_ESUCCESS, mtar_t::pos, mtar_t::remaining_data, round_up(), twrite(), and write_null_bytes().

Referenced by add_to_tar().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mtar_write_dir_header()

int mtar_write_dir_header ( mtar_t tar,
const char *  name 
)

Definition at line 345 of file microtar.c.

References mtar_header_t::mode, MTAR_TDIR, mtar_write_header(), give::name, mtar_header_t::name, and mtar_header_t::type.

+ Here is the call graph for this function:

◆ mtar_write_file_header()

int mtar_write_file_header ( mtar_t tar,
const char *  name,
unsigned  size 
)

Definition at line 332 of file microtar.c.

References mtar_header_t::mode, MTAR_TREG, mtar_write_header(), give::name, mtar_header_t::name, mtar_header_t::size, and mtar_header_t::type.

+ Here is the call graph for this function:

◆ mtar_write_header()

int mtar_write_header ( mtar_t tar,
const mtar_header_t h 
)

Definition at line 323 of file microtar.c.

References header_to_raw(), mtar_t::remaining_data, mtar_header_t::size, and twrite().

Referenced by add_to_tar(), mtar_write_dir_header(), and mtar_write_file_header().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ raw_to_header()

◆ round_up()

static unsigned round_up ( unsigned  n,
unsigned  incr 
)
static

Definition at line 44 of file microtar.c.

Referenced by mtar_next(), and mtar_write_data().

+ Here is the caller graph for this function:

◆ tread()

static int tread ( mtar_t tar,
void *  data,
unsigned  size 
)
static

Definition at line 63 of file microtar.c.

References navar-midane_time::data, mtar_t::pos, and mtar_t::read.

Referenced by mtar_read_data(), and mtar_read_header().

+ Here is the caller graph for this function:

◆ twrite()

static int twrite ( mtar_t tar,
const void *  data,
unsigned  size 
)
static

Definition at line 70 of file microtar.c.

References navar-midane_time::data, mtar_t::pos, and mtar_t::write.

Referenced by mtar_write_data(), mtar_write_header(), and write_null_bytes().

+ Here is the caller graph for this function:

◆ write_null_bytes()

static int write_null_bytes ( mtar_t tar,
int  n 
)
static

Definition at line 77 of file microtar.c.

References MTAR_ESUCCESS, and twrite().

Referenced by mtar_finalize(), and mtar_write_data().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: