// Create a package structure in memory
pack = Mem_Alloc (pak_mempool, sizeof (pack_t));
pack->ignorecase = true; // PK3 ignores case
- strcpy (pack->filename, packfile);
+ strlcpy (pack->filename, packfile, sizeof (pack->filename));
pack->handle = packhandle;
pack->numfiles = eocd.nbentries;
pack->mempool = Mem_AllocPool (packfile);
pack = Mem_Alloc(pak_mempool, sizeof (pack_t));
pack->ignorecase = false; // PAK is case sensitive
- strcpy (pack->filename, packfile);
+ strlcpy (pack->filename, packfile, sizeof (pack->filename));
pack->handle = packhandle;
pack->numfiles = numpackfiles;
pack->mempool = Mem_AllocPool(packfile);
size_t size;
packfile_t *file = &pack->files[i];
- strcpy (file->name, info[i].name);
+ strlcpy (file->name, info[i].name, sizeof (file->name));
file->offset = LittleLong(info[i].filepos);
size = LittleLong (info[i].filelen);
file->packsize = size;
pack_t *pak;
char pakfile[MAX_OSPATH];
- strcpy (fs_gamedir, dir);
+ strlcpy (fs_gamedir, dir, sizeof (fs_gamedir));
// add the directory to the search path
search = Mem_Alloc(pak_mempool, sizeof(searchpath_t));
- strcpy (search->filename, dir);
+ strlcpy (search->filename, dir, sizeof (search->filename));
search->next = fs_searchpaths;
fs_searchpaths = search;
{
if (matchpattern(current->text, "*.pak", true))
{
- sprintf (pakfile, "%s/%s", dir, current->text);
+ snprintf (pakfile, sizeof (pakfile), "%s/%s", dir, current->text);
pak = FS_LoadPackPAK (pakfile);
if (pak)
{
{
if (matchpattern(current->text, "*.pk3", true))
{
- sprintf (pakfile, "%s/%s", dir, current->text);
+ snprintf (pakfile, sizeof (pakfile), "%s/%s", dir, current->text);
pak = FS_LoadPackPK3 (pakfile);
if (pak)
{
// Overrides the system supplied base directory (under GAMENAME)
i = COM_CheckParm ("-basedir");
if (i && i < com_argc-1)
- strcpy (fs_basedir, com_argv[i+1]);
+ strlcpy (fs_basedir, com_argv[i+1], sizeof (fs_basedir));
i = strlen (fs_basedir);
if (i > 0 && (fs_basedir[i-1] == '\\' || fs_basedir[i-1] == '/'))
fs_basedir[i-1] = 0;
// start up with GAMENAME by default (id1)
- strcpy(com_modname, GAMENAME);
+ strlcpy (com_modname, GAMENAME, sizeof (com_modname));
FS_AddGameDirectory (va("%s/"GAMENAME, fs_basedir));
if (gamedirname[0])
{
fs_modified = true;
- strcpy(com_modname, gamedirname);
+ strlcpy (com_modname, gamedirname, sizeof (com_modname));
FS_AddGameDirectory (va("%s/%s", fs_basedir, gamedirname));
}
if (i && i < com_argc-1)
{
fs_modified = true;
- strcpy(com_modname, com_argv[i+1]);
+ strlcpy (com_modname, com_argv[i+1], sizeof (com_modname));
FS_AddGameDirectory (va("%s/%s", fs_basedir, com_argv[i+1]));
}
Sys_Error ("Couldn't load packfile: %s", com_argv[i]);
}
else
- strcpy (search->filename, com_argv[i]);
+ strlcpy (search->filename, com_argv[i], sizeof (search->filename));
search->next = fs_searchpaths;
fs_searchpaths = search;
}
filenamelen = strlen (filename);
+#ifdef AKVERSION
+ // search through the path, one element at a time
+ search = fs_searchpaths;
+
+ for( ; search ; search = search->next)
+ if(!search->pack)
+ {
+ snprintf (netpath, sizeof (netpath), "%s/%s",search->filename, filename);
+
+ if (!FS_SysFileExists (netpath))
+ continue;
+
+ if (!quiet)
+ Sys_Printf ("FindFile: %s\n",netpath);
+ return FS_OpenRead (netpath, -1, -1);
+ }
+
+ search = fs_searchpaths;
+ for ( ; search ; search = search->next)
+ // is the element a pak file?
+ if (search->pack)
+ {
+ // look through all the pak file elements
+ pak = search->pack;
+ for (i=0 ; i<pak->numfiles ; i++)
+ {
+ if (pak->ignorecase)
+ matched = !strcasecmp (pak->files[i].name, filename);
+ else
+ matched = !strcmp (pak->files[i].name, filename);
+ if (matched) // found it?
+ {
+ qfile_t *file;
+
+ if (!quiet)
+ Sys_Printf ("PackFile: %s : %s\n",pak->filename, pak->files[i].name);
+
+ // If we don't have the true offset, get it now
+ if (! (pak->files[i].flags & FILE_FLAG_TRUEOFFS))
+ PK3_GetTrueFileOffset (&pak->files[i], pak);
+
+ // No Zlib DLL = no compressed files
+ if (!zlib_dll && (pak->files[i].flags & FILE_FLAG_DEFLATED))
+ {
+ Con_Printf ("WARNING: can't open the compressed file %s\n"
+ "You need the Zlib DLL to use compressed files\n", filename);
+ fs_filesize = -1;
+ return NULL;
+ }
+
+ // open a new file in the pakfile
+ file = FS_OpenRead (pak->filename, pak->files[i].offset, pak->files[i].packsize);
+ fs_filesize = pak->files[i].realsize;
+
+ if (pak->files[i].flags & FILE_FLAG_DEFLATED)
+ {
+ ztoolkit_t *ztk;
+
+ file->flags |= FS_FLAG_DEFLATED;
+
+ // We need some more variables
+ ztk = Mem_Alloc (fs_mempool, sizeof (*file->z));
+
+ ztk->real_length = pak->files[i].realsize;
+
+ // 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)
+ Sys_Error ("inflate init error (file: %s)", filename);
+
+ ztk->zstream.next_out = ztk->output;
+ ztk->zstream.avail_out = sizeof (ztk->output);
+
+ file->z = ztk;
+ }
+
+ return file;
+ }
+ }
+ }
+#else
// search through the path, one element at a time
search = fs_searchpaths;
}
else
{
- sprintf (netpath, "%s/%s",search->filename, filename);
+ snprintf (netpath, sizeof (netpath), "%s/%s",search->filename, filename);
if (!FS_SysFileExists (netpath))
continue;
return FS_OpenRead (netpath, -1, -1);
}
}
-
+#endif
+
if (!quiet)
Sys_Printf ("FindFile: can't find %s\n", filename);
FILE *handle;
char name[MAX_OSPATH];
- sprintf (name, "%s/%s", fs_gamedir, filename);
+ snprintf (name, sizeof (name), "%s/%s", fs_gamedir, filename);
// Create directories up to the file
FS_CreatePath (name);
FS_StripExtension
============
*/
-void FS_StripExtension (const char *in, char *out)
+void FS_StripExtension (const char *in, char *out, size_t size_out)
{
char *last = NULL;
- while (*in)
+
+ if (size_out == 0)
+ return;
+
+ while (*in && size_out > 1)
{
if (*in == '.')
last = out;
else if (*in == '/' || *in == '\\' || *in == ':')
last = NULL;
*out++ = *in++;
+ size_out--;
}
if (last)
*last = 0;
FS_DefaultExtension
==================
*/
-void FS_DefaultExtension (char *path, const char *extension)
+void FS_DefaultExtension (char *path, const char *extension, size_t size_path)
{
const char *src;
src--;
}
- strcat (path, extension);
+ strlcat (path, extension, size_path);
}
}
else
{
- sprintf (netpath, "%s/%s",search->filename, filename);
+ snprintf (netpath, sizeof (netpath), "%s/%s",search->filename, filename);
if (FS_SysFileExists (netpath))
return true;
}