$NetBSD: patch-ab,v 1.1.1.1 2004/10/23 17:31:31 bencollver Exp $

--- libmpq/common.c.orig	Wed Feb 11 16:42:54 2004
+++ libmpq/common.c
@@ -29,6 +29,10 @@
 #include "libmpq/mpq.h"
 #include "libmpq/common.h"
 
+#ifndef strnlen
+#define strnlen(x,y) strlen(x)
+#endif
+
 /*
  *  This function decrypts a MPQ block.
  */
@@ -380,6 +384,8 @@ int libmpq_init_buffer(mpq_archive *mpq_
 int libmpq_read_hashtable(mpq_archive *mpq_a) {
 	unsigned int bytes = 0;
 	int rb = 0;
+	mpq_hash *mpq_h_end;
+	mpq_hash *mpq_h;
 
 	/*
 	 *  Allocate memory. Note that the block table should be as large as the
@@ -400,8 +406,8 @@ int libmpq_read_hashtable(mpq_archive *m
 	}
 
 	/* Decrypt hash table and check if it is correctly decrypted */
-	mpq_hash *mpq_h_end = mpq_a->hashtable + mpq_a->header->hashtablesize;
-	mpq_hash *mpq_h     = NULL;
+	mpq_h_end = mpq_a->hashtable + mpq_a->header->hashtablesize;
+	mpq_h     = NULL;
 
 	libmpq_decrypt_hashtable(mpq_a, "(hash table)");
 
@@ -431,6 +437,9 @@ int libmpq_read_hashtable(mpq_archive *m
 int libmpq_read_blocktable(mpq_archive *mpq_a) {
 	unsigned int bytes = 0;
 	int rb = 0;
+	mpq_block *mpq_b_end;
+	mpq_block *mpq_b;
+	unsigned int archivesize;
 
 	/*
 	 *  Allocate memory. Note that the block table should be as large as the
@@ -457,9 +466,9 @@ int libmpq_read_blocktable(mpq_archive *
 	 *  e.g. cracked Diablo version. We have to check if block table is
 	 *  already decrypted
 	 */
-	mpq_block *mpq_b_end     = mpq_a->blocktable + mpq_a->maxblockindex + 1;
-	mpq_block *mpq_b         = NULL;
-	unsigned int archivesize = mpq_a->header->archivesize + mpq_a->mpqpos;
+	mpq_b_end     = mpq_a->blocktable + mpq_a->maxblockindex + 1;
+	mpq_b         = NULL;
+	archivesize = mpq_a->header->archivesize + mpq_a->mpqpos;
 
 	if (mpq_a->header->offset != mpq_a->blocktable->filepos) {
 		libmpq_decrypt_blocktable(mpq_a, "(block table)");
@@ -484,6 +493,9 @@ int libmpq_file_read_block(mpq_archive *
 	unsigned int bytesread = 0;			/* Total number of bytes read */
 	unsigned int nblocks;				/* Number of blocks to load */
 	unsigned int i;
+	unsigned int blockstart;
+	unsigned int blocksize;
+	unsigned int index;
 
 	/* Test parameters. Block position and block size must be block-aligned, block size nonzero */
 	if ((blockpos & (mpq_a->blocksize - 1)) || blockbytes == 0) {
@@ -589,9 +601,9 @@ int libmpq_file_read_block(mpq_archive *
 	mpq_a->filepos = readpos + bytesread;
 
 	/* Block processing part. */
-	unsigned int blockstart = 0;			/* Index of block start in work buffer. */
-	unsigned int blocksize  = min(blockbytes, mpq_a->blocksize);
-	unsigned int index      = blocknum;		/* Current block index. */
+	blockstart = 0;			/* Index of block start in work buffer. */
+	blocksize  = min(blockbytes, mpq_a->blocksize);
+	index      = blocknum;		/* Current block index. */
 	bytesread = 0;					/* Clear read byte counter */
 
 	/* Walk through all blocks. */
