[9521] Let build map extractor at Mac OSX

Also restore build at Windows (Win32 not have unistd.h)

Win32 ad.exe binary updated but not expected any functional differences.

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
imbecile 2010-03-05 06:45:59 +03:00 committed by VladimirMangos
parent eaf5934c99
commit 24540e4b03
5 changed files with 28 additions and 37 deletions

View file

@ -22,7 +22,11 @@
#define _CRT_SECURE_NO_DEPRECATE
//#include <dirent.h>
#include <sys/stat.h>
//#include <unistd.h>
#ifndef WIN32
#include <unistd.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@ -30,6 +34,17 @@
#include "common.h"
#include <ctype.h>
unsigned int libmpq_lseek(mpq_archive* mpq_a, unsigned int pos)
{
#ifdef WIN32
return (unsigned int)_lseeki64(mpq_a->fd, pos, SEEK_SET);
#elif defined(__APPLE__)
return (unsigned int)lseek(mpq_a->fd, pos, SEEK_SET);
#else
return (unsigned int)lseek64(mpq_a->fd, pos, SEEK_SET);
#endif
}
/*
* This function decrypts a MPQ block.
*/
@ -396,11 +411,7 @@ int libmpq_read_hashtable(mpq_archive *mpq_a) {
/* Read the hash table into the buffer */
bytes = mpq_a->header->hashtablesize * sizeof(mpq_hash);
#ifdef WIN32
_lseeki64(mpq_a->fd, mpq_a->header->hashtablepos, SEEK_SET);
#else
lseek64(mpq_a->fd, mpq_a->header->hashtablepos, SEEK_SET);
#endif
libmpq_lseek(mpq_a, mpq_a->header->hashtablepos);
rb = _read(mpq_a->fd, mpq_a->hashtable, bytes);
if (rb != bytes) {
@ -455,11 +466,7 @@ int libmpq_read_blocktable(mpq_archive *mpq_a) {
bytes = mpq_a->header->blocktablesize * sizeof(mpq_block);
memset(mpq_a->blocktable, 0, mpq_a->header->blocktablesize * sizeof(mpq_block));
#ifdef WIN32
_lseeki64(mpq_a->fd, mpq_a->header->blocktablepos, SEEK_SET);
#else
lseek64(mpq_a->fd, mpq_a->header->blocktablepos, SEEK_SET);
#endif
libmpq_lseek(mpq_a, mpq_a->header->blocktablepos);
rb = _read(mpq_a->fd, mpq_a->blocktable, bytes);
if (rb != bytes) {
@ -519,12 +526,7 @@ int libmpq_file_read_block(mpq_archive *mpq_a, mpq_file *mpq_f, unsigned int blo
unsigned int nread;
if (mpq_f->mpq_b->filepos != mpq_a->filepos) {
#ifdef WIN32
_lseeki64(mpq_a->fd, mpq_f->mpq_b->filepos, SEEK_SET);
#else
lseek64(mpq_a->fd, mpq_f->mpq_b->filepos, SEEK_SET);
#endif
libmpq_lseek(mpq_a, mpq_f->mpq_b->filepos);
}
/* Read block positions from begin of file. */
@ -569,12 +571,7 @@ int libmpq_file_read_block(mpq_archive *mpq_a, mpq_file *mpq_f, unsigned int blo
if (mpq_f->blockpos[0] != nread) {
/* Try once again to detect file seed and decrypt the blocks */
#ifdef WIN32
_lseeki64(mpq_a->fd, mpq_f->mpq_b->filepos, SEEK_SET);
#else
lseek64(mpq_a->fd, mpq_f->mpq_b->filepos, SEEK_SET);
#endif
libmpq_lseek(mpq_a, mpq_f->mpq_b->filepos);
nread = _read(mpq_a->fd, mpq_f->blockpos, (mpq_f->nblocks + 1) * sizeof(int));
mpq_f->seed = libmpq_detect_fileseed(mpq_a, mpq_f->blockpos, nread);
@ -611,13 +608,7 @@ int libmpq_file_read_block(mpq_archive *mpq_a, mpq_file *mpq_f, unsigned int blo
/* Set file pointer, if necessary. */
if (mpq_a->filepos != readpos) {
#ifdef WIN32
mpq_a->filepos = _lseeki64(mpq_a->fd, readpos, SEEK_SET);
#else
mpq_a->filepos = lseek64(mpq_a->fd, readpos, SEEK_SET);
#endif
mpq_a->filepos = libmpq_lseek(mpq_a, readpos);
}
/* 15018F87 - Read all requested blocks. */