minizip-ng/ioapi.c

91 lines
2.4 KiB
C
Raw Normal View History

2017-06-05 13:36:52 +08:00
/* ioapi.c -- IO base function header for compress/uncompress .zip
part of the MiniZip project
2012-02-25 23:28:28 -07:00
2017-09-16 13:25:02 +08:00
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Modifications for Zip64 support
Copyright (C) 2009-2010 Mathias Svensson
http://result42.com
2017-09-16 13:25:02 +08:00
Copyright (C) 1998-2010 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
2012-02-25 23:28:28 -07:00
*/
2012-10-21 15:20:13 -07:00
#include <stdlib.h>
#include <string.h>
2012-10-21 15:20:13 -07:00
#include "ioapi.h"
2017-10-01 21:43:24 -07:00
int32_t mz_stream_open(voidpf stream, const char *filename, int mode)
2012-02-25 23:28:28 -07:00
{
2017-10-01 21:43:24 -07:00
mz_stream *strm = (mz_stream *)stream;
2017-09-29 21:02:09 -07:00
if (strm == NULL || strm->open == NULL)
2017-10-01 21:43:24 -07:00
return MZ_STREAM_ERR;
2017-09-29 21:02:09 -07:00
return strm->open(strm, filename, mode);
2012-02-25 23:28:28 -07:00
}
2017-10-01 21:43:24 -07:00
int32_t mz_stream_is_open(voidpf stream)
2012-02-25 23:28:28 -07:00
{
2017-10-01 21:43:24 -07:00
mz_stream *strm = (mz_stream *)stream;
2017-09-29 21:02:09 -07:00
if (strm == NULL || strm->is_open == NULL)
2017-10-01 21:43:24 -07:00
return MZ_STREAM_ERR;
2017-09-29 21:02:09 -07:00
return strm->is_open(strm);
2012-02-25 23:28:28 -07:00
}
2017-10-01 21:43:24 -07:00
int32_t mz_stream_read(voidpf stream, void* buf, uint32_t size)
2012-02-25 23:28:28 -07:00
{
2017-10-01 21:43:24 -07:00
mz_stream *strm = (mz_stream *)stream;
2017-09-29 21:02:09 -07:00
if (strm == NULL || strm->read == NULL)
2017-10-01 21:43:24 -07:00
return MZ_STREAM_ERR;
2017-09-29 21:02:09 -07:00
return strm->read(strm, buf, size);
2012-02-25 23:28:28 -07:00
}
2017-10-01 21:43:24 -07:00
int32_t mz_stream_write(voidpf stream, const void *buf, uint32_t size)
2012-02-25 23:28:28 -07:00
{
2017-10-01 21:43:24 -07:00
mz_stream *strm = (mz_stream *)stream;
2017-09-29 21:02:09 -07:00
if (strm == NULL || strm->write == NULL)
2017-10-01 21:43:24 -07:00
return MZ_STREAM_ERR;
2017-09-29 21:02:09 -07:00
return strm->write(strm, buf, size);
2012-02-25 23:28:28 -07:00
}
2017-10-01 21:43:24 -07:00
int64_t mz_stream_tell(voidpf stream)
2012-02-25 23:28:28 -07:00
{
2017-10-01 21:43:24 -07:00
mz_stream *strm = (mz_stream *)stream;
2017-09-29 21:02:09 -07:00
if (strm == NULL || strm->tell == NULL)
2017-10-01 21:43:24 -07:00
return MZ_STREAM_ERR;
2017-09-29 21:02:09 -07:00
return strm->tell(strm);
2012-02-25 23:28:28 -07:00
}
2017-10-01 21:43:24 -07:00
int32_t mz_stream_seek(voidpf stream, uint64_t offset, int origin)
2012-02-25 23:28:28 -07:00
{
2017-10-01 21:43:24 -07:00
mz_stream *strm = (mz_stream *)stream;
2017-09-29 21:02:09 -07:00
if (strm == NULL || strm->seek == NULL)
2017-10-01 21:43:24 -07:00
return MZ_STREAM_ERR;
2017-09-29 21:02:09 -07:00
return strm->seek(strm, offset, origin);
}
2012-02-25 23:28:28 -07:00
2017-10-01 21:43:24 -07:00
int32_t mz_stream_close(voidpf stream)
2012-02-25 23:28:28 -07:00
{
2017-10-01 21:43:24 -07:00
mz_stream *strm = (mz_stream *)stream;
2017-09-29 21:02:09 -07:00
if (strm == NULL || strm->close == NULL)
2017-10-01 21:43:24 -07:00
return MZ_STREAM_ERR;
2017-09-29 21:02:09 -07:00
return strm->close(strm);
2012-02-25 23:28:28 -07:00
}
2017-10-01 21:43:24 -07:00
int32_t mz_stream_error(voidpf stream)
2012-02-25 23:28:28 -07:00
{
2017-10-01 21:43:24 -07:00
mz_stream *strm = (mz_stream *)stream;
2017-09-29 21:02:09 -07:00
if (strm == NULL || strm->error == NULL)
2017-10-01 21:43:24 -07:00
return MZ_STREAM_ERR;
2017-09-29 21:02:09 -07:00
return strm->error(strm);
2012-02-25 23:28:28 -07:00
}
2017-10-01 21:43:24 -07:00
int32_t mz_stream_set_base(voidpf stream, voidpf base)
2012-02-25 23:28:28 -07:00
{
2017-10-01 21:43:24 -07:00
mz_stream *strm = (mz_stream *)stream;
strm->base = (mz_stream *)base;
return MZ_STREAM_OK;
2012-02-25 23:28:28 -07:00
}