-// LordHavoc: 256 pak files (was 10)
-#define MAX_HANDLES 256
-FILE *sys_handles[MAX_HANDLES];
-
-int findhandle (void)
-{
- int i;
-
- for (i=1 ; i<MAX_HANDLES ; i++)
- if (!sys_handles[i])
- return i;
- Sys_Error ("out of handles");
- return -1;
-}
-
-/*
-================
-filelength
-================
-*/
-int filelength (FILE *f)
-{
- int pos;
- int end;
- int t;
-
- t = VID_ForceUnlockedAndReturnState ();
-
- pos = ftell (f);
- fseek (f, 0, SEEK_END);
- end = ftell (f);
- fseek (f, pos, SEEK_SET);
-
- VID_ForceLockState (t);
-
- return end;
-}
-
-int Sys_FileOpenRead (char *path, int *hndl)
-{
- FILE *f;
- int i, retval;
- int t;
-
- t = VID_ForceUnlockedAndReturnState ();
-
- i = findhandle ();
-
- f = fopen(path, "rb");
-
- if (!f)
- {
- *hndl = -1;
- retval = -1;
- }
- else
- {
- sys_handles[i] = f;
- *hndl = i;
- retval = filelength(f);
- }
-
- VID_ForceLockState (t);
-
- return retval;
-}
-
-int Sys_FileOpenWrite (char *path)
-{
- FILE *f;
- int i;
- int t;
-
- t = VID_ForceUnlockedAndReturnState ();
-
- i = findhandle ();
-
- f = fopen(path, "wb");
- if (!f)
- Host_Error ("Error opening %s: %s", path,strerror(errno));
- sys_handles[i] = f;
-
- VID_ForceLockState (t);
-
- return i;
-}
-
-void Sys_FileClose (int handle)
-{
- int t;
-
- t = VID_ForceUnlockedAndReturnState ();
- fclose (sys_handles[handle]);
- sys_handles[handle] = NULL;
- VID_ForceLockState (t);
-}
-
-void Sys_FileSeek (int handle, int position)
-{
- int t;
-
- t = VID_ForceUnlockedAndReturnState ();
- fseek (sys_handles[handle], position, SEEK_SET);
- VID_ForceLockState (t);
-}
-
-int Sys_FileRead (int handle, void *dest, int count)
-{
- int t, x;
-
- t = VID_ForceUnlockedAndReturnState ();
- x = fread (dest, 1, count, sys_handles[handle]);
- VID_ForceLockState (t);
- return x;
-}
-
-int Sys_FileWrite (int handle, void *data, int count)