]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - fs.c
Merge MR 'Move SDL_GL_GetProcAddress after creating GL context'
[xonotic/darkplaces.git] / fs.c
diff --git a/fs.c b/fs.c
index 6c00d3c53b8de94173192c2db4b6aba7c885a80b..747ace822e63c840af846ee1d80d780902b7b17d 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -74,7 +74,6 @@
 # define dup _dup
 #endif
 
-#define USE_RWOPS 1
 #if USE_RWOPS
 # include <SDL.h>
 typedef SDL_RWops *filedesc_t;
@@ -683,7 +682,7 @@ static int PK3_BuildFileList (pack_t *pack, const pk3_endOfCentralDir_t *eocd)
                        return -1;
                }
 
-               namesize = BuffLittleShort (&ptr[28]);  // filename length
+               namesize = (unsigned short)BuffLittleShort (&ptr[28]);  // filename length
 
                // Check encryption, compression, and attributes
                // 1st uint8  : general purpose bit flag
@@ -700,7 +699,7 @@ static int PK3_BuildFileList (pack_t *pack, const pk3_endOfCentralDir_t *eocd)
                if ((ptr[8] & 0x21) == 0 && (ptr[38] & 0x18) == 0)
                {
                        // Still enough bytes for the name?
-                       if (namesize < 0 || remaining < namesize || namesize >= (int)sizeof (*pack->files))
+                       if (remaining < namesize || namesize >= (int)sizeof (*pack->files))
                        {
                                Mem_Free (central_dir);
                                return -1;
@@ -744,7 +743,7 @@ static int PK3_BuildFileList (pack_t *pack, const pk3_endOfCentralDir_t *eocd)
                // Skip the name, additionnal field, and comment
                // 1er uint16 : extra field length
                // 2eme uint16 : file comment length
-               count = namesize + BuffLittleShort (&ptr[30]) + BuffLittleShort (&ptr[32]);
+               count = namesize + (unsigned short)BuffLittleShort (&ptr[30]) + (unsigned short)BuffLittleShort (&ptr[32]);
                ptr += ZIP_CDIR_CHUNK_BASE_SIZE + count;
                remaining -= count;
        }
@@ -2085,15 +2084,18 @@ void FS_Init (void)
                *fs_userdir = 0; // user wants roaming installation, no userdir
        else
        {
+#ifdef DP_FS_USERDIR
+               strlcpy(fs_userdir, DP_FS_USERDIR, sizeof(fs_userdir));
+#else
                int dirmode;
                int highestuserdirmode = USERDIRMODE_COUNT - 1;
                int preferreduserdirmode = USERDIRMODE_COUNT - 1;
                int userdirstatus[USERDIRMODE_COUNT];
-#ifdef WIN32
+# ifdef WIN32
                // historical behavior...
                if (!strcmp(gamedirname1, "id1"))
                        preferreduserdirmode = USERDIRMODE_NOHOME;
-#endif
+# endif
                // check what limitations the user wants to impose
                if (COM_CheckParm("-home")) preferreduserdirmode = USERDIRMODE_HOME;
                if (COM_CheckParm("-mygames")) preferreduserdirmode = USERDIRMODE_MYGAMES;
@@ -2125,6 +2127,7 @@ void FS_Init (void)
                // and finally, we picked one...
                FS_ChooseUserDir((userdirmode_t)dirmode, fs_userdir, sizeof(fs_userdir));
                Con_DPrintf("userdir %i is the winner\n", dirmode);
+#endif
        }
 
        // if userdir equal to basedir, clear it to avoid confusion later
@@ -3239,9 +3242,9 @@ int FS_Seek (qfile_t* file, fs_offset_t offset, int whence)
        buffer = (unsigned char *)Mem_Alloc (tempmempool, buffersize);
 
        // Skip all data until we reach the requested offset
-       while (offset > file->position)
+       while (offset > (file->position - file->buff_len + file->buff_ind))
        {
-               fs_offset_t diff = offset - file->position;
+               fs_offset_t diff = offset - (file->position - file->buff_len + file->buff_ind);
                fs_offset_t count, len;
 
                count = (diff > buffersize) ? buffersize : diff;
@@ -3563,7 +3566,6 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet)
        stringlist_t dirlist;
        const char *slash, *backslash, *colon, *separator;
        char *basepath;
-       char temp[MAX_OSPATH];
 
        for (i = 0;pattern[i] == '.' || pattern[i] == ':' || pattern[i] == '/' || pattern[i] == '\\';i++)
                ;
@@ -3598,6 +3600,7 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet)
                        pak = searchpath->pack;
                        for (i = 0;i < pak->numfiles;i++)
                        {
+                               char temp[MAX_OSPATH];
                                strlcpy(temp, pak->files[i].name, sizeof(temp));
                                while (temp[0])
                                {
@@ -3681,6 +3684,7 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet)
 
                                // for each entry in matchedSet try to open the subdirectories specified in subpath
                                for( dirlistindex = 0 ; dirlistindex < matchedSet.numstrings ; dirlistindex++ ) {
+                                       char temp[MAX_OSPATH];
                                        strlcpy( temp, matchedSet.strings[ dirlistindex ], sizeof(temp) );
                                        strlcat( temp, subpath, sizeof(temp) );
                                        listdirectory( &foundSet, searchpath->filename, temp );
@@ -3704,17 +3708,17 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet)
 
                        for (dirlistindex = 0;dirlistindex < matchedSet.numstrings;dirlistindex++)
                        {
-                               const char *temp = matchedSet.strings[dirlistindex];
-                               if (matchpattern(temp, (char *)pattern, true))
+                               const char *matchtemp = matchedSet.strings[dirlistindex];
+                               if (matchpattern(matchtemp, (char *)pattern, true))
                                {
                                        for (resultlistindex = 0;resultlistindex < resultlist.numstrings;resultlistindex++)
-                                               if (!strcmp(resultlist.strings[resultlistindex], temp))
+                                               if (!strcmp(resultlist.strings[resultlistindex], matchtemp))
                                                        break;
                                        if (resultlistindex == resultlist.numstrings)
                                        {
-                                               stringlistappend(&resultlist, temp);
+                                               stringlistappend(&resultlist, matchtemp);
                                                if (!quiet && developer_loading.integer)
-                                                       Con_Printf("SearchDirFile: %s\n", temp);
+                                                       Con_Printf("SearchDirFile: %s\n", matchtemp);
                                        }
                                }
                        }