From b36ef730c05561d70b6480700f7ae9262dbc1eb6 Mon Sep 17 00:00:00 2001 From: Guido Draheim <guidod@gmx.de> Date: Wed, 18 Dec 2002 16:34:12 +0000 Subject: [PATCH] This commit was generated by cvs2svn to compensate for changes in r29, which included commits to RCS files with non-trunk default branches. --- SDL/SDL_rwops_zzip.c | 62 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 SDL/SDL_rwops_zzip.c diff --git a/SDL/SDL_rwops_zzip.c b/SDL/SDL_rwops_zzip.c new file mode 100644 index 0000000..993bc1f --- /dev/null +++ b/SDL/SDL_rwops_zzip.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2001 Guido Draheim <guidod@gmx.de> + * Use freely under the restrictions of the ZLIB License + * + * (this example uses errno which might not be multithreaded everywhere) + */ + +#include <SDL_rwops_zzip.h> +#include <zzip/zzip.h> +#include <string.h> /* strchr */ + +/* MSVC can not take a casted variable as an lvalue ! */ +#define SDL_RWOPS_ZZIP_DATA(_context) \ + ((_context)->hidden.unknown.data1) +#define SDL_RWOPS_ZZIP_FILE(_context) (ZZIP_FILE*) \ + ((_context)->hidden.unknown.data1) + +static int _zzip_seek(SDL_RWops *context, int offset, int whence) +{ + return zzip_seek(SDL_RWOPS_ZZIP_FILE(context), offset, whence); +} + +static int _zzip_read(SDL_RWops *context, void *ptr, int size, int maxnum) +{ + return zzip_read(SDL_RWOPS_ZZIP_FILE(context), ptr, size*maxnum); +} + +static int _zzip_write(SDL_RWops *context, const void *ptr, int size, int num) +{ + return 0; /* ignored */ +} + +static int _zzip_close(SDL_RWops *context) +{ + if (! context) return 0; /* may be SDL_RWclose is called by atexit */ + + zzip_close (SDL_RWOPS_ZZIP_FILE(context)); + SDL_FreeRW (context); + return 0; +} + +SDL_RWops *SDL_RWFromZZIP(const char* file, const char* mode) +{ + register SDL_RWops* rwops; + register ZZIP_FILE* zzip_file; + + if (! strchr (mode, 'r')) + return SDL_RWFromFile(file, mode); + + zzip_file = zzip_fopen (file, mode); + if (! zzip_file) return 0; + + rwops = SDL_AllocRW (); + if (! rwops) { errno=ENOMEM; zzip_close (zzip_file); return 0; } + + SDL_RWOPS_ZZIP_DATA(rwops) = zzip_file; + rwops->read = _zzip_read; + rwops->write = _zzip_write; + rwops->seek = _zzip_seek; + rwops->close = _zzip_close; + return rwops; +} -- 2.40.0