+ i = (int)strlen (fs_basedir);
+ if (i > 0 && (fs_basedir[i-1] == '\\' || fs_basedir[i-1] == '/'))
+ fs_basedir[i-1] = 0;
+ }
+ else
+ {
+// If the base directory is explicitly defined by the compilation process
+#ifdef DP_FS_BASEDIR
+ strlcpy(fs_basedir, DP_FS_BASEDIR, sizeof(fs_basedir));
+#elif defined(MACOSX)
+ // FIXME: is there a better way to find the directory outside the .app, without using Objective-C?
+ if (strstr(com_argv[0], ".app/"))
+ {
+ char *split;
+ strlcpy(fs_basedir, com_argv[0], sizeof(fs_basedir));
+ split = strstr(fs_basedir, ".app/");
+ if (split)
+ {
+ struct stat statresult;
+ char vabuf[1024];
+ // truncate to just after the .app/
+ split[5] = 0;
+ // see if gamedir exists in Resources
+ if (stat(va(vabuf, sizeof(vabuf), "%s/Contents/Resources/%s", fs_basedir, gamedirname1), &statresult) == 0)
+ {
+ // found gamedir inside Resources, use it
+ strlcat(fs_basedir, "Contents/Resources/", sizeof(fs_basedir));
+ }
+ else
+ {
+ // no gamedir found in Resources, gamedir is probably
+ // outside the .app, remove .app part of path
+ while (split > fs_basedir && *split != '/')
+ split--;
+ *split = 0;
+ }
+ }
+ }
+#endif
+ }
+
+ // make sure the appending of a path separator won't create an unterminated string
+ memset(fs_basedir + sizeof(fs_basedir) - 2, 0, 2);
+ // add a path separator to the end of the basedir if it lacks one
+ if (fs_basedir[0] && fs_basedir[strlen(fs_basedir) - 1] != '/' && fs_basedir[strlen(fs_basedir) - 1] != '\\')
+ strlcat(fs_basedir, "/", sizeof(fs_basedir));
+
+ // Add the personal game directory
+ if((i = COM_CheckParm("-userdir")) && i < com_argc - 1)
+ dpsnprintf(fs_userdir, sizeof(fs_userdir), "%s/", com_argv[i+1]);
+ else if (COM_CheckParm("-nohome"))
+ *fs_userdir = 0; // user wants roaming installation, no userdir
+ else
+ {
+ int dirmode;
+ int highestuserdirmode = USERDIRMODE_COUNT - 1;
+ int preferreduserdirmode = USERDIRMODE_COUNT - 1;
+ int userdirstatus[USERDIRMODE_COUNT];
+#ifdef WIN32
+ // historical behavior...
+ if (!strcmp(gamedirname1, "id1"))
+ preferreduserdirmode = USERDIRMODE_NOHOME;
+#endif
+ // check what limitations the user wants to impose
+ if (COM_CheckParm("-home")) preferreduserdirmode = USERDIRMODE_HOME;
+ if (COM_CheckParm("-mygames")) preferreduserdirmode = USERDIRMODE_MYGAMES;
+ if (COM_CheckParm("-savedgames")) preferreduserdirmode = USERDIRMODE_SAVEDGAMES;
+ // gather the status of the possible userdirs
+ for (dirmode = 0;dirmode < USERDIRMODE_COUNT;dirmode++)
+ {
+ userdirstatus[dirmode] = FS_ChooseUserDir((userdirmode_t)dirmode, fs_userdir, sizeof(fs_userdir));
+ if (userdirstatus[dirmode] == 1)
+ Con_DPrintf("userdir %i = %s (writable)\n", dirmode, fs_userdir);
+ else if (userdirstatus[dirmode] == 0)
+ Con_DPrintf("userdir %i = %s (not writable or does not exist)\n", dirmode, fs_userdir);
+ else
+ Con_DPrintf("userdir %i (not applicable)\n", dirmode);
+ }
+ // some games may prefer writing to basedir, but if write fails we
+ // have to search for a real userdir...
+ if (preferreduserdirmode == 0 && userdirstatus[0] < 1)
+ preferreduserdirmode = highestuserdirmode;
+ // check for an existing userdir and continue using it if possible...
+ for (dirmode = USERDIRMODE_COUNT - 1;dirmode > 0;dirmode--)
+ if (userdirstatus[dirmode] == 1)
+ break;
+ // if no existing userdir found, make a new one...
+ if (dirmode == 0 && preferreduserdirmode > 0)
+ for (dirmode = preferreduserdirmode;dirmode > 0;dirmode--)
+ if (userdirstatus[dirmode] >= 0)
+ break;
+ // and finally, we picked one...
+ FS_ChooseUserDir((userdirmode_t)dirmode, fs_userdir, sizeof(fs_userdir));
+ Con_DPrintf("userdir %i is the winner\n", dirmode);
+ }
+
+ // if userdir equal to basedir, clear it to avoid confusion later
+ if (!strcmp(fs_basedir, fs_userdir))
+ fs_userdir[0] = 0;
+
+ FS_ListGameDirs();
+
+ p = FS_CheckGameDir(gamedirname1);
+ if(!p || p == fs_checkgamedir_missing)
+ Con_Printf("WARNING: base gamedir %s%s/ not found!\n", fs_basedir, gamedirname1);
+
+ if(gamedirname2)
+ {
+ p = FS_CheckGameDir(gamedirname2);
+ if(!p || p == fs_checkgamedir_missing)
+ Con_Printf("WARNING: base gamedir %s%s/ not found!\n", fs_basedir, gamedirname2);
+ }
+
+ // -game <gamedir>
+ // Adds basedir/gamedir as an override game
+ // LordHavoc: now supports multiple -game directories
+ for (i = 1;i < com_argc && fs_numgamedirs < MAX_GAMEDIRS;i++)
+ {
+ if (!com_argv[i])
+ continue;
+ if (!strcmp (com_argv[i], "-game") && i < com_argc-1)
+ {
+ i++;
+ p = FS_CheckGameDir(com_argv[i]);
+ if(!p)
+ Sys_Error("Nasty -game name rejected: %s", com_argv[i]);
+ if(p == fs_checkgamedir_missing)
+ Con_Printf("WARNING: -game %s%s/ not found!\n", fs_basedir, com_argv[i]);
+ // add the gamedir to the list of active gamedirs
+ strlcpy (fs_gamedirs[fs_numgamedirs], com_argv[i], sizeof(fs_gamedirs[fs_numgamedirs]));
+ fs_numgamedirs++;
+ }
+ }
+
+ // generate the searchpath
+ FS_Rescan();
+
+ if (Thread_HasThreads())
+ fs_mutex = Thread_CreateMutex();
+}
+
+void FS_Init_Commands(void)
+{
+ Cvar_RegisterVariable (&scr_screenshot_name);
+ Cvar_RegisterVariable (&fs_empty_files_in_pack_mark_deletions);
+ Cvar_RegisterVariable (&cvar_fs_gamedir);
+
+ Cmd_AddCommand ("gamedir", FS_GameDir_f, "changes active gamedir list (can take multiple arguments), not including base directory (example usage: gamedir ctf)");
+ Cmd_AddCommand ("fs_rescan", FS_Rescan_f, "rescans filesystem for new pack archives and any other changes");
+ Cmd_AddCommand ("path", FS_Path_f, "print searchpath (game directories and archives)");
+ Cmd_AddCommand ("dir", FS_Dir_f, "list files in searchpath matching an * filename pattern, one per line");
+ Cmd_AddCommand ("ls", FS_Ls_f, "list files in searchpath matching an * filename pattern, multiple per line");
+ Cmd_AddCommand ("which", FS_Which_f, "accepts a file name as argument and reports where the file is taken from");
+}
+
+/*
+================
+FS_Shutdown
+================
+*/
+void FS_Shutdown (void)
+{
+ // close all pack files and such
+ // (hopefully there aren't any other open files, but they'll be cleaned up
+ // by the OS anyway)
+ FS_ClearSearchPath();
+ Mem_FreePool (&fs_mempool);
+ PK3_CloseLibrary ();
+
+#ifdef WIN32
+ Sys_UnloadLibrary (&shfolder_dll);
+ Sys_UnloadLibrary (&shell32_dll);
+ Sys_UnloadLibrary (&ole32_dll);
+#endif
+
+ if (fs_mutex)
+ Thread_DestroyMutex(fs_mutex);
+}
+
+int FS_SysOpenFD(const char *filepath, const char *mode, qboolean nonblocking)
+{
+ int handle = -1;
+ int mod, opt;
+ unsigned int ind;
+ qboolean dolock = false;
+
+ // Parse the mode string
+ switch (mode[0])
+ {
+ case 'r':
+ mod = O_RDONLY;
+ opt = 0;
+ break;
+ case 'w':
+ mod = O_WRONLY;
+ opt = O_CREAT | O_TRUNC;
+ break;
+ case 'a':
+ mod = O_WRONLY;
+ opt = O_CREAT | O_APPEND;
+ break;
+ default:
+ Con_Printf ("FS_SysOpen(%s, %s): invalid mode\n", filepath, mode);
+ return -1;
+ }
+ for (ind = 1; mode[ind] != '\0'; ind++)
+ {
+ switch (mode[ind])
+ {
+ case '+':
+ mod = O_RDWR;
+ break;
+ case 'b':
+ opt |= O_BINARY;
+ break;
+ case 'l':
+ dolock = true;
+ break;
+ default:
+ Con_Printf ("FS_SysOpen(%s, %s): unknown character in mode (%c)\n",
+ filepath, mode, mode[ind]);
+ }
+ }
+
+ if (nonblocking)
+ opt |= O_NONBLOCK;
+
+#ifdef WIN32
+# if _MSC_VER >= 1400
+ _sopen_s(&handle, filepath, mod | opt, (dolock ? ((mod == O_RDONLY) ? _SH_DENYRD : _SH_DENYRW) : _SH_DENYNO), _S_IREAD | _S_IWRITE);
+# else
+ handle = _sopen (filepath, mod | opt, (dolock ? ((mod == O_RDONLY) ? _SH_DENYRD : _SH_DENYRW) : _SH_DENYNO), _S_IREAD | _S_IWRITE);
+# endif
+#else
+ handle = open (filepath, mod | opt, 0666);
+ if(handle >= 0 && dolock)
+ {
+ struct flock l;
+ l.l_type = ((mod == O_RDONLY) ? F_RDLCK : F_WRLCK);
+ l.l_whence = SEEK_SET;
+ l.l_start = 0;
+ l.l_len = 0;
+ if(fcntl(handle, F_SETLK, &l) == -1)
+ {
+ close(handle);
+ handle = -1;
+ }
+ }
+#endif
+
+ return handle;
+}
+
+/*
+====================
+FS_SysOpen
+
+Internal function used to create a qfile_t and open the relevant non-packed file on disk
+====================
+*/
+qfile_t* FS_SysOpen (const char* filepath, const char* mode, qboolean nonblocking)
+{
+ qfile_t* file;
+
+ file = (qfile_t *)Mem_Alloc (fs_mempool, sizeof (*file));
+ file->ungetc = EOF;
+ file->handle = FS_SysOpenFD(filepath, mode, nonblocking);
+ if (file->handle < 0)
+ {
+ Mem_Free (file);
+ return NULL;
+ }
+
+ file->filename = Mem_strdup(fs_mempool, filepath);
+
+ file->real_length = lseek (file->handle, 0, SEEK_END);
+
+ // For files opened in append mode, we start at the end of the file
+ if (mode[0] == 'a')
+ file->position = file->real_length;
+ else
+ lseek (file->handle, 0, SEEK_SET);
+
+ return file;
+}
+
+
+/*
+===========
+FS_OpenPackedFile
+
+Open a packed file using its package file descriptor
+===========
+*/
+static qfile_t *FS_OpenPackedFile (pack_t* pack, int pack_ind)
+{
+ packfile_t *pfile;
+ int dup_handle;
+ qfile_t* file;
+
+ pfile = &pack->files[pack_ind];
+
+ // If we don't have the true offset, get it now
+ if (! (pfile->flags & PACKFILE_FLAG_TRUEOFFS))
+ if (!PK3_GetTrueFileOffset (pfile, pack))
+ return NULL;
+
+#ifndef LINK_TO_ZLIB
+ // No Zlib DLL = no compressed files
+ if (!zlib_dll && (pfile->flags & PACKFILE_FLAG_DEFLATED))
+ {
+ Con_Printf("WARNING: can't open the compressed file %s\n"
+ "You need the Zlib DLL to use compressed files\n",
+ pfile->name);
+ return NULL;
+ }
+#endif
+
+ // LordHavoc: lseek affects all duplicates of a handle so we do it before
+ // the dup() call to avoid having to close the dup_handle on error here
+ if (lseek (pack->handle, pfile->offset, SEEK_SET) == -1)
+ {
+ Con_Printf ("FS_OpenPackedFile: can't lseek to %s in %s (offset: %08x%08x)\n",
+ pfile->name, pack->filename, (unsigned int)(pfile->offset >> 32), (unsigned int)(pfile->offset));
+ return NULL;
+ }
+
+ dup_handle = dup (pack->handle);
+ if (dup_handle < 0)
+ {
+ Con_Printf ("FS_OpenPackedFile: can't dup package's handle (pack: %s)\n", pack->filename);
+ return NULL;
+ }
+
+ file = (qfile_t *)Mem_Alloc (fs_mempool, sizeof (*file));
+ memset (file, 0, sizeof (*file));
+ file->handle = dup_handle;
+ file->flags = QFILE_FLAG_PACKED;
+ file->real_length = pfile->realsize;
+ file->offset = pfile->offset;
+ file->position = 0;
+ file->ungetc = EOF;
+
+ if (pfile->flags & PACKFILE_FLAG_DEFLATED)
+ {
+ ztoolkit_t *ztk;
+
+ file->flags |= QFILE_FLAG_DEFLATED;
+
+ // We need some more variables
+ ztk = (ztoolkit_t *)Mem_Alloc (fs_mempool, sizeof (*ztk));
+
+ ztk->comp_length = pfile->packsize;
+
+ // Initialize zlib stream
+ ztk->zstream.next_in = ztk->input;
+ ztk->zstream.avail_in = 0;
+
+ /* From Zlib's "unzip.c":
+ *
+ * windowBits is passed < 0 to tell that there is no zlib header.
+ * Note that in this case inflate *requires* an extra "dummy" byte
+ * after the compressed stream in order to complete decompression and
+ * return Z_STREAM_END.
+ * In unzip, i don't wait absolutely Z_STREAM_END because I known the
+ * size of both compressed and uncompressed data
+ */
+ if (qz_inflateInit2 (&ztk->zstream, -MAX_WBITS) != Z_OK)
+ {
+ Con_Printf ("FS_OpenPackedFile: inflate init error (file: %s)\n", pfile->name);
+ close(dup_handle);
+ Mem_Free(file);
+ return NULL;
+ }
+
+ ztk->zstream.next_out = file->buff;
+ ztk->zstream.avail_out = sizeof (file->buff);
+
+ file->ztk = ztk;
+ }
+
+ return file;
+}
+
+/*
+====================
+FS_CheckNastyPath
+
+Return true if the path should be rejected due to one of the following:
+1: path elements that are non-portable
+2: path elements that would allow access to files outside the game directory,
+ or are just not a good idea for a mod to be using.
+====================
+*/
+int FS_CheckNastyPath (const char *path, qboolean isgamedir)
+{
+ // all: never allow an empty path, as for gamedir it would access the parent directory and a non-gamedir path it is just useless
+ if (!path[0])
+ return 2;
+
+ // Windows: don't allow \ in filenames (windows-only), period.
+ // (on Windows \ is a directory separator, but / is also supported)
+ if (strstr(path, "\\"))
+ return 1; // non-portable
+
+ // Mac: don't allow Mac-only filenames - : is a directory separator
+ // instead of /, but we rely on / working already, so there's no reason to
+ // support a Mac-only path
+ // Amiga and Windows: : tries to go to root of drive
+ if (strstr(path, ":"))
+ return 1; // non-portable attempt to go to root of drive
+
+ // Amiga: // is parent directory
+ if (strstr(path, "//"))
+ return 1; // non-portable attempt to go to parent directory
+
+ // all: don't allow going to parent directory (../ or /../)
+ if (strstr(path, ".."))
+ return 2; // attempt to go outside the game directory
+
+ // Windows and UNIXes: don't allow absolute paths
+ if (path[0] == '/')
+ return 2; // attempt to go outside the game directory
+
+ // all: don't allow . characters before the last slash (it should only be used in filenames, not path elements), this catches all imaginable cases of ./, ../, .../, etc
+ if (strchr(path, '.'))
+ {
+ if (isgamedir)
+ {
+ // gamedir is entirely path elements, so simply forbid . entirely
+ return 2;
+ }
+ if (strchr(path, '.') < strrchr(path, '/'))
+ return 2; // possible attempt to go outside the game directory
+ }
+
+ // all: forbid trailing slash on gamedir
+ if (isgamedir && path[strlen(path)-1] == '/')
+ return 2;
+
+ // all: forbid leading dot on any filename for any reason
+ if (strstr(path, "/."))
+ return 2; // attempt to go outside the game directory
+
+ // after all these checks we're pretty sure it's a / separated filename
+ // and won't do much if any harm
+ return false;
+}
+
+
+/*
+====================
+FS_FindFile
+
+Look for a file in the packages and in the filesystem
+
+Return the searchpath where the file was found (or NULL)
+and the file index in the package if relevant
+====================
+*/
+static searchpath_t *FS_FindFile (const char *name, int* index, qboolean quiet)
+{
+ searchpath_t *search;
+ pack_t *pak;
+
+ // search through the path, one element at a time
+ for (search = fs_searchpaths;search;search = search->next)
+ {
+ // is the element a pak file?
+ if (search->pack && !search->pack->vpack)
+ {
+ int (*strcmp_funct) (const char* str1, const char* str2);
+ int left, right, middle;
+
+ pak = search->pack;
+ strcmp_funct = pak->ignorecase ? strcasecmp : strcmp;
+
+ // Look for the file (binary search)
+ left = 0;
+ right = pak->numfiles - 1;
+ while (left <= right)
+ {
+ int diff;
+
+ middle = (left + right) / 2;
+ diff = strcmp_funct (pak->files[middle].name, name);
+
+ // Found it
+ if (!diff)
+ {
+ if (fs_empty_files_in_pack_mark_deletions.integer && pak->files[middle].realsize == 0)
+ {
+ // yes, but the first one is empty so we treat it as not being there
+ if (!quiet && developer_extra.integer)
+ Con_DPrintf("FS_FindFile: %s is marked as deleted\n", name);
+
+ if (index != NULL)
+ *index = -1;
+ return NULL;
+ }
+
+ if (!quiet && developer_extra.integer)
+ Con_DPrintf("FS_FindFile: %s in %s\n",
+ pak->files[middle].name, pak->filename);
+
+ if (index != NULL)
+ *index = middle;
+ return search;
+ }
+
+ // If we're too far in the list
+ if (diff > 0)
+ right = middle - 1;
+ else
+ left = middle + 1;
+ }
+ }
+ else
+ {
+ char netpath[MAX_OSPATH];
+ dpsnprintf(netpath, sizeof(netpath), "%s%s", search->filename, name);
+ if (FS_SysFileExists (netpath))
+ {
+ if (!quiet && developer_extra.integer)
+ Con_DPrintf("FS_FindFile: %s\n", netpath);
+
+ if (index != NULL)
+ *index = -1;
+ return search;
+ }
+ }
+ }
+
+ if (!quiet && developer_extra.integer)
+ Con_DPrintf("FS_FindFile: can't find %s\n", name);
+
+ if (index != NULL)
+ *index = -1;
+ return NULL;
+}
+
+
+/*
+===========
+FS_OpenReadFile
+
+Look for a file in the search paths and open it in read-only mode
+===========
+*/
+static qfile_t *FS_OpenReadFile (const char *filename, qboolean quiet, qboolean nonblocking, int symlinkLevels)
+{
+ searchpath_t *search;
+ int pack_ind;
+
+ search = FS_FindFile (filename, &pack_ind, quiet);
+
+ // Not found?
+ if (search == NULL)
+ return NULL;
+
+ // Found in the filesystem?
+ if (pack_ind < 0)
+ {
+ // this works with vpacks, so we are fine
+ char path [MAX_OSPATH];
+ dpsnprintf (path, sizeof (path), "%s%s", search->filename, filename);
+ return FS_SysOpen (path, "rb", nonblocking);
+ }
+
+ // So, we found it in a package...
+
+ // Is it a PK3 symlink?
+ // TODO also handle directory symlinks by parsing the whole structure...
+ // but heck, file symlinks are good enough for now
+ if(search->pack->files[pack_ind].flags & PACKFILE_FLAG_SYMLINK)
+ {
+ if(symlinkLevels <= 0)
+ {
+ Con_Printf("symlink: %s: too many levels of symbolic links\n", filename);
+ return NULL;
+ }
+ else
+ {
+ char linkbuf[MAX_QPATH];
+ fs_offset_t count;
+ qfile_t *linkfile = FS_OpenPackedFile (search->pack, pack_ind);
+ const char *mergeslash;
+ char *mergestart;
+
+ if(!linkfile)
+ return NULL;
+ count = FS_Read(linkfile, linkbuf, sizeof(linkbuf) - 1);
+ FS_Close(linkfile);
+ if(count < 0)
+ return NULL;
+ linkbuf[count] = 0;
+
+ // Now combine the paths...
+ mergeslash = strrchr(filename, '/');
+ mergestart = linkbuf;
+ if(!mergeslash)
+ mergeslash = filename;
+ while(!strncmp(mergestart, "../", 3))
+ {
+ mergestart += 3;
+ while(mergeslash > filename)
+ {
+ --mergeslash;
+ if(*mergeslash == '/')
+ break;
+ }
+ }
+ // Now, mergestart will point to the path to be appended, and mergeslash points to where it should be appended
+ if(mergeslash == filename)
+ {
+ // Either mergeslash == filename, then we just replace the name (done below)
+ }
+ else
+ {
+ // Or, we append the name after mergeslash;
+ // or rather, we can also shift the linkbuf so we can put everything up to and including mergeslash first
+ int spaceNeeded = mergeslash - filename + 1;
+ int spaceRemoved = mergestart - linkbuf;
+ if(count - spaceRemoved + spaceNeeded >= MAX_QPATH)
+ {
+ Con_DPrintf("symlink: too long path rejected\n");
+ return NULL;
+ }
+ memmove(linkbuf + spaceNeeded, linkbuf + spaceRemoved, count - spaceRemoved);
+ memcpy(linkbuf, filename, spaceNeeded);
+ linkbuf[count - spaceRemoved + spaceNeeded] = 0;
+ mergestart = linkbuf;
+ }
+ if (!quiet && developer_loading.integer)
+ Con_DPrintf("symlink: %s -> %s\n", filename, mergestart);
+ if(FS_CheckNastyPath (mergestart, false))
+ {
+ Con_DPrintf("symlink: nasty path %s rejected\n", mergestart);
+ return NULL;
+ }
+ return FS_OpenReadFile(mergestart, quiet, nonblocking, symlinkLevels - 1);
+ }
+ }
+
+ return FS_OpenPackedFile (search->pack, pack_ind);
+}
+
+
+/*
+=============================================================================
+
+MAIN PUBLIC FUNCTIONS
+
+=============================================================================
+*/
+
+/*
+====================
+FS_OpenRealFile
+
+Open a file in the userpath. The syntax is the same as fopen
+Used for savegame scanning in menu, and all file writing.
+====================
+*/
+qfile_t* FS_OpenRealFile (const char* filepath, const char* mode, qboolean quiet)
+{
+ char real_path [MAX_OSPATH];
+
+ if (FS_CheckNastyPath(filepath, false))
+ {
+ Con_Printf("FS_OpenRealFile(\"%s\", \"%s\", %s): nasty filename rejected\n", filepath, mode, quiet ? "true" : "false");
+ return NULL;
+ }
+
+ dpsnprintf (real_path, sizeof (real_path), "%s/%s", fs_gamedir, filepath); // this is never a vpack
+
+ // If the file is opened in "write", "append", or "read/write" mode,
+ // create directories up to the file.
+ if (mode[0] == 'w' || mode[0] == 'a' || strchr (mode, '+'))
+ FS_CreatePath (real_path);
+ return FS_SysOpen (real_path, mode, false);
+}
+
+
+/*
+====================
+FS_OpenVirtualFile
+
+Open a file. The syntax is the same as fopen
+====================
+*/
+qfile_t* FS_OpenVirtualFile (const char* filepath, qboolean quiet)
+{
+ qfile_t *result = NULL;
+ if (FS_CheckNastyPath(filepath, false))
+ {
+ Con_Printf("FS_OpenVirtualFile(\"%s\", %s): nasty filename rejected\n", filepath, quiet ? "true" : "false");
+ return NULL;
+ }
+
+ if (fs_mutex) Thread_LockMutex(fs_mutex);
+ result = FS_OpenReadFile (filepath, quiet, false, 16);
+ if (fs_mutex) Thread_UnlockMutex(fs_mutex);
+ return result;
+}
+
+
+/*
+====================
+FS_FileFromData
+
+Open a file. The syntax is the same as fopen
+====================
+*/
+qfile_t* FS_FileFromData (const unsigned char *data, const size_t size, qboolean quiet)
+{
+ qfile_t* file;
+ file = (qfile_t *)Mem_Alloc (fs_mempool, sizeof (*file));
+ memset (file, 0, sizeof (*file));
+ file->flags = QFILE_FLAG_DATA;
+ file->ungetc = EOF;
+ file->real_length = size;
+ file->data = data;
+ return file;
+}