diff options
-rw-r--r-- | externals/libmpq/debian/rules | 2 | ||||
-rw-r--r-- | externals/libmpq/doc/man3/Makefile.am | 1 | ||||
-rw-r--r-- | externals/libmpq/doc/man3/libmpq.3 | 3 | ||||
-rw-r--r-- | externals/libmpq/doc/man3/libmpq__strerror.3 | 45 | ||||
-rw-r--r-- | externals/libmpq/libmpq/common.c | 5 | ||||
-rw-r--r-- | externals/libmpq/libmpq/common.h | 3 | ||||
-rw-r--r-- | externals/libmpq/libmpq/mpq.c | 28 | ||||
-rw-r--r-- | externals/libmpq/libmpq/mpq.h | 3 |
8 files changed, 85 insertions, 5 deletions
diff --git a/externals/libmpq/debian/rules b/externals/libmpq/debian/rules index 5d11fe010db..1e101be5faf 100644 --- a/externals/libmpq/debian/rules +++ b/externals/libmpq/debian/rules @@ -41,7 +41,7 @@ endif ifneq "$(wildcard /usr/share/misc/config.guess)" "" cp -f /usr/share/misc/config.guess config.guess endif - ./configure $(CROSS) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,defs" + ./configure $(CROSS) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS) -ggdb" LDFLAGS="-Wl,-z,defs" build: build-stamp diff --git a/externals/libmpq/doc/man3/Makefile.am b/externals/libmpq/doc/man3/Makefile.am index 80bff4e7461..cad3d865dc1 100644 --- a/externals/libmpq/doc/man3/Makefile.am +++ b/externals/libmpq/doc/man3/Makefile.am @@ -27,4 +27,5 @@ man_MANS = \ libmpq__file_packed_size.3 \ libmpq__file_read.3 \ libmpq__file_unpacked_size.3 \ + libmpq__strerror.3 \ libmpq__version.3 diff --git a/externals/libmpq/doc/man3/libmpq.3 b/externals/libmpq/doc/man3/libmpq.3 index 349451f87b1..768dab0a712 100644 --- a/externals/libmpq/doc/man3/libmpq.3 +++ b/externals/libmpq/doc/man3/libmpq.3 @@ -29,6 +29,8 @@ libmpq \- cross-platform C library for manipulating mpq archives. .sp .BI "const char *libmpq__version();" .sp +.BI "const char *libmpq__strerror(int32_t returncode);" +.sp .BI "int32_t libmpq__archive_open(" .BI " mpq_archive_s **" "mpq_archive", .BI " const char *" "mpq_filename", @@ -172,6 +174,7 @@ libmpq \- cross-platform C library for manipulating mpq archives. The \fIlibmpq\fP library supports decrypting, decompressing, exploding and various manipulations of the MoPaQ archive files. It uses \fIzlib(3)\fP and \fIbzip2(1)\fP compression library. At this moment \fIlibmpq\fP is not able to create MoPaQ archives, this limitation will be removed in a future version. .SH SEE ALSO .BR libmpq__version (3), +.BR libmpq__strerror (3), .BR libmpq__archive_open (3), .BR libmpq__archive_close (3), .BR libmpq__archive_packed_size (3), diff --git a/externals/libmpq/doc/man3/libmpq__strerror.3 b/externals/libmpq/doc/man3/libmpq__strerror.3 new file mode 100644 index 00000000000..246f422eed0 --- /dev/null +++ b/externals/libmpq/doc/man3/libmpq__strerror.3 @@ -0,0 +1,45 @@ +.\" Copyright (c) 2010 Georg Lukas <georg@op-co.de> +.\" +.\" This is free documentation; you can redistribute it and/or +.\" modify it under the terms of the GNU General Public License as +.\" published by the Free Software Foundation; either version 2 of +.\" the License, or (at your option) any later version. +.\" +.\" The GNU General Public License's references to "object code" +.\" and "executables" are to be interpreted as the output of any +.\" document formatting or typesetting system, including +.\" intermediate and printed output. +.\" +.\" This manual is distributed in the hope that it will be useful, +.\" but WITHOUT ANY WARRANTY; without even the implied warranty of +.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +.\" GNU General Public License for more details. +.\" +.\" You should have received a copy of the GNU General Public +.\" License along with this manual; if not, write to the Free +.\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, +.\" USA. +.TH libmpq 3 2010-07-18 "The MoPaQ archive library" +.SH NAME +libmpq__strerror \- return string describing libmpq error number +.SH SYNOPSIS +.nf +.B +#include <mpq.h> +.sp +.BI "const char *libmpq__strerror(int32_t returncode);" +.fi +.SH DESCRIPTION +.PP +Call \fBlibmpq__strerror\fP() to get a string message for the return code of one of the other libmpq functions. +.SH RETURN VALUE +The function returns a string pointer to non-writable memory or NULL if \fBreturncode\fP is not a return code of a libmpq function. +.SH SEE ALSO +.BR libmpq (3), strerror (3) +.SH AUTHOR +Check documentation. +.TP +libmpq is (c) 2003-2008 +.B Maik Broemme <mbroemme@plusserver.de> +.PP +The above e-mail address can be used to send bug reports, feedbacks or library enhancements. diff --git a/externals/libmpq/libmpq/common.c b/externals/libmpq/libmpq/common.c index c17e4035dcc..879bd902b58 100644 --- a/externals/libmpq/libmpq/common.c +++ b/externals/libmpq/libmpq/common.c @@ -100,7 +100,7 @@ int32_t libmpq__decrypt_block(uint32_t *in_buf, uint32_t in_size, uint32_t seed) } /* function to detect decryption key. */ -int32_t libmpq__decrypt_key(uint8_t *in_buf, uint32_t in_size, uint32_t block_size) { +int32_t libmpq__decrypt_key(uint8_t *in_buf, uint32_t in_size, uint32_t block_size, uint32_t *key) { /* some common variables. */ uint32_t saveseed1; @@ -148,7 +148,8 @@ int32_t libmpq__decrypt_key(uint8_t *in_buf, uint32_t in_size, uint32_t block_si if ((ch - ch2) <= block_size) { /* file seed found, so return it. */ - return saveseed1; + *key = saveseed1; + return LIBMPQ_SUCCESS; } } diff --git a/externals/libmpq/libmpq/common.h b/externals/libmpq/libmpq/common.h index 12d6008debb..b9e03126434 100644 --- a/externals/libmpq/libmpq/common.h +++ b/externals/libmpq/libmpq/common.h @@ -45,7 +45,8 @@ int32_t libmpq__decrypt_block( int32_t libmpq__decrypt_key( uint8_t *in_buf, uint32_t in_size, - uint32_t block_size + uint32_t block_size, + uint32_t *key ); /* function to decompress or explode block from archive. */ diff --git a/externals/libmpq/libmpq/mpq.c b/externals/libmpq/libmpq/mpq.c index 83d5533109f..4e11e59d3f7 100644 --- a/externals/libmpq/libmpq/mpq.c +++ b/externals/libmpq/libmpq/mpq.c @@ -44,6 +44,32 @@ const char *libmpq__version(void) { return VERSION; } +static const char *__libmpq_error_strings[] = { + "success", + "open error on file", + "close error on file", + "lseek error on file", + "read error on file", + "write error on file", + "memory allocation error", + "format errror", + "init() wasn't called", + "buffer size is to small", + "file or block does not exist in archive", + "we don't know the decryption seed", + "error on unpacking file" + }; + +/* this function returns a string message for a return code. */ +const char *libmpq__strerror(int32_t returncode) { + /* check for array bounds */ + if (-returncode < 0 || -returncode > sizeof(__libmpq_error_strings)/sizeof(char*)) + return NULL; + + /* return appropriate string */ + return __libmpq_error_strings[-returncode]; +} + /* this function read a file and verify if it is a valid mpq archive, then it read and decrypt the hash table. */ int32_t libmpq__archive_open(mpq_archive_s **mpq_archive, const char *mpq_filename, libmpq__off_t archive_offset) { @@ -668,7 +694,7 @@ int32_t libmpq__block_open_offset(mpq_archive_s *mpq_archive, uint32_t file_numb if (mpq_archive->mpq_block[mpq_archive->mpq_map[file_number].block_table_indices].flags & LIBMPQ_FLAG_ENCRYPTED) { /* check if we don't know the file seed, try to find it. */ - if ((mpq_archive->mpq_file[file_number]->seed = libmpq__decrypt_key((uint8_t *)mpq_archive->mpq_file[file_number]->packed_offset, packed_size, mpq_archive->block_size)) < 0) { + if (libmpq__decrypt_key((uint8_t *)mpq_archive->mpq_file[file_number]->packed_offset, packed_size, mpq_archive->block_size, mpq_archive->mpq_file[file_number]->seed) < 0) { /* sorry without seed, we cannot extract file. */ result = LIBMPQ_ERROR_DECRYPT; diff --git a/externals/libmpq/libmpq/mpq.h b/externals/libmpq/libmpq/mpq.h index 3d53e06477c..abd4862c334 100644 --- a/externals/libmpq/libmpq/mpq.h +++ b/externals/libmpq/libmpq/mpq.h @@ -65,6 +65,9 @@ typedef int64_t libmpq__off_t; /* generic information about library. */ extern LIBMPQ_API const char *libmpq__version(void); +/* string error message for a libmpq return code. */ +extern LIBMPQ_API const char *libmpq__strerror(int32_t returncode); + /* generic mpq archive information. */ extern LIBMPQ_API int32_t libmpq__archive_open(mpq_archive_s **mpq_archive, const char *mpq_filename, libmpq__off_t archive_offset); extern LIBMPQ_API int32_t libmpq__archive_close(mpq_archive_s *mpq_archive); |