]> 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 b34116971f36d159af3da2d1fcdbcd629df0520f..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));
@@ -1483,7 +1496,7 @@ fs_offset_t FS_Write (qfile_t* file, const void* data, size_t datasize)
 
        // If necessary, seek to the exact file position we're supposed to be
        if (file->buff_ind != file->buff_len)
-               lseek (file->handle, (fs_offset_t)(file->buff_ind - file->buff_len), SEEK_CUR);
+               lseek (file->handle, file->buff_ind - file->buff_len, SEEK_CUR);
 
        // Purge cached data
        FS_Purge (file);
@@ -1529,7 +1542,7 @@ fs_offset_t FS_Read (qfile_t* file, void* buffer, size_t buffersize)
        // First, we copy as many bytes as we can from "buff"
        if (file->buff_ind < file->buff_len)
        {
-               count = (fs_offset_t)(file->buff_len - file->buff_ind);
+               count = file->buff_len - file->buff_ind;
 
                done += ((fs_offset_t)buffersize > count) ? count : (fs_offset_t)buffersize;
                memcpy (buffer, &file->buff[file->buff_ind], done);
@@ -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 = (fs_offset_t)((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;
@@ -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->position += (fs_offset_t)file->buff_len;
+                       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 = (fs_offset_t)((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;
                }
@@ -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;
@@ -1880,7 +1892,7 @@ Give the current position in a file
 */
 fs_offset_t FS_Tell (qfile_t* file)
 {
-       return file->position - (fs_offset_t)(file->buff_len + file->buff_ind);
+       return file->position - file->buff_len + file->buff_ind;
 }