forked from Mirrors/openclonk
Rename our custom gz* functions to avoid conflicts with zlib.dll
This fixes the build with native mingw for me.
parent
f4bc45c4a3
commit
a1370c2954
|
@ -545,6 +545,7 @@ set(OC_CLONK_SOURCES
|
|||
src/script/C4Value.h
|
||||
src/script/C4ValueMap.cpp
|
||||
src/script/C4ValueMap.h
|
||||
src/zlib/gzio.h
|
||||
src/zlib/gzio.c
|
||||
src/zlib/zutil.h
|
||||
|
||||
|
@ -961,6 +962,7 @@ add_executable(c4script
|
|||
src/c4group/C4GroupSet.cpp
|
||||
src/c4group/C4ComponentHost.cpp
|
||||
src/c4group/C4LangStringTable.cpp
|
||||
src/zlib/gzio.c
|
||||
src/C4Include.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <SHA1.h>
|
||||
|
||||
#include <zlib.h>
|
||||
#include <zlib/gzio.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -79,7 +80,7 @@ bool CStdFile::Create(const char *szFilename, bool fCompressed, bool fExecutable
|
|||
int flags = O_CREAT|O_WRONLY|O_TRUNC;
|
||||
int fd = open(Name, flags, mode);
|
||||
#endif
|
||||
if (!(hgzFile = gzdopen(fd,"wb1"))) return false;
|
||||
if (!(hgzFile = c4_gzdopen(fd,"wb1"))) return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -122,7 +123,7 @@ bool CStdFile::Open(const char *szFilename, bool fCompressed)
|
|||
int flags = O_RDONLY;
|
||||
int fd = open(Name, flags, mode);
|
||||
#endif
|
||||
if (!(hgzFile = gzdopen(fd,"rb"))) return false;
|
||||
if (!(hgzFile = c4_gzdopen(fd,"rb"))) return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -167,7 +168,7 @@ bool CStdFile::Close(StdBuf **ppMemory)
|
|||
// Save buffer if in write mode
|
||||
if (ModeWrite && BufferLoad) if (!SaveBuffer()) rval=false;
|
||||
// Close file(s)
|
||||
if (hgzFile) if (gzclose(hgzFile)!=Z_OK) rval=false;
|
||||
if (hgzFile) if (c4_gzclose(hgzFile)!=Z_OK) rval=false;
|
||||
if (hFile) if (fclose(hFile)!=0) rval=false;
|
||||
if (pMemory)
|
||||
{
|
||||
|
@ -224,7 +225,7 @@ int CStdFile::LoadBuffer()
|
|||
{
|
||||
thread_check.Check();
|
||||
if (hFile) BufferLoad = fread(Buffer,1,CStdFileBufSize,hFile);
|
||||
if (hgzFile) BufferLoad = gzread(hgzFile, Buffer,CStdFileBufSize);
|
||||
if (hgzFile) BufferLoad = c4_gzread(hgzFile, Buffer,CStdFileBufSize);
|
||||
BufferPtr=0;
|
||||
return BufferLoad;
|
||||
}
|
||||
|
@ -234,7 +235,7 @@ bool CStdFile::SaveBuffer()
|
|||
thread_check.Check();
|
||||
int saved = 0;
|
||||
if (hFile) saved=fwrite(Buffer,1,BufferLoad,hFile);
|
||||
if (hgzFile) saved=gzwrite(hgzFile,Buffer,BufferLoad);
|
||||
if (hgzFile) saved=c4_gzwrite(hgzFile,Buffer,BufferLoad);
|
||||
if (pMemory) { pMemory->Append(Buffer, BufferLoad); saved = BufferLoad; }
|
||||
if (saved!=BufferLoad) return false;
|
||||
BufferLoad=0;
|
||||
|
@ -288,7 +289,7 @@ bool CStdFile::Rewind()
|
|||
if (ModeWrite) return false;
|
||||
ClearBuffer();
|
||||
if (hFile) rewind(hFile);
|
||||
if (hgzFile) gzrewind(hgzFile);
|
||||
if (hgzFile) c4_gzrewind(hgzFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -329,15 +330,15 @@ int UncompressedFileSize(const char *szFilename)
|
|||
int fd = open(szFilename, flags, mode);
|
||||
#endif
|
||||
gzFile hFile;
|
||||
if (!(hFile = gzdopen(fd,"rb"))) return 0;
|
||||
if (!(hFile = c4_gzdopen(fd,"rb"))) return 0;
|
||||
do
|
||||
{
|
||||
rd = gzread(hFile,&buf,sizeof(buf));
|
||||
rd = c4_gzread(hFile,&buf,sizeof(buf));
|
||||
if (rd < 0) break;
|
||||
rval += rd;
|
||||
}
|
||||
while (rd == sizeof buf);
|
||||
gzclose(hFile);
|
||||
c4_gzclose(hFile);
|
||||
return rval;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,19 @@ namespace
|
|||
}
|
||||
};
|
||||
|
||||
template<typename Iter, typename Pred>
|
||||
void BubbleSort(Iter begin, Iter end, Pred pred)
|
||||
{
|
||||
for(Iter iter = begin; iter != end; ++iter)
|
||||
{
|
||||
for(Iter iter2 = begin+1; iter2 != end; ++iter2)
|
||||
{
|
||||
if(pred(*iter2, *iter)) // iter2 < iter
|
||||
std::swap(*iter, *iter2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to sort faces for FaceOrdering
|
||||
struct StdMeshInstanceFaceOrderingCmpPred
|
||||
{
|
||||
|
@ -1138,7 +1151,10 @@ void StdMeshInstance::ReorderFaces(StdMeshMatrix* global_trans)
|
|||
if(inst.CurrentFaceOrdering != StdSubMeshInstance::FO_Fixed)
|
||||
{
|
||||
StdMeshInstanceFaceOrderingCmpPred pred(inst, global_trans ? *global_trans : StdMeshMatrix::Identity());
|
||||
std::sort(inst.Faces.begin(), inst.Faces.end(), pred);
|
||||
|
||||
//std::sort(inst.Faces.begin(), inst.Faces.end(), pred);
|
||||
|
||||
BubbleSort(inst.Faces.begin(), inst.Faces.end(), pred);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -221,7 +221,7 @@ local gzFile gz_open (path, mode, fd)
|
|||
/* ===========================================================================
|
||||
Opens a gzip (.gz) file for reading or writing.
|
||||
*/
|
||||
gzFile ZEXPORT gzopen (path, mode)
|
||||
gzFile ZEXPORT c4_gzopen (path, mode)
|
||||
const char *path;
|
||||
const char *mode;
|
||||
{
|
||||
|
@ -232,7 +232,7 @@ gzFile ZEXPORT gzopen (path, mode)
|
|||
Associate a gzFile with the file descriptor fd. fd is not dup'ed here
|
||||
to mimic the behavio(u)r of fdopen.
|
||||
*/
|
||||
gzFile ZEXPORT gzdopen (fd, mode)
|
||||
gzFile ZEXPORT c4_gzdopen (fd, mode)
|
||||
int fd;
|
||||
const char *mode;
|
||||
{
|
||||
|
@ -247,7 +247,7 @@ gzFile ZEXPORT gzdopen (fd, mode)
|
|||
/* ===========================================================================
|
||||
* Update the compression level and strategy
|
||||
*/
|
||||
int ZEXPORT gzsetparams (file, level, strategy)
|
||||
int ZEXPORT c4_gzsetparams (file, level, strategy)
|
||||
gzFile file;
|
||||
int level;
|
||||
int strategy;
|
||||
|
@ -409,7 +409,7 @@ local int destroy (s)
|
|||
Reads the given number of uncompressed bytes from the compressed file.
|
||||
gzread returns the number of bytes actually read (0 for end of file).
|
||||
*/
|
||||
int ZEXPORT gzread (file, buf, len)
|
||||
int ZEXPORT c4_gzread (file, buf, len)
|
||||
gzFile file;
|
||||
voidp buf;
|
||||
unsigned len;
|
||||
|
@ -518,7 +518,7 @@ int ZEXPORT gzread (file, buf, len)
|
|||
Reads one byte from the compressed file. gzgetc returns this byte
|
||||
or -1 in case of end of file or error.
|
||||
*/
|
||||
int ZEXPORT gzgetc(file)
|
||||
int ZEXPORT c4_gzgetc(file)
|
||||
gzFile file;
|
||||
{
|
||||
unsigned char c;
|
||||
|
@ -530,7 +530,7 @@ int ZEXPORT gzgetc(file)
|
|||
/* ===========================================================================
|
||||
Push one byte back onto the stream.
|
||||
*/
|
||||
int ZEXPORT gzungetc(c, file)
|
||||
int ZEXPORT c4_gzungetc(c, file)
|
||||
int c;
|
||||
gzFile file;
|
||||
{
|
||||
|
@ -555,7 +555,7 @@ int ZEXPORT gzungetc(c, file)
|
|||
|
||||
The current implementation is not optimized at all.
|
||||
*/
|
||||
char * ZEXPORT gzgets(file, buf, len)
|
||||
char * ZEXPORT c4_gzgets(file, buf, len)
|
||||
gzFile file;
|
||||
char *buf;
|
||||
int len;
|
||||
|
@ -574,7 +574,7 @@ char * ZEXPORT gzgets(file, buf, len)
|
|||
Writes the given number of uncompressed bytes into the compressed file.
|
||||
gzwrite returns the number of bytes actually written (0 in case of error).
|
||||
*/
|
||||
int ZEXPORT gzwrite (file, buf, len)
|
||||
int ZEXPORT c4_gzwrite (file, buf, len)
|
||||
gzFile file;
|
||||
voidpc buf;
|
||||
unsigned len;
|
||||
|
@ -618,7 +618,7 @@ int ZEXPORT gzwrite (file, buf, len)
|
|||
#ifdef STDC
|
||||
#include <stdarg.h>
|
||||
|
||||
int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...)
|
||||
int ZEXPORTVA c4_gzprintf (gzFile file, const char *format, /* args */ ...)
|
||||
{
|
||||
char buf[Z_PRINTF_BUFSIZE];
|
||||
va_list va;
|
||||
|
@ -652,7 +652,7 @@ int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...)
|
|||
}
|
||||
#else /* not ANSI C */
|
||||
|
||||
int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
||||
int ZEXPORTVA c4_gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
||||
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
|
||||
gzFile file;
|
||||
const char *format;
|
||||
|
@ -693,7 +693,7 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
|||
Writes c, converted to an unsigned char, into the compressed file.
|
||||
gzputc returns the value that was written, or -1 in case of error.
|
||||
*/
|
||||
int ZEXPORT gzputc(file, c)
|
||||
int ZEXPORT c4_gzputc(file, c)
|
||||
gzFile file;
|
||||
int c;
|
||||
{
|
||||
|
@ -708,7 +708,7 @@ int ZEXPORT gzputc(file, c)
|
|||
the terminating null character.
|
||||
gzputs returns the number of characters written, or -1 in case of error.
|
||||
*/
|
||||
int ZEXPORT gzputs(file, s)
|
||||
int ZEXPORT c4_gzputs(file, s)
|
||||
gzFile file;
|
||||
const char *s;
|
||||
{
|
||||
|
@ -761,7 +761,7 @@ local int do_flush (file, flush)
|
|||
return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
|
||||
}
|
||||
|
||||
int ZEXPORT gzflush (file, flush)
|
||||
int ZEXPORT c4_gzflush (file, flush)
|
||||
gzFile file;
|
||||
int flush;
|
||||
{
|
||||
|
@ -782,7 +782,7 @@ int ZEXPORT gzflush (file, flush)
|
|||
SEEK_END is not implemented, returns error.
|
||||
In this version of the library, gzseek can be extremely slow.
|
||||
*/
|
||||
z_off_t ZEXPORT gzseek (file, offset, whence)
|
||||
z_off_t ZEXPORT c4_gzseek (file, offset, whence)
|
||||
gzFile file;
|
||||
z_off_t offset;
|
||||
int whence;
|
||||
|
@ -872,7 +872,7 @@ z_off_t ZEXPORT gzseek (file, offset, whence)
|
|||
/* ===========================================================================
|
||||
Rewinds input file.
|
||||
*/
|
||||
int ZEXPORT gzrewind (file)
|
||||
int ZEXPORT c4_gzrewind (file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
|
@ -896,7 +896,7 @@ int ZEXPORT gzrewind (file)
|
|||
given compressed file. This position represents a number of bytes in the
|
||||
uncompressed data stream.
|
||||
*/
|
||||
z_off_t ZEXPORT gztell (file)
|
||||
z_off_t ZEXPORT c4_gztell (file)
|
||||
gzFile file;
|
||||
{
|
||||
return gzseek(file, 0L, SEEK_CUR);
|
||||
|
@ -906,7 +906,7 @@ z_off_t ZEXPORT gztell (file)
|
|||
Returns 1 when EOF has previously been detected reading the given
|
||||
input stream, otherwise zero.
|
||||
*/
|
||||
int ZEXPORT gzeof (file)
|
||||
int ZEXPORT c4_gzeof (file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
|
@ -923,7 +923,7 @@ int ZEXPORT gzeof (file)
|
|||
/* ===========================================================================
|
||||
Returns 1 if reading and doing so transparently, otherwise zero.
|
||||
*/
|
||||
int ZEXPORT gzdirect (file)
|
||||
int ZEXPORT c4_gzdirect (file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
|
@ -968,7 +968,7 @@ local uLong getLong (s)
|
|||
Flushes all pending output if necessary, closes the compressed file
|
||||
and deallocates all the (de)compression state.
|
||||
*/
|
||||
int ZEXPORT gzclose (file)
|
||||
int ZEXPORT c4_gzclose (file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
|
@ -1003,7 +1003,7 @@ int ZEXPORT gzclose (file)
|
|||
to get the exact error code.
|
||||
*/
|
||||
#if 0
|
||||
const char * ZEXPORT gzerror (file, errnum)
|
||||
const char * ZEXPORT c4_gzerror (file, errnum)
|
||||
gzFile file;
|
||||
int *errnum;
|
||||
{
|
||||
|
@ -1034,7 +1034,7 @@ const char * ZEXPORT gzerror (file, errnum)
|
|||
/* ===========================================================================
|
||||
Clear the error and end-of-file flags, and do the same for the real file.
|
||||
*/
|
||||
void ZEXPORT gzclearerr (file)
|
||||
void ZEXPORT c4_gzclearerr (file)
|
||||
gzFile file;
|
||||
{
|
||||
gz_stream *s = (gz_stream*)file;
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (C) 2012 Armin Burgmeier
|
||||
*/
|
||||
|
||||
#ifndef C4_GZIO_H
|
||||
#define C4_GZIO_H
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
gzFile ZEXPORT c4_gzopen (const char* path, const char* mode);
|
||||
gzFile ZEXPORT c4_gzdopen (int fd, const char* mode);
|
||||
int ZEXPORT c4_gzsetparams (gzFile file, int level, int strategy);
|
||||
int ZEXPORT c4_gzread (gzFile file, voidp buf, unsigned len);
|
||||
int ZEXPORT c4_gzgetc(gzFile file);
|
||||
int ZEXPORT c4_gzungetc(int c, gzFile file);
|
||||
char * ZEXPORT c4_gzgets(gzFile file, char* buf, int len);
|
||||
int ZEXPORT c4_gzwrite (gzFile file, voidpc buf, unsigned len);
|
||||
int ZEXPORTVA c4_gzprintf (gzFile file, const char *format, /* args */ ...);
|
||||
int ZEXPORT c4_gzputc(gzFile file, int c);
|
||||
int ZEXPORT c4_gzputs(gzFile file, const char* s);
|
||||
int ZEXPORT c4_gzflush (gzFile file, int flush);
|
||||
z_off_t ZEXPORT c4_gzseek (gzFile file, z_off_t offset, int whence);
|
||||
int ZEXPORT c4_gzrewind (gzFile file);
|
||||
z_off_t ZEXPORT c4_gztell (gzFile file);
|
||||
int ZEXPORT c4_gzeof (gzFile file);
|
||||
int ZEXPORT c4_gzdirect (gzFile file);
|
||||
int ZEXPORT c4_gzclose (gzFile file);
|
||||
void ZEXPORT c4_gzclearerr (gzFile file);
|
||||
|
||||
}
|
||||
|
||||
#endif // C4_GZIO_H
|
Loading…
Reference in New Issue