]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - fs.c
- Updated Zlib definitions to version 1.2.3. The only difference is that
[xonotic/darkplaces.git] / fs.c
diff --git a/fs.c b/fs.c
index 9fd764153457d1f5a049ec1a69626c8100e6dd3f..1ff670a0586adcaea7e1265be3242c6afeba30dd 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -2,7 +2,6 @@
        DarkPlaces file system
 
        Copyright (C) 2003-2005 Mathieu Olivier
-       Copyright (C) 1999,2000  contributors of the QuakeForge project
 
        This program is free software; you can redistribute it and/or
        modify it under the terms of the GNU General Public License
 # define O_BINARY 0
 #endif
 
+// In case the system doesn't support the O_NONBLOCK flag
+#ifndef O_NONBLOCK
+# define O_NONBLOCK 0
+#endif
+
 
 /*
 
@@ -90,7 +94,11 @@ CONSTANTS
 #define MAX_WBITS              15
 #define Z_OK                   0
 #define Z_STREAM_END   1
-#define ZLIB_VERSION   "1.1.4"
+#define ZLIB_VERSION   "1.2.3"
+
+// Uncomment the following line if the zlib DLL you have still uses
+// the 1.1.x series calling convention on Win32 (WINAPI)
+//#define ZLIB_USES_WINAPI
 
 
 /*
@@ -154,7 +162,7 @@ struct qfile_s
        int                             ungetc;                                 // single stored character from ungetc, cleared to EOF when read
 
        // Contents buffer
-       size_t                  buff_ind, buff_len;             // buffer current index and length
+       fs_offset_t             buff_ind, buff_len;             // buffer current index and length
        qbyte                   buff [FILE_BUFF_SIZE];
 
        // For zipped files
@@ -281,7 +289,7 @@ PRIVATE FUNCTIONS - PK3 HANDLING
 */
 
 // Functions exported from zlib
-#ifdef WIN32
+#if defined(WIN32) && defined(ZLIB_USES_WINAPI)
 # define ZEXPORT WINAPI
 #else
 # define ZEXPORT
@@ -332,8 +340,15 @@ qboolean PK3_OpenLibrary (void)
 {
        const char* dllnames [] =
        {
-#ifdef WIN32
+#if defined(WIN64)
+               "zlib64.dll",
+#elif defined(WIN32)
+# ifdef ZLIB_USES_WINAPI
+               "zlibwapi.dll",
                "zlib.dll",
+# else
+               "zlib1.dll",
+# endif
 #elif defined(MACOSX)
                "libz.dylib",
 #else
@@ -939,7 +954,7 @@ void FS_Init (void)
        if (strstr(com_argv[0], ".app/"))
        {
                char *split;
-               char temp[4096];
+
                split = strstr(com_argv[0], ".app/");
                while (split > com_argv[0] && *split != '/')
                        split--;
@@ -1113,10 +1128,8 @@ static qfile_t* FS_SysOpen (const char* filepath, const char* mode, qboolean non
                }
        }
 
-#ifndef WIN32
        if (nonblocking)
                opt |= O_NONBLOCK;
-#endif
 
        file = Mem_Alloc (fs_mempool, sizeof (*file));
        memset (file, 0, sizeof (*file));
@@ -1489,7 +1502,7 @@ fs_offset_t FS_Write (qfile_t* file, const void* data, size_t datasize)
        FS_Purge (file);
 
        // Write the buffer and update the position
-       result = write (file->handle, data, datasize);
+       result = write (file->handle, data, (fs_offset_t)datasize);
        file->position = lseek (file->handle, 0, SEEK_CUR);
        if (file->real_length < file->position)
                file->real_length = file->position;
@@ -1545,7 +1558,7 @@ fs_offset_t FS_Read (qfile_t* file, void* buffer, size_t buffersize)
        // If the file isn't compressed
        if (! (file->flags & QFILE_FLAG_DEFLATED))
        {
-               int nb;
+               fs_offset_t nb;
 
                // We must take care to not read after the end of the file
                count = file->real_length - file->position;
@@ -1578,7 +1591,7 @@ fs_offset_t FS_Read (qfile_t* file, void* buffer, size_t buffersize)
                                file->position += nb;
 
                                // Copy the requested data in "buffer" (as much as we can)
-                               count = (buffersize > file->buff_len) ? file->buff_len : buffersize;
+                               count = (fs_offset_t)buffersize > file->buff_len ? file->buff_len : (fs_offset_t)buffersize;
                                memcpy (&((qbyte*)buffer)[done], file->buff, count);
                                file->buff_ind = count;
                                done += count;
@@ -1604,11 +1617,11 @@ fs_offset_t FS_Read (qfile_t* file, void* buffer, size_t buffersize)
                        if (file->position == file->real_length)
                                return done;
 
-                       count = ztk->comp_length - ztk->in_position;
+                       count = (fs_offset_t)(ztk->comp_length - ztk->in_position);
                        if (count > (fs_offset_t)sizeof (ztk->input))
                                count = (fs_offset_t)sizeof (ztk->input);
-                       lseek (file->handle, file->offset + ztk->in_position, SEEK_SET);
-                       if (read (file->handle, ztk->input, count) != (fs_offset_t)count)
+                       lseek (file->handle, file->offset + (fs_offset_t)ztk->in_position, SEEK_SET);
+                       if (read (file->handle, ztk->input, count) != count)
                        {
                                Con_Printf ("FS_Read: unexpected end of file");
                                break;
@@ -1638,11 +1651,11 @@ fs_offset_t FS_Read (qfile_t* file, void* buffer, size_t buffersize)
                        }
                        ztk->in_ind = ztk->in_len - ztk->zstream.avail_in;
 
-                       file->buff_len = sizeof (file->buff) - ztk->zstream.avail_out;
+                       file->buff_len = (fs_offset_t)sizeof (file->buff) - ztk->zstream.avail_out;
                        file->position += file->buff_len;
 
                        // Copy the requested data in "buffer" (as much as we can)
-                       count = (buffersize > file->buff_len) ? file->buff_len : buffersize;
+                       count = (fs_offset_t)buffersize > file->buff_len ? file->buff_len : (fs_offset_t)buffersize;
                        memcpy (&((qbyte*)buffer)[done], file->buff, count);
                        file->buff_ind = count;
                }
@@ -1661,7 +1674,7 @@ fs_offset_t FS_Read (qfile_t* file, void* buffer, size_t buffersize)
                        ztk->in_ind = ztk->in_len - ztk->zstream.avail_in;
 
                        // How much data did it inflate?
-                       count = buffersize - ztk->zstream.avail_out;
+                       count = (fs_offset_t)(buffersize - ztk->zstream.avail_out);
                        file->position += count;
 
                        // Purge cached data
@@ -1792,14 +1805,14 @@ int FS_Seek (qfile_t* file, fs_offset_t offset, int whence)
        switch (whence)
        {
                case SEEK_CUR:
-                       offset += (long)(file->position - file->buff_len + file->buff_ind);
+                       offset += file->position - file->buff_len + file->buff_ind;
                        break;
 
                case SEEK_SET:
                        break;
 
                case SEEK_END:
-                       offset += (long)file->real_length;
+                       offset += file->real_length;
                        break;
 
                default:
@@ -1809,8 +1822,7 @@ int FS_Seek (qfile_t* file, fs_offset_t offset, int whence)
                return -1;
 
        // If we have the data in our read buffer, we don't need to actually seek
-       if (file->position - (fs_offset_t)file->buff_len <= offset
-               && offset <= file->position)
+       if (file->position - file->buff_len <= offset && offset <= file->position)
        {
                file->buff_ind = offset + file->buff_len - file->position;
                return 0;