From 7b3a0f0cb8d8de8b721e17c81b72ca8debec15d3 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 3 Jan 2002 20:09:12 +0000 Subject: [PATCH] preliminary zlib patch --- Makefile | 6 +- client/cl_cin.c | 8 +- client/cl_main.c | 36 ++-- client/cl_parse.c | 18 +- client/cl_view.c | 2 +- client/client.h | 6 +- client/console.c | 8 +- client/keys.c | 4 +- client/keys.h | 2 +- client/menu.c | 18 +- client/snd_dma.c | 2 +- ctf/g_save.c | 91 ++++----- ctf/g_svcmds.c | 11 +- game/g_save.c | 89 ++++----- game/g_svcmds.c | 12 +- irix/qgl_irix.c | 4 +- irix/sys_irix.c | 4 +- irix/vid_so.c | 2 +- linux/glw_linux.h | 2 +- linux/qgl_linux.c | 94 ++++----- linux/sys_linux.c | 2 +- linux/vid_so.c | 8 +- qcommon/cmodel.c | 6 +- qcommon/common.c | 24 +-- qcommon/cvar.c | 8 +- qcommon/files.c | 60 +++--- qcommon/qcommon.h | 14 +- qcommon/quakeio.c | 432 ++++++++++++++++++++++++++++++++++++++++++ qcommon/quakeio.h | 56 ++++++ ref_gl/gl_rmisc.c | 12 +- ref_soft/r_misc.c | 14 +- server/server.h | 4 +- server/sv_ccmds.c | 66 +++---- server/sv_ents.c | 4 +- server/sv_init.c | 8 +- server/sv_main.c | 4 +- server/sv_send.c | 10 +- solaris/sys_solaris.c | 2 +- win32/glw_imp.c | 2 +- win32/glw_win.h | 2 +- win32/qgl_win.c | 2 +- win32/sys_win.c | 6 +- 42 files changed, 830 insertions(+), 335 deletions(-) create mode 100644 qcommon/quakeio.c create mode 100644 qcommon/quakeio.h diff --git a/Makefile b/Makefile index 5442fd2..3d41e71 100644 --- a/Makefile +++ b/Makefile @@ -82,7 +82,7 @@ BASE_CFLAGS=-Dstricmp=strcasecmp -Wall -Werror DEBUG_CFLAGS=$(BASE_CFLAGS) -g -LDFLAGS=-lm -ldl +LDFLAGS=-lz -lm -ldl SVGALDFLAGS=-lvga @@ -272,6 +272,7 @@ QUAKE2_OBJS = \ $(BUILDDIR)/client/files.o \ $(BUILDDIR)/client/mdfour.o \ $(BUILDDIR)/client/net_chan.o \ + $(BUILDDIR)/client/quakeio.o \ \ $(BUILDDIR)/client/sv_ccmds.o \ $(BUILDDIR)/client/sv_ents.o \ @@ -400,6 +401,9 @@ $(BUILDDIR)/client/mdfour.o : $(COMMON_DIR)/mdfour.c $(BUILDDIR)/client/net_chan.o : $(COMMON_DIR)/net_chan.c $(DO_CC) +$(BUILDDIR)/client/quakeio.o : $(COMMON_DIR)/quakeio.c + $(DO_CC) + $(BUILDDIR)/client/q_shared.o : $(GAME_DIR)/q_shared.c $(DO_CC) diff --git a/client/cl_cin.c b/client/cl_cin.c index 18ea81a..d495626 100644 --- a/client/cl_cin.c +++ b/client/cl_cin.c @@ -170,7 +170,7 @@ void SCR_StopCinematic (void) } if (cl.cinematic_file) { - fclose (cl.cinematic_file); + Qclose (cl.cinematic_file); cl.cinematic_file = NULL; } if (cin.hnodes1) @@ -436,11 +436,11 @@ byte *SCR_ReadNextFrame (void) int start, end, count; // read the next frame - r = fread (&command, 4, 1, cl.cinematic_file); + r = Qread (cl.cinematic_file, &command, 4); if (r == 0) // we'll give it one more chance - r = fread (&command, 4, 1, cl.cinematic_file); + r = Qread (cl.cinematic_file, &command, 4); - if (r != 1) + if (r != 4) return NULL; command = LittleLong(command); if (command == 2) diff --git a/client/cl_main.c b/client/cl_main.c index e19423a..6f7123a 100644 --- a/client/cl_main.c +++ b/client/cl_main.c @@ -117,8 +117,8 @@ void CL_WriteDemoMessage (void) // the first eight bytes are just packet sequencing stuff len = net_message.cursize-8; swlen = LittleLong(len); - fwrite (&swlen, 4, 1, cls.demofile); - fwrite (net_message.data+8, len, 1, cls.demofile); + Qwrite (cls.demofile, &swlen, 4); + Qwrite (cls.demofile, net_message.data+8, len); } @@ -141,8 +141,8 @@ void CL_Stop_f (void) // finish up len = -1; - fwrite (&len, 4, 1, cls.demofile); - fclose (cls.demofile); + Qwrite (cls.demofile, &len, 4); + Qclose (cls.demofile); cls.demofile = NULL; cls.demorecording = false; Com_Printf ("Stopped demo.\n"); @@ -192,7 +192,7 @@ void CL_Record_f (void) Com_Printf ("recording to %s.\n", name); FS_CreatePath (name); - cls.demofile = fopen (name, "wb"); + cls.demofile = Qopen (name, "wb"); if (!cls.demofile) { Com_Printf ("ERROR: couldn't open.\n"); @@ -226,8 +226,8 @@ void CL_Record_f (void) if (buf.cursize + strlen (cl.configstrings[i]) + 32 > buf.maxsize) { // write it out len = LittleLong (buf.cursize); - fwrite (&len, 4, 1, cls.demofile); - fwrite (buf.data, buf.cursize, 1, cls.demofile); + Qwrite (cls.demofile, &len, 4); + Qwrite (cls.demofile, buf.data, buf.cursize); buf.cursize = 0; } @@ -249,8 +249,8 @@ void CL_Record_f (void) if (buf.cursize + 64 > buf.maxsize) { // write it out len = LittleLong (buf.cursize); - fwrite (&len, 4, 1, cls.demofile); - fwrite (buf.data, buf.cursize, 1, cls.demofile); + Qwrite (cls.demofile, &len, 4); + Qwrite (cls.demofile, buf.data, buf.cursize); buf.cursize = 0; } @@ -264,8 +264,8 @@ void CL_Record_f (void) // write it to the demo file len = LittleLong (buf.cursize); - fwrite (&len, 4, 1, cls.demofile); - fwrite (buf.data, buf.cursize, 1, cls.demofile); + Qwrite (cls.demofile, &len, 4); + Qwrite (cls.demofile, buf.data, buf.cursize); // the rest of the demo file will be individual frames } @@ -652,7 +652,7 @@ void CL_Disconnect (void) // stop download if (cls.download) { - fclose(cls.download); + Qclose(cls.download); cls.download = NULL; } @@ -1555,23 +1555,23 @@ Writes key bindings and archived cvars to config.cfg */ void CL_WriteConfiguration (void) { - FILE *f; + QFile *f; char path[MAX_QPATH]; if (cls.state == ca_uninitialized) return; Com_sprintf (path, sizeof(path),"%s/config.cfg",FS_Gamedir()); - f = fopen (path, "w"); + f = Qopen (path, "w"); if (!f) { Com_Printf ("Couldn't write config.cfg.\n"); return; } - fprintf (f, "// generated by quake, do not modify\n"); + Qprintf (f, "// generated by quake, do not modify\n"); Key_WriteBindings (f); - fclose (f); + Qclose (f); Cvar_WriteVariables (path); } @@ -1755,14 +1755,14 @@ void CL_Frame (int msec) { lasttimecalled = Sys_Milliseconds(); if ( log_stats_file ) - fprintf( log_stats_file, "0\n" ); + Qprintf( log_stats_file, "0\n" ); } else { int now = Sys_Milliseconds(); if ( log_stats_file ) - fprintf( log_stats_file, "%d\n", now - lasttimecalled ); + Qprintf( log_stats_file, "%d\n", now - lasttimecalled ); lasttimecalled = now; } } diff --git a/client/cl_parse.c b/client/cl_parse.c index a79b217..7c0978c 100644 --- a/client/cl_parse.c +++ b/client/cl_parse.c @@ -68,7 +68,7 @@ to start a download from the server. */ qboolean CL_CheckOrDownloadFile (char *filename) { - FILE *fp; + QFile *fp; char name[MAX_OSPATH]; if (strstr (filename, "..")) @@ -97,11 +97,11 @@ qboolean CL_CheckOrDownloadFile (char *filename) // FS_CreatePath (name); - fp = fopen (name, "r+b"); + fp = Qopen (name, "r+b"); if (fp) { // it exists int len; - fseek(fp, 0, SEEK_END); - len = ftell(fp); + Qseek(fp, 0, SEEK_END); + len = Qtell(fp); cls.download = fp; @@ -212,7 +212,7 @@ void CL_ParseDownload (void) if (cls.download) { // if here, we tried to resume a file but the server said no - fclose (cls.download); + Qclose (cls.download); cls.download = NULL; } CL_RequestNextDownload (); @@ -226,7 +226,7 @@ void CL_ParseDownload (void) FS_CreatePath (name); - cls.download = fopen (name, "wb"); + cls.download = Qopen (name, "wb"); if (!cls.download) { net_message.readcount += size; @@ -236,7 +236,7 @@ void CL_ParseDownload (void) } } - fwrite (net_message.data + net_message.readcount, 1, size, cls.download); + Qwrite (cls.download, net_message.data + net_message.readcount, size); net_message.readcount += size; if (percent != 100) @@ -263,7 +263,7 @@ void CL_ParseDownload (void) // Com_Printf ("100%%\n"); - fclose (cls.download); + Qclose (cls.download); // rename the temp file to it's final name CL_DownloadFileName(oldn, sizeof(oldn), cls.downloadtempname); @@ -715,7 +715,7 @@ void CL_ParseServerMessage (void) Com_Printf ("Server disconnected, reconnecting\n"); if (cls.download) { //ZOID, close download - fclose (cls.download); + Qclose (cls.download); cls.download = NULL; } cls.state = ca_connecting; diff --git a/client/cl_view.c b/client/cl_view.c index 4b75809..b2c82e6 100644 --- a/client/cl_view.c +++ b/client/cl_view.c @@ -537,7 +537,7 @@ void V_RenderView( float stereo_separation ) if (cl_stats->value) Com_Printf ("ent:%i lt:%i part:%i\n", r_numentities, r_numdlights, r_numparticles); if ( log_stats->value && ( log_stats_file != 0 ) ) - fprintf( log_stats_file, "%i,%i,%i,",r_numentities, r_numdlights, r_numparticles); + Qprintf( log_stats_file, "%i,%i,%i,",r_numentities, r_numdlights, r_numparticles); SCR_AddDirtyPoint (scr_vrect.x, scr_vrect.y); diff --git a/client/client.h b/client/client.h index 2dc57a2..697c5fe 100644 --- a/client/client.h +++ b/client/client.h @@ -140,7 +140,7 @@ typedef struct // // non-gameserver infornamtion // FIXME: move this cinematic stuff into the cin_t structure - FILE *cinematic_file; + QFile *cinematic_file; int cinematictime; // cls.realtime for first cinematic frame int cinematicframe; char cinematicpalette[768]; @@ -225,7 +225,7 @@ typedef struct int challenge; // from the server to use for connecting - FILE *download; // file transfer from server + QFile *download; // file transfer from server char downloadtempname[MAX_OSPATH]; char downloadname[MAX_OSPATH]; int downloadnumber; @@ -235,7 +235,7 @@ typedef struct // demo recording info must be here, so it isn't cleared on level change qboolean demorecording; qboolean demowaiting; // don't record until a non-delta message is received - FILE *demofile; + QFile *demofile; } client_static_t; extern client_static_t cls; diff --git a/client/console.c b/client/console.c index 99e2e86..ec1fbec 100644 --- a/client/console.c +++ b/client/console.c @@ -144,7 +144,7 @@ void Con_Dump_f (void) { int l, x; char *line; - FILE *f; + QFile *f; char buffer[1024]; char name[MAX_OSPATH]; @@ -158,7 +158,7 @@ void Con_Dump_f (void) Com_Printf ("Dumped console text to %s.\n", name); FS_CreatePath (name); - f = fopen (name, "w"); + f = Qopen (name, "w"); if (!f) { Com_Printf ("ERROR: couldn't open.\n"); @@ -192,10 +192,10 @@ void Con_Dump_f (void) for (x=0; buffer[x]; x++) buffer[x] &= 0x7f; - fprintf (f, "%s\n", buffer); + Qprintf (f, "%s\n", buffer); } - fclose (f); + Qclose (f); } diff --git a/client/keys.c b/client/keys.c index 74d682d..a1734f8 100644 --- a/client/keys.c +++ b/client/keys.c @@ -613,13 +613,13 @@ Key_WriteBindings Writes lines containing "bind key value" ============ */ -void Key_WriteBindings (FILE *f) +void Key_WriteBindings (QFile *f) { int i; for (i=0 ; i<256 ; i++) if (keybindings[i] && keybindings[i][0]) - fprintf (f, "bind %s \"%s\"\n", Key_KeynumToString(i), keybindings[i]); + Qprintf (f, "bind %s \"%s\"\n", Key_KeynumToString(i), keybindings[i]); } diff --git a/client/keys.h b/client/keys.h index bed9735..35deb15 100644 --- a/client/keys.h +++ b/client/keys.h @@ -139,7 +139,7 @@ extern qboolean chat_team; void Key_Event (int key, qboolean down, unsigned time); void Key_Init (void); -void Key_WriteBindings (FILE *f); +void Key_WriteBindings (QFile *f); void Key_SetBinding (int keynum, char *binding); void Key_ClearStates (void); int Key_GetKey (void); diff --git a/client/menu.c b/client/menu.c index 150b510..1ffa2c3 100644 --- a/client/menu.c +++ b/client/menu.c @@ -2031,13 +2031,13 @@ qboolean m_savevalid[MAX_SAVEGAMES]; void Create_Savestrings (void) { int i; - FILE *f; + QFile *f; char name[MAX_OSPATH]; for (i=0 ; i"); @@ -2046,7 +2046,7 @@ void Create_Savestrings (void) else { FS_Read (m_savestrings[i], sizeof(m_savestrings[i]), f); - fclose (f); + Qclose (f); m_savevalid[i] = true; } } @@ -2514,13 +2514,13 @@ void StartServer_MenuInit( void ) char *s; int length; int i; - FILE *fp; + QFile *fp; /* ** load the list of map names */ Com_sprintf( mapsname, sizeof( mapsname ), "%s/maps.lst", FS_Gamedir() ); - if ( ( fp = fopen( mapsname, "rb" ) ) == 0 ) + if ( ( fp = Qopen( mapsname, "rb" ) ) == 0 ) { if ( ( length = FS_LoadFile( "maps.lst", ( void ** ) &buffer ) ) == -1 ) Com_Error( ERR_DROP, "couldn't find maps.lst\n" ); @@ -2530,12 +2530,12 @@ void StartServer_MenuInit( void ) #ifdef _WIN32 length = filelength( fileno( fp ) ); #else - fseek(fp, 0, SEEK_END); - length = ftell(fp); - fseek(fp, 0, SEEK_SET); + Qseek(fp, 0, SEEK_END); + length = Qtell(fp); + Qseek(fp, 0, SEEK_SET); #endif buffer = malloc( length ); - fread( buffer, length, 1, fp ); + Qread (fp , buffer, length); } s = buffer; diff --git a/client/snd_dma.c b/client/snd_dma.c index 09e408d..4a28e89 100644 --- a/client/snd_dma.c +++ b/client/snd_dma.c @@ -589,7 +589,7 @@ struct sfx_s *S_RegisterSexedSound (entity_state_t *ent, char *base) int n; char *p; struct sfx_s *sfx; - FILE *f; + QFile *f; char model[MAX_QPATH]; char sexedFilename[MAX_QPATH]; char maleFilename[MAX_QPATH]; diff --git a/ctf/g_save.c b/ctf/g_save.c index b14696b..31656ad 100644 --- a/ctf/g_save.c +++ b/ctf/g_save.c @@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "../qcommon/quakeio.h" #include "g_local.h" field_t fields[] = { @@ -236,7 +237,7 @@ void InitGame (void) //========================================================= -void WriteField1 (FILE *f, field_t *field, byte *base) +void WriteField1 (QFile *f, field_t *field, byte *base) { void *p; int len; @@ -287,7 +288,7 @@ void WriteField1 (FILE *f, field_t *field, byte *base) } } -void WriteField2 (FILE *f, field_t *field, byte *base) +void WriteField2 (QFile *f, field_t *field, byte *base) { int len; void *p; @@ -300,7 +301,7 @@ void WriteField2 (FILE *f, field_t *field, byte *base) if ( *(char **)p ) { len = strlen(*(char **)p) + 1; - fwrite (*(char **)p, len, 1, f); + Qwrite (f, *(char **)p, len); } break; default: @@ -308,7 +309,7 @@ void WriteField2 (FILE *f, field_t *field, byte *base) } } -void ReadField (FILE *f, field_t *field, byte *base) +void ReadField (QFile *f, field_t *field, byte *base) { void *p; int len; @@ -331,7 +332,7 @@ void ReadField (FILE *f, field_t *field, byte *base) else { *(char **)p = gi.TagMalloc (len, TAG_LEVEL); - fread (*(char **)p, len, 1, f); + Qread (f, *(char **)p, len); } break; case F_GSTRING: @@ -341,7 +342,7 @@ void ReadField (FILE *f, field_t *field, byte *base) else { *(char **)p = gi.TagMalloc (len, TAG_GAME); - fread (*(char **)p, len, 1, f); + Qread (f, *(char **)p, len); } break; case F_EDICT: @@ -380,7 +381,7 @@ WriteClient All pointer variables (except function pointers) must be handled specially. ============== */ -void WriteClient (FILE *f, gclient_t *client) +void WriteClient (QFile *f, gclient_t *client) { field_t *field; gclient_t temp; @@ -395,7 +396,7 @@ void WriteClient (FILE *f, gclient_t *client) } // write the block - fwrite (&temp, sizeof(temp), 1, f); + Qwrite (f, &temp, sizeof(temp)); // now write any allocated data following the edict for (field=clientfields ; field->name ; field++) @@ -411,11 +412,11 @@ ReadClient All pointer variables (except function pointers) must be handled specially. ============== */ -void ReadClient (FILE *f, gclient_t *client) +void ReadClient (QFile *f, gclient_t *client) { field_t *field; - fread (client, sizeof(*client), 1, f); + Qread (f, client, sizeof(*client)); for (field=clientfields ; field->name ; field++) { @@ -439,59 +440,59 @@ last save position. */ void WriteGame (char *filename, qboolean autosave) { - FILE *f; + QFile *f; int i; char str[16]; if (!autosave) SaveClientData (); - f = fopen (filename, "wb"); + f = Qopen (filename, "wb"); if (!f) gi.error ("Couldn't open %s", filename); memset (str, 0, sizeof(str)); strcpy (str, __DATE__); - fwrite (str, sizeof(str), 1, f); + Qwrite (f, str, sizeof(str)); game.autosaved = autosave; - fwrite (&game, sizeof(game), 1, f); + Qwrite (f, &game, sizeof(game)); game.autosaved = false; for (i=0 ; iname ; field++) @@ -536,7 +537,7 @@ WriteLevelLocals All pointer variables (except function pointers) must be handled specially. ============== */ -void WriteLevelLocals (FILE *f) +void WriteLevelLocals (QFile *f) { field_t *field; level_locals_t temp; @@ -551,7 +552,7 @@ void WriteLevelLocals (FILE *f) } // write the block - fwrite (&temp, sizeof(temp), 1, f); + Qwrite (f, &temp, sizeof(temp)); // now write any allocated data following the edict for (field=levelfields ; field->name ; field++) @@ -568,11 +569,11 @@ ReadEdict All pointer variables (except function pointers) must be handled specially. ============== */ -void ReadEdict (FILE *f, edict_t *ent) +void ReadEdict (QFile *f, edict_t *ent) { field_t *field; - fread (ent, sizeof(*ent), 1, f); + Qread (f, ent, sizeof(*ent)); for (field=savefields ; field->name ; field++) { @@ -587,11 +588,11 @@ ReadLevelLocals All pointer variables (except function pointers) must be handled specially. ============== */ -void ReadLevelLocals (FILE *f) +void ReadLevelLocals (QFile *f) { field_t *field; - fread (&level, sizeof(level), 1, f); + Qread (f, &level, sizeof(level)); for (field=levelfields ; field->name ; field++) { @@ -609,20 +610,20 @@ void WriteLevel (char *filename) { int i; edict_t *ent; - FILE *f; + QFile *f; void *base; - f = fopen (filename, "wb"); + f = Qopen (filename, "wb"); if (!f) gi.error ("Couldn't open %s", filename); // write out edict size for checking i = sizeof(edict_t); - fwrite (&i, sizeof(i), 1, f); + Qwrite (f, &i, sizeof(i)); // write out a function pointer for checking base = (void *)InitGame; - fwrite (&base, sizeof(base), 1, f); + Qwrite (f, &base, sizeof(base)); // write out level_locals_t WriteLevelLocals (f); @@ -633,13 +634,13 @@ void WriteLevel (char *filename) ent = &g_edicts[i]; if (!ent->inuse) continue; - fwrite (&i, sizeof(i), 1, f); + Qwrite (f, &i, sizeof(i)); WriteEdict (f, ent); } i = -1; - fwrite (&i, sizeof(i), 1, f); + Qwrite (f, &i, sizeof(i)); - fclose (f); + Qclose (f); } @@ -662,12 +663,12 @@ No clients are connected yet. void ReadLevel (char *filename) { int entnum; - FILE *f; + QFile *f; int i; void *base; edict_t *ent; - f = fopen (filename, "rb"); + f = Qopen (filename, "rb"); if (!f) gi.error ("Couldn't open %s", filename); @@ -680,18 +681,18 @@ void ReadLevel (char *filename) globals.num_edicts = maxclients->value+1; // check edict size - fread (&i, sizeof(i), 1, f); + Qread (f, &i, sizeof(i)); if (i != sizeof(edict_t)) { - fclose (f); + Qclose (f); gi.error ("ReadLevel: mismatched edict size"); } // check function pointer base address - fread (&base, sizeof(base), 1, f); + Qread (f, &base, sizeof(base)); if (base != (void *)InitGame) { - fclose (f); + Qclose (f); gi.error ("ReadLevel: function pointers have moved"); } @@ -701,9 +702,9 @@ void ReadLevel (char *filename) // load all the entities while (1) { - if (fread (&entnum, sizeof(entnum), 1, f) != 1) + if (Qread (f, &entnum, sizeof(entnum)) != sizeof(entnum)) { - fclose (f); + Qclose (f); gi.error ("ReadLevel: failed to read entnum"); } if (entnum == -1) @@ -719,7 +720,7 @@ void ReadLevel (char *filename) gi.linkentity (ent); } - fclose (f); + Qclose (f); // mark all clients as unconnected for (i=0 ; ivalue ; i++) diff --git a/ctf/g_svcmds.c b/ctf/g_svcmds.c index 6868633..b40efdc 100644 --- a/ctf/g_svcmds.c +++ b/ctf/g_svcmds.c @@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "../qcommon/quakeio.h" #include "g_local.h" @@ -237,7 +238,7 @@ SV_WriteIP_f */ void SVCmd_WriteIP_f (void) { - FILE *f; + QFile *f; char name[MAX_OSPATH]; byte b[4]; int i; @@ -252,22 +253,22 @@ void SVCmd_WriteIP_f (void) gi.cprintf (NULL, PRINT_HIGH, "Writing %s.\n", name); - f = fopen (name, "wb"); + f = Qopen (name, "wb"); if (!f) { gi.cprintf (NULL, PRINT_HIGH, "Couldn't open %s\n", name); return; } - fprintf(f, "set filterban %d\n", (int)filterban->value); + Qprintf(f, "set filterban %d\n", (int)filterban->value); for (i=0 ; iname ; field++) @@ -434,11 +435,11 @@ ReadClient All pointer variables (except function pointers) must be handled specially. ============== */ -void ReadClient (FILE *f, gclient_t *client) +void ReadClient (QFile *f, gclient_t *client) { field_t *field; - fread (client, sizeof(*client), 1, f); + Qread (f, client, sizeof(*client)); for (field=clientfields ; field->name ; field++) { @@ -462,59 +463,59 @@ last save position. */ void WriteGame (char *filename, qboolean autosave) { - FILE *f; + QFile *f; int i; char str[16]; if (!autosave) SaveClientData (); - f = fopen (filename, "wb"); + f = Qopen (filename, "wb"); if (!f) gi.error ("Couldn't open %s", filename); memset (str, 0, sizeof(str)); strcpy (str, __DATE__); - fwrite (str, sizeof(str), 1, f); + Qwrite (f, str, sizeof(str)); game.autosaved = autosave; - fwrite (&game, sizeof(game), 1, f); + Qwrite (f, &game, sizeof(game)); game.autosaved = false; for (i=0 ; iname ; field++) @@ -559,7 +560,7 @@ WriteLevelLocals All pointer variables (except function pointers) must be handled specially. ============== */ -void WriteLevelLocals (FILE *f) +void WriteLevelLocals (QFile *f) { field_t *field; level_locals_t temp; @@ -574,7 +575,7 @@ void WriteLevelLocals (FILE *f) } // write the block - fwrite (&temp, sizeof(temp), 1, f); + Qwrite (f, &temp, sizeof(temp)); // now write any allocated data following the edict for (field=levelfields ; field->name ; field++) @@ -591,11 +592,11 @@ ReadEdict All pointer variables (except function pointers) must be handled specially. ============== */ -void ReadEdict (FILE *f, edict_t *ent) +void ReadEdict (QFile *f, edict_t *ent) { field_t *field; - fread (ent, sizeof(*ent), 1, f); + Qread (f, ent, sizeof(*ent)); for (field=fields ; field->name ; field++) { @@ -610,11 +611,11 @@ ReadLevelLocals All pointer variables (except function pointers) must be handled specially. ============== */ -void ReadLevelLocals (FILE *f) +void ReadLevelLocals (QFile *f) { field_t *field; - fread (&level, sizeof(level), 1, f); + Qread (f, &level, sizeof(level)); for (field=levelfields ; field->name ; field++) { @@ -632,20 +633,20 @@ void WriteLevel (char *filename) { int i; edict_t *ent; - FILE *f; + QFile *f; void *base; - f = fopen (filename, "wb"); + f = Qopen (filename, "wb"); if (!f) gi.error ("Couldn't open %s", filename); // write out edict size for checking i = sizeof(edict_t); - fwrite (&i, sizeof(i), 1, f); + Qwrite (f, &i, sizeof(i)); // write out a function pointer for checking base = (void *)InitGame; - fwrite (&base, sizeof(base), 1, f); + Qwrite (f, &base, sizeof(base)); // write out level_locals_t WriteLevelLocals (f); @@ -656,13 +657,13 @@ void WriteLevel (char *filename) ent = &g_edicts[i]; if (!ent->inuse) continue; - fwrite (&i, sizeof(i), 1, f); + Qwrite (f, &i, sizeof(i)); WriteEdict (f, ent); } i = -1; - fwrite (&i, sizeof(i), 1, f); + Qwrite (f, &i, sizeof(i)); - fclose (f); + Qclose (f); } @@ -685,12 +686,12 @@ No clients are connected yet. void ReadLevel (char *filename) { int entnum; - FILE *f; + QFile *f; int i; void *base; edict_t *ent; - f = fopen (filename, "rb"); + f = Qopen (filename, "rb"); if (!f) gi.error ("Couldn't open %s", filename); @@ -703,19 +704,19 @@ void ReadLevel (char *filename) globals.num_edicts = maxclients->value+1; // check edict size - fread (&i, sizeof(i), 1, f); + Qread (f, &i, sizeof(i)); if (i != sizeof(edict_t)) { - fclose (f); + Qclose (f); gi.error ("ReadLevel: mismatched edict size"); } // check function pointer base address - fread (&base, sizeof(base), 1, f); + Qread (f, &base, sizeof(base)); #ifdef _WIN32 if (base != (void *)InitGame) { - fclose (f); + Qclose (f); gi.error ("ReadLevel: function pointers have moved"); } #else @@ -728,9 +729,9 @@ void ReadLevel (char *filename) // load all the entities while (1) { - if (fread (&entnum, sizeof(entnum), 1, f) != 1) + if (Qread (f, &entnum, sizeof(entnum)) != sizeof(entnum)) { - fclose (f); + Qclose (f); gi.error ("ReadLevel: failed to read entnum"); } if (entnum == -1) @@ -746,7 +747,7 @@ void ReadLevel (char *filename) gi.linkentity (ent); } - fclose (f); + Qclose (f); // mark all clients as unconnected for (i=0 ; ivalue ; i++) diff --git a/game/g_svcmds.c b/game/g_svcmds.c index 6868633..56abb02 100644 --- a/game/g_svcmds.c +++ b/game/g_svcmds.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - +#include "../qcommon/quakeio.h" #include "g_local.h" @@ -237,7 +237,7 @@ SV_WriteIP_f */ void SVCmd_WriteIP_f (void) { - FILE *f; + QFile *f; char name[MAX_OSPATH]; byte b[4]; int i; @@ -252,22 +252,22 @@ void SVCmd_WriteIP_f (void) gi.cprintf (NULL, PRINT_HIGH, "Writing %s.\n", name); - f = fopen (name, "wb"); + f = Qopen (name, "wb"); if (!f) { gi.cprintf (NULL, PRINT_HIGH, "Couldn't open %s\n", name); return; } - fprintf(f, "set filterban %d\n", (int)filterban->value); + Qprintf(f, "set filterban %d\n", (int)filterban->value); for (i=0 ; ivalue) return; - fputs(string, stdout); + Qputs(string, stdout); } void Sys_Printf (char *fmt, ...) @@ -321,7 +321,7 @@ int main (int argc, char **argv) void Sys_CopyProtect(void) { - FILE *mnt; + QFile *mnt; struct mntent *ent; char path[MAX_OSPATH]; struct stat st; diff --git a/irix/vid_so.c b/irix/vid_so.c index 10280e9..0b1d4ed 100644 --- a/irix/vid_so.c +++ b/irix/vid_so.c @@ -215,7 +215,7 @@ qboolean VID_LoadRefresh( char *name ) char fn[MAX_OSPATH]; struct stat st; extern uid_t saved_euid; - FILE *fp; + QFile *fp; char *path; char curpath[MAX_OSPATH]; diff --git a/linux/glw_linux.h b/linux/glw_linux.h index cd04b0e..bf73353 100644 --- a/linux/glw_linux.h +++ b/linux/glw_linux.h @@ -28,7 +28,7 @@ typedef struct { void *OpenGLLib; // instance of OpenGL library - FILE *log_fp; + QFile *log_fp; } glwstate_t; extern glwstate_t glw_state; diff --git a/linux/qgl_linux.c b/linux/qgl_linux.c index e177aa7..e71fb17 100644 --- a/linux/qgl_linux.c +++ b/linux/qgl_linux.c @@ -743,179 +743,179 @@ static void ( APIENTRY * dllViewport )(GLint x, GLint y, GLsizei width, GLsizei static void APIENTRY logAccum(GLenum op, GLfloat value) { - fprintf( glw_state.log_fp, "glAccum\n" ); + Qprintf( glw_state.log_fp, "glAccum\n" ); dllAccum( op, value ); } static void APIENTRY logAlphaFunc(GLenum func, GLclampf ref) { - fprintf( glw_state.log_fp, "glAlphaFunc( 0x%x, %f )\n", func, ref ); + Qprintf( glw_state.log_fp, "glAlphaFunc( 0x%x, %f )\n", func, ref ); dllAlphaFunc( func, ref ); } static GLboolean APIENTRY logAreTexturesResident(GLsizei n, const GLuint *textures, GLboolean *residences) { - fprintf( glw_state.log_fp, "glAreTexturesResident\n" ); + Qprintf( glw_state.log_fp, "glAreTexturesResident\n" ); return dllAreTexturesResident( n, textures, residences ); } static void APIENTRY logArrayElement(GLint i) { - fprintf( glw_state.log_fp, "glArrayElement\n" ); + Qprintf( glw_state.log_fp, "glArrayElement\n" ); dllArrayElement( i ); } static void APIENTRY logBegin(GLenum mode) { - fprintf( glw_state.log_fp, "glBegin( 0x%x )\n", mode ); + Qprintf( glw_state.log_fp, "glBegin( 0x%x )\n", mode ); dllBegin( mode ); } static void APIENTRY logBindTexture(GLenum target, GLuint texture) { - fprintf( glw_state.log_fp, "glBindTexture( 0x%x, %u )\n", target, texture ); + Qprintf( glw_state.log_fp, "glBindTexture( 0x%x, %u )\n", target, texture ); dllBindTexture( target, texture ); } static void APIENTRY logBitmap(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap) { - fprintf( glw_state.log_fp, "glBitmap\n" ); + Qprintf( glw_state.log_fp, "glBitmap\n" ); dllBitmap( width, height, xorig, yorig, xmove, ymove, bitmap ); } static void APIENTRY logBlendFunc(GLenum sfactor, GLenum dfactor) { - fprintf( glw_state.log_fp, "glBlendFunc( 0x%x, 0x%x )\n", sfactor, dfactor ); + Qprintf( glw_state.log_fp, "glBlendFunc( 0x%x, 0x%x )\n", sfactor, dfactor ); dllBlendFunc( sfactor, dfactor ); } static void APIENTRY logCallList(GLuint list) { - fprintf( glw_state.log_fp, "glCallList( %u )\n", list ); + Qprintf( glw_state.log_fp, "glCallList( %u )\n", list ); dllCallList( list ); } static void APIENTRY logCallLists(GLsizei n, GLenum type, const void *lists) { - fprintf( glw_state.log_fp, "glCallLists\n" ); + Qprintf( glw_state.log_fp, "glCallLists\n" ); dllCallLists( n, type, lists ); } static void APIENTRY logClear(GLbitfield mask) { - fprintf( glw_state.log_fp, "glClear\n" ); + Qprintf( glw_state.log_fp, "glClear\n" ); dllClear( mask ); } static void APIENTRY logClearAccum(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { - fprintf( glw_state.log_fp, "glClearAccum\n" ); + Qprintf( glw_state.log_fp, "glClearAccum\n" ); dllClearAccum( red, green, blue, alpha ); } static void APIENTRY logClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) { - fprintf( glw_state.log_fp, "glClearColor\n" ); + Qprintf( glw_state.log_fp, "glClearColor\n" ); dllClearColor( red, green, blue, alpha ); } static void APIENTRY logClearDepth(GLclampd depth) { - fprintf( glw_state.log_fp, "glClearDepth\n" ); + Qprintf( glw_state.log_fp, "glClearDepth\n" ); dllClearDepth( depth ); } static void APIENTRY logClearIndex(GLfloat c) { - fprintf( glw_state.log_fp, "glClearIndex\n" ); + Qprintf( glw_state.log_fp, "glClearIndex\n" ); dllClearIndex( c ); } static void APIENTRY logClearStencil(GLint s) { - fprintf( glw_state.log_fp, "glClearStencil\n" ); + Qprintf( glw_state.log_fp, "glClearStencil\n" ); dllClearStencil( s ); } static void APIENTRY logClipPlane(GLenum plane, const GLdouble *equation) { - fprintf( glw_state.log_fp, "glClipPlane\n" ); + Qprintf( glw_state.log_fp, "glClipPlane\n" ); dllClipPlane( plane, equation ); } static void APIENTRY logColor3b(GLbyte red, GLbyte green, GLbyte blue) { - fprintf( glw_state.log_fp, "glColor3b\n" ); + Qprintf( glw_state.log_fp, "glColor3b\n" ); dllColor3b( red, green, blue ); } static void APIENTRY logColor3bv(const GLbyte *v) { - fprintf( glw_state.log_fp, "glColor3bv\n" ); + Qprintf( glw_state.log_fp, "glColor3bv\n" ); dllColor3bv( v ); } static void APIENTRY logColor3d(GLdouble red, GLdouble green, GLdouble blue) { - fprintf( glw_state.log_fp, "glColor3d\n" ); + Qprintf( glw_state.log_fp, "glColor3d\n" ); dllColor3d( red, green, blue ); } static void APIENTRY logColor3dv(const GLdouble *v) { - fprintf( glw_state.log_fp, "glColor3dv\n" ); + Qprintf( glw_state.log_fp, "glColor3dv\n" ); dllColor3dv( v ); } static void APIENTRY logColor3f(GLfloat red, GLfloat green, GLfloat blue) { - fprintf( glw_state.log_fp, "glColor3f\n" ); + Qprintf( glw_state.log_fp, "glColor3f\n" ); dllColor3f( red, green, blue ); } static void APIENTRY logColor3fv(const GLfloat *v) { - fprintf( glw_state.log_fp, "glColor3fv\n" ); + Qprintf( glw_state.log_fp, "glColor3fv\n" ); dllColor3fv( v ); } static void APIENTRY logColor3i(GLint red, GLint green, GLint blue) { - fprintf( glw_state.log_fp, "glColor3i\n" ); + Qprintf( glw_state.log_fp, "glColor3i\n" ); dllColor3i( red, green, blue ); } static void APIENTRY logColor3iv(const GLint *v) { - fprintf( glw_state.log_fp, "glColor3iv\n" ); + Qprintf( glw_state.log_fp, "glColor3iv\n" ); dllColor3iv( v ); } static void APIENTRY logColor3s(GLshort red, GLshort green, GLshort blue) { - fprintf( glw_state.log_fp, "glColor3s\n" ); + Qprintf( glw_state.log_fp, "glColor3s\n" ); dllColor3s( red, green, blue ); } static void APIENTRY logColor3sv(const GLshort *v) { - fprintf( glw_state.log_fp, "glColor3sv\n" ); + Qprintf( glw_state.log_fp, "glColor3sv\n" ); dllColor3sv( v ); } static void APIENTRY logColor3ub(GLubyte red, GLubyte green, GLubyte blue) { - fprintf( glw_state.log_fp, "glColor3ub\n" ); + Qprintf( glw_state.log_fp, "glColor3ub\n" ); dllColor3ub( red, green, blue ); } static void APIENTRY logColor3ubv(const GLubyte *v) { - fprintf( glw_state.log_fp, "glColor3ubv\n" ); + Qprintf( glw_state.log_fp, "glColor3ubv\n" ); dllColor3ubv( v ); } -#define SIG( x ) fprintf( glw_state.log_fp, x "\n" ) +#define SIG( x ) Qprintf( glw_state.log_fp, x "\n" ) static void APIENTRY logColor3ui(GLuint red, GLuint green, GLuint blue) { @@ -965,12 +965,12 @@ static void APIENTRY logColor4dv(const GLdouble *v) } static void APIENTRY logColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { - fprintf( glw_state.log_fp, "glColor4f( %f,%f,%f,%f )\n", red, green, blue, alpha ); + Qprintf( glw_state.log_fp, "glColor4f( %f,%f,%f,%f )\n", red, green, blue, alpha ); dllColor4f( red, green, blue, alpha ); } static void APIENTRY logColor4fv(const GLfloat *v) { - fprintf( glw_state.log_fp, "glColor4fv( %f,%f,%f,%f )\n", v[0], v[1], v[2], v[3] ); + Qprintf( glw_state.log_fp, "glColor4fv( %f,%f,%f,%f )\n", v[0], v[1], v[2], v[3] ); dllColor4fv( v ); } static void APIENTRY logColor4i(GLint red, GLint green, GLint blue, GLint alpha) @@ -1108,7 +1108,7 @@ static void APIENTRY logDepthRange(GLclampd zNear, GLclampd zFar) static void APIENTRY logDisable(GLenum cap) { - fprintf( glw_state.log_fp, "glDisable( 0x%x )\n", cap ); + Qprintf( glw_state.log_fp, "glDisable( 0x%x )\n", cap ); dllDisable( cap ); } @@ -1162,7 +1162,7 @@ static void APIENTRY logEdgeFlagv(const GLboolean *flag) static void APIENTRY logEnable(GLenum cap) { - fprintf( glw_state.log_fp, "glEnable( 0x%x )\n", cap ); + Qprintf( glw_state.log_fp, "glEnable( 0x%x )\n", cap ); dllEnable( cap ); } @@ -1490,7 +1490,7 @@ static void APIENTRY logGetTexParameteriv(GLenum target, GLenum pname, GLint *pa static void APIENTRY logHint(GLenum target, GLenum mode) { - fprintf( glw_state.log_fp, "glHint( 0x%x, 0x%x )\n", target, mode ); + Qprintf( glw_state.log_fp, "glHint( 0x%x, 0x%x )\n", target, mode ); dllHint( target, mode ); } @@ -1909,7 +1909,7 @@ static void APIENTRY logPointSize(GLfloat size) static void APIENTRY logPolygonMode(GLenum face, GLenum mode) { - fprintf( glw_state.log_fp, "glPolygonMode( 0x%x, 0x%x )\n", face, mode ); + Qprintf( glw_state.log_fp, "glPolygonMode( 0x%x, 0x%x )\n", face, mode ); dllPolygonMode( face, mode ); } @@ -2389,7 +2389,7 @@ static void APIENTRY logTexCoordPointer(GLint size, GLenum type, GLsizei stride, static void APIENTRY logTexEnvf(GLenum target, GLenum pname, GLfloat param) { - fprintf( glw_state.log_fp, "glTexEnvf( 0x%x, 0x%x, %f )\n", target, pname, param ); + Qprintf( glw_state.log_fp, "glTexEnvf( 0x%x, 0x%x, %f )\n", target, pname, param ); dllTexEnvf( target, pname, param ); } @@ -2401,7 +2401,7 @@ static void APIENTRY logTexEnvfv(GLenum target, GLenum pname, const GLfloat *par static void APIENTRY logTexEnvi(GLenum target, GLenum pname, GLint param) { - fprintf( glw_state.log_fp, "glTexEnvi( 0x%x, 0x%x, 0x%x )\n", target, pname, param ); + Qprintf( glw_state.log_fp, "glTexEnvi( 0x%x, 0x%x, 0x%x )\n", target, pname, param ); dllTexEnvi( target, pname, param ); } static void APIENTRY logTexEnviv(GLenum target, GLenum pname, const GLint *params) @@ -2455,7 +2455,7 @@ static void APIENTRY logTexImage2D(GLenum target, GLint level, GLint internalfor static void APIENTRY logTexParameterf(GLenum target, GLenum pname, GLfloat param) { - fprintf( glw_state.log_fp, "glTexParameterf( 0x%x, 0x%x, %f )\n", target, pname, param ); + Qprintf( glw_state.log_fp, "glTexParameterf( 0x%x, 0x%x, %f )\n", target, pname, param ); dllTexParameterf( target, pname, param ); } @@ -2466,7 +2466,7 @@ static void APIENTRY logTexParameterfv(GLenum target, GLenum pname, const GLfloa } static void APIENTRY logTexParameteri(GLenum target, GLenum pname, GLint param) { - fprintf( glw_state.log_fp, "glTexParameteri( 0x%x, 0x%x, 0x%x )\n", target, pname, param ); + Qprintf( glw_state.log_fp, "glTexParameteri( 0x%x, 0x%x, 0x%x )\n", target, pname, param ); dllTexParameteri( target, pname, param ); } static void APIENTRY logTexParameteriv(GLenum target, GLenum pname, const GLint *params) @@ -3034,19 +3034,19 @@ qboolean QGL_Init( const char *dllname ) char fn[MAX_OSPATH]; char *path; #if 0 - FILE *fp; + QFile *fp; #endif // ri.Con_Printf(PRINT_ALL, "QGL_Init: Can't load %s from /etc/ld.so.conf: %s\n", // dllname, dlerror()); #if 0 - if ((fp = fopen(so_file, "r")) == NULL) { + if ((fp = Qopen(so_file, "r")) == NULL) { ri.Con_Printf(PRINT_ALL, "QGL_Init(\"%s\") failed: can't open %s\n", dllname, so_file); return false; } - fgets(fn, sizeof(fn), fp); - fclose(fp); + Qgets(fn, sizeof(fn), fp); + Qclose(fp); while (*fn && isspace(fn[strlen(fn) - 1])) fn[strlen(fn) - 1] = 0; #endif @@ -3442,9 +3442,9 @@ void GLimp_EnableLogging( qboolean enable ) asctime( newtime ); Com_sprintf( buffer, sizeof(buffer), "%s/gl.log", ri.FS_Gamedir() ); - glw_state.log_fp = fopen( buffer, "wt" ); + glw_state.log_fp = Qopen( buffer, "wt" ); - fprintf( glw_state.log_fp, "%s\n", asctime( newtime ) ); + Qprintf( glw_state.log_fp, "%s\n", asctime( newtime ) ); } qglAccum = logAccum; @@ -4128,7 +4128,7 @@ void GLimp_EnableLogging( qboolean enable ) void GLimp_LogNewFrame( void ) { - fprintf( glw_state.log_fp, "*** R_BeginFrame ***\n" ); + Qprintf( glw_state.log_fp, "*** R_BeginFrame ***\n" ); } diff --git a/linux/sys_linux.c b/linux/sys_linux.c index 3279609..0f75a84 100644 --- a/linux/sys_linux.c +++ b/linux/sys_linux.c @@ -324,7 +324,7 @@ int main (int argc, char **argv) #if 0 void Sys_CopyProtect(void) { - FILE *mnt; + QFile *mnt; struct mntent *ent; char path[MAX_OSPATH]; struct stat st; diff --git a/linux/vid_so.c b/linux/vid_so.c index abf0cc9..7ecd484 100644 --- a/linux/vid_so.c +++ b/linux/vid_so.c @@ -206,7 +206,7 @@ qboolean VID_LoadRefresh( char *name ) struct stat st; extern uid_t saved_euid; #if 0 - FILE *fp; + QFile *fp; #endif if ( reflib_active ) @@ -227,12 +227,12 @@ qboolean VID_LoadRefresh( char *name ) seteuid(saved_euid); #if 0 - if ((fp = fopen(so_file, "r")) == NULL) { + if ((fp = Qopen(so_file, "r")) == NULL) { Com_Printf( "LoadLibrary(\"%s\") failed: can't open %s (required for location of ref libraries)\n", name, so_file); return false; } - fgets(fn, sizeof(fn), fp); - fclose(fp); + Qgets(fn, sizeof(fn), fp); + Qclose(fp); while (*fn && isspace(fn[strlen(fn) - 1])) fn[strlen(fn) - 1] = 0; diff --git a/qcommon/cmodel.c b/qcommon/cmodel.c index 7fc6879..fc699ae 100644 --- a/qcommon/cmodel.c +++ b/qcommon/cmodel.c @@ -1718,9 +1718,9 @@ CM_WritePortalState Writes the portal state to a savegame file =================== */ -void CM_WritePortalState (FILE *f) +void CM_WritePortalState (QFile *f) { - fwrite (portalopen, sizeof(portalopen), 1, f); + Qwrite (f, portalopen, sizeof(portalopen)); } /* @@ -1731,7 +1731,7 @@ Reads the portal state from a savegame file and recalculates the area connections =================== */ -void CM_ReadPortalState (FILE *f) +void CM_ReadPortalState (QFile *f) { FS_Read (portalopen, sizeof(portalopen), f); FloodAreaConnections (); diff --git a/qcommon/common.c b/qcommon/common.c index ef1a661..63ea45c 100644 --- a/qcommon/common.c +++ b/qcommon/common.c @@ -34,7 +34,7 @@ int realtime; jmp_buf abortframe; // an ERR_DROP occured, exit the entire frame -FILE *log_stats_file; +QFile *log_stats_file; cvar_t *host_speeds; cvar_t *log_stats; @@ -45,7 +45,7 @@ cvar_t *logfile_active; // 1 = buffer log, 2 = flush after each print cvar_t *showtrace; cvar_t *dedicated; -FILE *logfile; +QFile *logfile; int server_state; @@ -132,14 +132,14 @@ void Com_Printf (char *fmt, ...) { Com_sprintf (name, sizeof(name), "%s/qconsole.log", FS_Gamedir ()); if (logfile_active->value > 2) - logfile = fopen (name, "a"); + logfile = Qopen (name, "a"); else - logfile = fopen (name, "w"); + logfile = Qopen (name, "w"); } if (logfile) - fprintf (logfile, "%s", msg); + Qprintf (logfile, "%s", msg); if (logfile_active->value > 1) - fflush (logfile); // force it to save every time + Qflush (logfile); // force it to save every time } } @@ -211,7 +211,7 @@ void Com_Error (int code, char *fmt, ...) if (logfile) { - fclose (logfile); + Qclose (logfile); logfile = NULL; } @@ -234,7 +234,7 @@ void Com_Quit (void) if (logfile) { - fclose (logfile); + Qclose (logfile); logfile = NULL; } @@ -1506,18 +1506,18 @@ void Qcommon_Frame (volatile int msec) { if ( log_stats_file ) { - fclose( log_stats_file ); + Qclose( log_stats_file ); log_stats_file = 0; } - log_stats_file = fopen( "stats.log", "w" ); + log_stats_file = Qopen( "stats.log", "w" ); if ( log_stats_file ) - fprintf( log_stats_file, "entities,dlights,parts,frame time\n" ); + Qprintf( log_stats_file, "entities,dlights,parts,frame time\n" ); } else { if ( log_stats_file ) { - fclose( log_stats_file ); + Qclose( log_stats_file ); log_stats_file = 0; } } diff --git a/qcommon/cvar.c b/qcommon/cvar.c index 29a12df..43d28de 100644 --- a/qcommon/cvar.c +++ b/qcommon/cvar.c @@ -430,18 +430,18 @@ void Cvar_WriteVariables (char *path) { cvar_t *var; char buffer[1024]; - FILE *f; + QFile *f; - f = fopen (path, "a"); + f = Qopen (path, "a"); for (var = cvar_vars ; var ; var = var->next) { if (var->flags & CVAR_ARCHIVE) { Com_sprintf (buffer, sizeof(buffer), "set %s \"%s\"\n", var->name, var->string); - fprintf (f, "%s", buffer); + Qprintf (f, "%s", buffer); } } - fclose (f); + Qclose (f); } /* diff --git a/qcommon/files.c b/qcommon/files.c index 1bcfdc2..18b3e5e 100644 --- a/qcommon/files.c +++ b/qcommon/files.c @@ -53,7 +53,7 @@ typedef struct typedef struct pack_s { char filename[MAX_OSPATH]; - FILE *handle; + QFile *handle; int numfiles; packfile_t *files; } pack_t; @@ -101,15 +101,15 @@ The "game directory" is the first tree on the search path and directory that all FS_filelength ================ */ -int FS_filelength (FILE *f) +int FS_filelength (QFile *f) { int pos; int end; - pos = ftell (f); - fseek (f, 0, SEEK_END); - end = ftell (f); - fseek (f, pos, SEEK_SET); + pos = Qtell (f); + Qseek (f, 0, SEEK_END); + end = Qtell (f); + Qseek (f, pos, SEEK_SET); return end; } @@ -142,13 +142,13 @@ void FS_CreatePath (char *path) ============== FS_FCloseFile -For some reason, other dll's can't just cal fclose() +For some reason, other dll's can't just cal Qclose() on files returned by FS_FOpenFile... ============== */ -void FS_FCloseFile (FILE *f) +void FS_FCloseFile (QFile *f) { - fclose (f); + Qclose (f); } @@ -196,14 +196,14 @@ int Developer_searchpath (int who) FS_FOpenFile Finds the file in the search path. -returns filesize and an open FILE * +returns filesize and an open QFile * Used for streaming data out of either a pak file or a seperate file. =========== */ int file_from_pak = 0; #ifndef NO_ADDONS -int FS_FOpenFile (char *filename, FILE **file) +int FS_FOpenFile (char *filename, QFile **file) { searchpath_t *search; char netpath[MAX_OSPATH]; @@ -219,7 +219,7 @@ int FS_FOpenFile (char *filename, FILE **file) if (!strncmp (filename, link->from, link->fromlength)) { Com_sprintf (netpath, sizeof(netpath), "%s%s",link->to, filename+link->fromlength); - *file = fopen (netpath, "rb"); + *file = Qopen (netpath, "rb"); if (*file) { Com_DPrintf ("link file: %s\n",netpath); @@ -245,10 +245,10 @@ int FS_FOpenFile (char *filename, FILE **file) file_from_pak = 1; Com_DPrintf ("PackFile: %s : %s\n",pak->filename, filename); // open a new file on the pakfile - *file = fopen (pak->filename, "rb"); + *file = Qopen (pak->filename, "rb"); if (!*file) Com_Error (ERR_FATAL, "Couldn't reopen %s", pak->filename); - fseek (*file, pak->files[i].filepos, SEEK_SET); + Qseek (*file, pak->files[i].filepos, SEEK_SET); return pak->files[i].filelen; } } @@ -258,7 +258,7 @@ int FS_FOpenFile (char *filename, FILE **file) Com_sprintf (netpath, sizeof(netpath), "%s/%s",search->filename, filename); - *file = fopen (netpath, "rb"); + *file = Qopen (netpath, "rb"); if (!*file) continue; @@ -279,7 +279,7 @@ int FS_FOpenFile (char *filename, FILE **file) // this is just for demos to prevent add on hacking -int FS_FOpenFile (char *filename, FILE **file) +int FS_FOpenFile (char *filename, QFile **file) { searchpath_t *search; char netpath[MAX_OSPATH]; @@ -293,7 +293,7 @@ int FS_FOpenFile (char *filename, FILE **file) { Com_sprintf (netpath, sizeof(netpath), "%s/%s",FS_Gamedir(), filename); - *file = fopen (netpath, "rb"); + *file = Qopen (netpath, "rb"); if (!*file) return -1; @@ -318,10 +318,10 @@ int FS_FOpenFile (char *filename, FILE **file) file_from_pak = 1; Com_DPrintf ("PackFile: %s : %s\n",pak->filename, filename); // open a new file on the pakfile - *file = fopen (pak->filename, "rb"); + *file = Qopen (pak->filename, "rb"); if (!*file) Com_Error (ERR_FATAL, "Couldn't reopen %s", pak->filename); - fseek (*file, pak->files[i].filepos, SEEK_SET); + Qseek (*file, pak->files[i].filepos, SEEK_SET); return pak->files[i].filelen; } @@ -343,7 +343,7 @@ Properly handles partial reads */ void CDAudio_Stop(void); #define MAX_READ 0x10000 // read in blocks of 64k -void FS_Read (void *buffer, int len, FILE *f) +void FS_Read (void *buffer, int len, QFile *f) { int block, remaining; int read; @@ -360,7 +360,7 @@ void FS_Read (void *buffer, int len, FILE *f) block = remaining; if (block > MAX_READ) block = MAX_READ; - read = fread (buf, 1, block, f); + read = Qread (f, buf, block); if (read == 0) { // we might have been trying to read from a CD @@ -393,7 +393,7 @@ a null buffer will just return the file length without loading */ int FS_LoadFile (char *path, void **buffer) { - FILE *h; + QFile *h; byte *buf; int len; @@ -410,7 +410,7 @@ int FS_LoadFile (char *path, void **buffer) if (!buffer) { - fclose (h); + Qclose (h); return len; } @@ -419,7 +419,7 @@ int FS_LoadFile (char *path, void **buffer) FS_Read (buf, len, h); - fclose (h); + Qclose (h); return len; } @@ -452,15 +452,15 @@ pack_t *FS_LoadPackFile (char *packfile) packfile_t *newfiles; int numpackfiles; pack_t *pack; - FILE *packhandle; + QFile *packhandle; dpackfile_t info[MAX_FILES_IN_PACK]; unsigned checksum; - packhandle = fopen(packfile, "rb"); + packhandle = Qopen(packfile, "rb"); if (!packhandle) return NULL; - fread (&header, 1, sizeof(header), packhandle); + Qread (packhandle, &header, sizeof(header)); if (LittleLong(header.ident) != IDPAKHEADER) Com_Error (ERR_FATAL, "%s is not a packfile", packfile); header.dirofs = LittleLong (header.dirofs); @@ -473,8 +473,8 @@ pack_t *FS_LoadPackFile (char *packfile) newfiles = Z_Malloc (numpackfiles * sizeof(packfile_t)); - fseek (packhandle, header.dirofs, SEEK_SET); - fread (info, 1, header.dirlen, packhandle); + Qseek (packhandle, header.dirofs, SEEK_SET); + Qread (packhandle, info, header.dirlen); // crc the directory to check for modifications checksum = Com_BlockChecksum ((void *)info, header.dirlen); @@ -630,7 +630,7 @@ void FS_SetGamedir (char *dir) { if (fs_searchpaths->pack) { - fclose (fs_searchpaths->pack->handle); + Qclose (fs_searchpaths->pack->handle); Z_Free (fs_searchpaths->pack->files); Z_Free (fs_searchpaths->pack); } diff --git a/qcommon/qcommon.h b/qcommon/qcommon.h index 13eb26f..2d301ac 100644 --- a/qcommon/qcommon.h +++ b/qcommon/qcommon.h @@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // qcommon.h -- definitions common between client and server, but not game.dll #include "../game/q_shared.h" - +#include "../qcommon/quakeio.h" #define VERSION 3.21 @@ -667,8 +667,8 @@ qboolean CM_AreasConnected (int area1, int area2); int CM_WriteAreaBits (byte *buffer, int area); qboolean CM_HeadnodeVisible (int headnode, byte *visbits); -void CM_WritePortalState (FILE *f); -void CM_ReadPortalState (FILE *f); +void CM_WritePortalState (QFile *f); +void CM_ReadPortalState (QFile *f); /* ============================================================== @@ -698,15 +698,15 @@ char *FS_Gamedir (void); char *FS_NextPath (char *prevpath); void FS_ExecAutoexec (void); -int FS_FOpenFile (char *filename, FILE **file); -void FS_FCloseFile (FILE *f); +int FS_FOpenFile (char *filename, QFile **file); +void FS_FCloseFile (QFile *f); // note: this can't be called from another DLL, due to MS libc issues int FS_LoadFile (char *path, void **buffer); // a null buffer will just return the file length without loading // a -1 length is not present -void FS_Read (void *buffer, int len, FILE *f); +void FS_Read (void *buffer, int len, QFile *f); // properly handles partial reads void FS_FreeFile (void *buffer); @@ -755,7 +755,7 @@ extern cvar_t *dedicated; extern cvar_t *host_speeds; extern cvar_t *log_stats; -extern FILE *log_stats_file; +extern QFile *log_stats_file; // host_speeds times extern int time_before_game; diff --git a/qcommon/quakeio.c b/qcommon/quakeio.c new file mode 100644 index 0000000..b1a4ea5 --- /dev/null +++ b/qcommon/quakeio.c @@ -0,0 +1,432 @@ +/* + quakeio.c + + (description) + + Copyright (C) 1996-1997 Id Software, Inc. + Copyright (C) 1999,2000 contributors of the QuakeForge project + Please see the file "AUTHORS" for a list of contributors + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + +*/ +static const char rcsid[] = + "$Id$"; + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#define HAVE_ZLIB //FIXME remove when autoconfiscated +#define HAVE_STRING_H //FIXME remove when autoconfiscated +#define HAVE_UNISTD_H //FIXME remove when autoconfiscated +#ifdef HAVE_ZLIB +# include +#endif +#ifdef HAVE_STRING_H +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif +#ifdef WIN32 +# include +# include +#else +# include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif +#ifdef _MSC_VER +# define _POSIX_ +#endif + +#include +#include +#include + +#include "quakeio.h" + +#ifdef WIN32 +# ifndef __BORLANDC__ +# define setmode _setmode +# define O_BINARY _O_BINARY +# endif +#endif + +struct QFile_s { + FILE *file; +#ifdef HAVE_ZLIB + gzFile *gzfile; +#endif +}; + + +void +Qexpand_squiggle (const char *path, char *dest) +{ + char *home; + +#ifndef _WIN32 + struct passwd *pwd_ent; +#endif + + if (strncmp (path, "~/", 2) != 0) { + strcpy (dest, path); + return; + } + +#ifdef _WIN32 + // LordHavoc: first check HOME to duplicate previous version behavior + // (also handy if someone wants it elsewhere than their windows directory) + home = getenv ("HOME"); + if (!home || !home[0]) + home = getenv ("WINDIR"); +#else + if ((pwd_ent = getpwuid (getuid ()))) { + home = pwd_ent->pw_dir; + } else + home = getenv ("HOME"); +#endif + + if (home) { + strcpy (dest, home); + strcat (dest, path + 1); + // skip leading ~ + } else + strcpy (dest, path); +} + +int +Qrename (const char *old, const char *new) +{ + char e_old[PATH_MAX]; + char e_new[PATH_MAX]; + + Qexpand_squiggle (old, e_old); + Qexpand_squiggle (new, e_new); + return rename (e_old, e_new); +} + +QFile * +Qopen (const char *path, const char *mode) +{ + QFile *file; + char m[80], *p; + int zip = 0; + char e_path[PATH_MAX]; + + Qexpand_squiggle (path, e_path); + path = e_path; + + for (p = m; *mode && p - m < (sizeof (m) - 1); mode++) { + if (*mode == 'z') { + zip = 1; + continue; + } +#ifndef HAVE_ZLIB + if (strchr ("0123456789fh", *mode)) { + continue; + } +#endif + *p++ = *mode; + } + *p = 0; + + file = calloc (sizeof (*file), 1); + if (!file) + return 0; +#ifdef HAVE_ZLIB + if (zip) { + file->gzfile = gzopen (path, m); + if (!file->gzfile) { + free (file); + return 0; + } + } else +#endif + { + file->file = fopen (path, m); + if (!file->file) { + free (file); + return 0; + } + } + return file; +} + +QFile * +Qdopen (int fd, const char *mode) +{ + QFile *file; + char m[80], *p; + int zip = 0; + + for (p = m; *mode && p - m < (sizeof (m) - 1); mode++) { + if (*mode == 'z') { + zip = 1; + continue; + } + *p++ = *mode; + } + + *p = 0; + + file = calloc (sizeof (*file), 1); + if (!file) + return 0; +#ifdef HAVE_ZLIB + if (zip) { + file->gzfile = gzdopen (fd, m); + if (!file->gzfile) { + free (file); + return 0; + } + } else +#endif + { + file->file = fdopen (fd, m); + if (!file->file) { + free (file); + return 0; + } + } +#ifdef WIN32 + if (file->file) + setmode (_fileno (file->file), O_BINARY); +#endif + return file; +} + +void +Qclose (QFile *file) +{ + if (file->file) + fclose (file->file); +#ifdef HAVE_ZLIB + else + gzclose (file->gzfile); +#endif + free (file); +} + +int +Qread (QFile *file, void *buf, int count) +{ + if (file->file) + return fread (buf, count, 1, file->file); +#ifdef HAVE_ZLIB + else + return gzread (file->gzfile, buf, count); +#else + return -1; +#endif +} + +int +Qwrite (QFile *file, const void *buf, int count) +{ + if (file->file) + return fwrite (buf, count, 1, file->file); +#ifdef HAVE_ZLIB + else + return gzwrite (file->gzfile, (const voidp)buf, count); +#else + return -1; +#endif +} + +int +Qprintf (QFile *file, const char *fmt, ...) +{ + va_list args; + int ret = -1; + + va_start (args, fmt); + if (file->file) + ret = vfprintf (file->file, fmt, args); +#ifdef HAVE_ZLIB + else { + char buf[4096]; + + va_start (args, fmt); +#ifdef HAVE_VSNPRINTF + (args, void) vsnprintf (buf, sizeof (buf), fmt); +#else + (void) vsprintf (buf, fmt, args); +#endif + va_end (args); + ret = strlen (buf); /* some *snprintf don't return the nb + of bytes written */ + if (ret > 0) + ret = gzwrite (file->gzfile, buf, (unsigned) ret); + } +#endif + va_end (args); + return ret; +} + +char * +Qgets (QFile *file, char *buf, int count) +{ + if (file->file) + return fgets (buf, count, file->file); +#ifdef HAVE_ZLIB + else + return gzgets (file->gzfile, buf, count); +#else + return 0; +#endif +} + +int +Qgetc (QFile *file) +{ + if (file->file) + return fgetc (file->file); +#ifdef HAVE_ZLIB + else + return gzgetc (file->gzfile); +#else + return -1; +#endif +} + +int +Qputc (QFile *file, int c) +{ + if (file->file) + return fputc (c, file->file); +#ifdef HAVE_ZLIB + else + return gzputc (file->gzfile, c); +#else + return -1; +#endif +} + +int +Qseek (QFile *file, long offset, int whence) +{ + if (file->file) + return fseek (file->file, offset, whence); +#ifdef HAVE_ZLIB + else + return gzseek (file->gzfile, offset, whence); +#else + return -1; +#endif +} + +long +Qtell (QFile *file) +{ + if (file->file) + return ftell (file->file); +#ifdef HAVE_ZLIB + else + return gztell (file->gzfile); +#else + return -1; +#endif +} + +int +Qflush (QFile *file) +{ + if (file->file) + return fflush (file->file); +#ifdef HAVE_ZLIB + else + return gzflush (file->gzfile, Z_SYNC_FLUSH); +#else + return -1; +#endif +} + +int +Qeof (QFile *file) +{ + if (file->file) + return feof (file->file); +#ifdef HAVE_ZLIB + else + return gzeof (file->gzfile); +#else + return -1; +#endif +} + +/* + Qgetline + + Dynamic length version of Qgets. DO NOT free the buffer. +*/ +const char * +Qgetline (QFile *file) +{ + static int size = 256; + static char *buf = 0; + int len; + + if (!buf) { + buf = malloc (size); + if (!buf) + return 0; + } + + if (!Qgets (file, buf, size)) + return 0; + + len = strlen (buf); + while (buf[len - 1] != '\n') { + char *t = realloc (buf, size + 256); + + if (!t) + return 0; + buf = t; + size += 256; + if (!Qgets (file, buf + len, size - len)) + break; + len = strlen (buf); + } + return buf; +} + +int +Qgetpos (QFile *file, fpos_t * pos) +{ +#ifdef HAVE_FPOS_T_STRUCT + pos->__pos = Qtell (file); + return pos->__pos == -1 ? -1 : 0; +#else + *pos = Qtell (file); + return *pos == -1 ? -1 : 0; +#endif +} + +int +Qsetpos (QFile *file, fpos_t * pos) +{ +#ifdef HAVE_FPOS_T_STRUCT + return Qseek (file, pos->__pos, 0); +#else + return Qseek (file, *pos, 0); +#endif +} diff --git a/qcommon/quakeio.h b/qcommon/quakeio.h new file mode 100644 index 0000000..0d1a56d --- /dev/null +++ b/qcommon/quakeio.h @@ -0,0 +1,56 @@ +/* + quakeio.h + + (description) + + Copyright (C) 1996-1997 Id Software, Inc. + Copyright (C) 1999,2000 contributors of the QuakeForge project + Please see the file "AUTHORS" for a list of contributors + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + + $Id$ +*/ +#ifndef __quakeio_h +#define __quakeio_h + +#include + +typedef struct QFile_s QFile; + +void Qexpand_squiggle(const char *path, char *dest); +int Qrename(const char *old, const char *new); +QFile *Qopen(const char *path, const char *mode); +QFile *Qdopen(int fd, const char *mode); +void Qclose(QFile *file); +int Qread(QFile *file, void *buf, int count); +int Qwrite(QFile *file, const void *buf, int count); +int Qprintf(QFile *file, const char *fmt, ...) __attribute__((format(printf,2,3))); +char *Qgets(QFile *file, char *buf, int count); +int Qgetc(QFile *file); +int Qputc(QFile *file, int c); +int Qseek(QFile *file, long offset, int whence); +long Qtell(QFile *file); +int Qflush(QFile *file); +int Qeof(QFile *file); +const char *Qgetline(QFile *file); +int Qgetpos(QFile *file, fpos_t *pos); +int Qsetpos(QFile *file, fpos_t *pos); + +#endif /*__quakeio_h*/ diff --git a/ref_gl/gl_rmisc.c b/ref_gl/gl_rmisc.c index a6f461c..2e58518 100644 --- a/ref_gl/gl_rmisc.c +++ b/ref_gl/gl_rmisc.c @@ -103,7 +103,7 @@ void GL_ScreenShot_f (void) char picname[80]; char checkname[MAX_OSPATH]; int i, c, temp; - FILE *f; + QFile *f; // create the scrnshots directory if it doesn't exist Com_sprintf (checkname, sizeof(checkname), "%s/scrnshot", ri.FS_Gamedir()); @@ -119,10 +119,10 @@ void GL_ScreenShot_f (void) picname[5] = i/10 + '0'; picname[6] = i%10 + '0'; Com_sprintf (checkname, sizeof(checkname), "%s/scrnshot/%s", ri.FS_Gamedir(), picname); - f = fopen (checkname, "rb"); + f = Qopen (checkname, "rb"); if (!f) break; // file doesn't exist - fclose (f); + Qclose (f); } if (i==100) { @@ -151,9 +151,9 @@ void GL_ScreenShot_f (void) buffer[i+2] = temp; } - f = fopen (checkname, "wb"); - fwrite (buffer, 1, c, f); - fclose (f); + f = Qopen (checkname, "wb"); + Qwrite (f, buffer, c); + Qclose (f); free (buffer); ri.Con_Printf (PRINT_ALL, "Wrote %s\n", picname); diff --git a/ref_soft/r_misc.c b/ref_soft/r_misc.c index ce6837c..b00be57 100644 --- a/ref_soft/r_misc.c +++ b/ref_soft/r_misc.c @@ -550,7 +550,7 @@ void WritePCXfile (char *filename, byte *data, int width, int height, int i, j, length; pcx_t *pcx; byte *pack; - FILE *f; + QFile *f; pcx = (pcx_t *)malloc (width*height*2+1000); if (!pcx) @@ -598,13 +598,13 @@ void WritePCXfile (char *filename, byte *data, int width, int height, // write output file length = pack - (byte *)pcx; - f = fopen (filename, "wb"); + f = Qopen (filename, "wb"); if (!f) ri.Con_Printf (PRINT_ALL, "Failed to open to %s\n", filename); else { - fwrite ((void *)pcx, 1, length, f); - fclose (f); + Qwrite (f, (void *)pcx, length); + Qclose (f); } free (pcx); @@ -622,7 +622,7 @@ void R_ScreenShot_f (void) int i; char pcxname[80]; char checkname[MAX_OSPATH]; - FILE *f; + QFile *f; byte palette[768]; // create the scrnshots directory if it doesn't exist @@ -639,10 +639,10 @@ void R_ScreenShot_f (void) pcxname[5] = i/10 + '0'; pcxname[6] = i%10 + '0'; Com_sprintf (checkname, sizeof(checkname), "%s/scrnshot/%s", ri.FS_Gamedir(), pcxname); - f = fopen (checkname, "r"); + f = Qopen (checkname, "r"); if (!f) break; // file doesn't exist - fclose (f); + Qclose (f); } if (i==100) { diff --git a/server/server.h b/server/server.h index a8d30ca..7e8a76b 100644 --- a/server/server.h +++ b/server/server.h @@ -62,7 +62,7 @@ typedef struct byte multicast_buf[MAX_MSGLEN]; // demo server information - FILE *demofile; + QFile *demofile; qboolean timedemo; // don't time sync } server_t; @@ -175,7 +175,7 @@ typedef struct challenge_t challenges[MAX_CHALLENGES]; // to prevent invalid IPs from connecting // serverrecord values - FILE *demofile; + QFile *demofile; sizebuf_t demo_multicast; byte demo_multicast_buf[MAX_MSGLEN]; } server_static_t; diff --git a/server/sv_ccmds.c b/server/sv_ccmds.c index ebe6203..9f1fe29 100644 --- a/server/sv_ccmds.c +++ b/server/sv_ccmds.c @@ -191,32 +191,32 @@ CopyFile */ void CopyFile (char *src, char *dst) { - FILE *f1, *f2; + QFile *f1, *f2; int l; byte buffer[65536]; Com_DPrintf ("CopyFile (%s, %s)\n", src, dst); - f1 = fopen (src, "rb"); + f1 = Qopen (src, "rb"); if (!f1) return; - f2 = fopen (dst, "wb"); + f2 = Qopen (dst, "wb"); if (!f2) { - fclose (f1); + Qclose (f1); return; } while (1) { - l = fread (buffer, 1, sizeof(buffer), f1); + l = Qread (f1, buffer, sizeof(buffer)); if (!l) break; - fwrite (buffer, 1, l, f2); + Qwrite (f2, buffer, l); } - fclose (f1); - fclose (f2); + Qclose (f1); + Qclose (f2); } @@ -278,20 +278,20 @@ SV_WriteLevelFile void SV_WriteLevelFile (void) { char name[MAX_OSPATH]; - FILE *f; + QFile *f; Com_DPrintf("SV_WriteLevelFile()\n"); Com_sprintf (name, sizeof(name), "%s/save/current/%s.sv2", FS_Gamedir(), sv.name); - f = fopen(name, "wb"); + f = Qopen(name, "wb"); if (!f) { Com_Printf ("Failed to open %s\n", name); return; } - fwrite (sv.configstrings, sizeof(sv.configstrings), 1, f); + Qwrite (f, sv.configstrings, sizeof(sv.configstrings)); CM_WritePortalState (f); - fclose (f); + Qclose (f); Com_sprintf (name, sizeof(name), "%s/save/current/%s.sav", FS_Gamedir(), sv.name); ge->WriteLevel (name); @@ -306,12 +306,12 @@ SV_ReadLevelFile void SV_ReadLevelFile (void) { char name[MAX_OSPATH]; - FILE *f; + QFile *f; Com_DPrintf("SV_ReadLevelFile()\n"); Com_sprintf (name, sizeof(name), "%s/save/current/%s.sv2", FS_Gamedir(), sv.name); - f = fopen(name, "rb"); + f = Qopen(name, "rb"); if (!f) { Com_Printf ("Failed to open %s\n", name); @@ -319,7 +319,7 @@ void SV_ReadLevelFile (void) } FS_Read (sv.configstrings, sizeof(sv.configstrings), f); CM_ReadPortalState (f); - fclose (f); + Qclose (f); Com_sprintf (name, sizeof(name), "%s/save/current/%s.sav", FS_Gamedir(), sv.name); ge->ReadLevel (name); @@ -333,7 +333,7 @@ SV_WriteServerFile */ void SV_WriteServerFile (qboolean autosave) { - FILE *f; + QFile *f; cvar_t *var; char name[MAX_OSPATH], string[128]; char comment[32]; @@ -343,7 +343,7 @@ void SV_WriteServerFile (qboolean autosave) Com_DPrintf("SV_WriteServerFile(%s)\n", autosave ? "true" : "false"); Com_sprintf (name, sizeof(name), "%s/save/current/server.ssv", FS_Gamedir()); - f = fopen (name, "wb"); + f = Qopen (name, "wb"); if (!f) { Com_Printf ("Couldn't write %s\n", name); @@ -366,10 +366,10 @@ void SV_WriteServerFile (qboolean autosave) Com_sprintf (comment, sizeof(comment), "ENTERING %s", sv.configstrings[CS_NAME]); } - fwrite (comment, 1, sizeof(comment), f); + Qwrite (f, comment, sizeof(comment)); // write the mapcmd - fwrite (svs.mapcmd, 1, sizeof(svs.mapcmd), f); + Qwrite (f, svs.mapcmd, sizeof(svs.mapcmd)); // write all CVAR_LATCH cvars // these will be things like coop, skill, deathmatch, etc @@ -387,11 +387,11 @@ void SV_WriteServerFile (qboolean autosave) memset (string, 0, sizeof(string)); strcpy (name, var->name); strcpy (string, var->string); - fwrite (name, 1, sizeof(name), f); - fwrite (string, 1, sizeof(string), f); + Qwrite (f, name, sizeof(name)); + Qwrite (f, string, sizeof(string)); } - fclose (f); + Qclose (f); // write game state Com_sprintf (name, sizeof(name), "%s/save/current/game.ssv", FS_Gamedir()); @@ -406,7 +406,7 @@ SV_ReadServerFile */ void SV_ReadServerFile (void) { - FILE *f; + QFile *f; char name[MAX_OSPATH], string[128]; char comment[32]; char mapcmd[MAX_TOKEN_CHARS]; @@ -414,7 +414,7 @@ void SV_ReadServerFile (void) Com_DPrintf("SV_ReadServerFile()\n"); Com_sprintf (name, sizeof(name), "%s/save/current/server.ssv", FS_Gamedir()); - f = fopen (name, "rb"); + f = Qopen (name, "rb"); if (!f) { Com_Printf ("Couldn't read %s\n", name); @@ -430,14 +430,14 @@ void SV_ReadServerFile (void) // these will be things like coop, skill, deathmatch, etc while (1) { - if (!fread (name, 1, sizeof(name), f)) + if (!Qread (f, name, sizeof(name))) break; FS_Read (string, sizeof(string), f); Com_DPrintf ("Set %s = %s\n", name, string); Cvar_ForceSet (name, string); } - fclose (f); + Qclose (f); // start a new game fresh with new cvars SV_InitGame (); @@ -594,7 +594,7 @@ SV_Loadgame_f void SV_Loadgame_f (void) { char name[MAX_OSPATH]; - FILE *f; + QFile *f; char *dir; if (Cmd_Argc() != 2) @@ -613,13 +613,13 @@ void SV_Loadgame_f (void) // make sure the server.ssv file exists Com_sprintf (name, sizeof(name), "%s/save/%s/server.ssv", FS_Gamedir(), Cmd_Argv(1)); - f = fopen (name, "rb"); + f = Qopen (name, "rb"); if (!f) { Com_Printf ("No such savegame: %s\n", name); return; } - fclose (f); + Qclose (f); SV_CopySaveGame (Cmd_Argv(1), "current"); @@ -912,7 +912,7 @@ void SV_ServerRecord_f (void) Com_Printf ("recording to %s.\n", name); FS_CreatePath (name); - svs.demofile = fopen (name, "wb"); + svs.demofile = Qopen (name, "wb"); if (!svs.demofile) { Com_Printf ("ERROR: couldn't open.\n"); @@ -953,8 +953,8 @@ void SV_ServerRecord_f (void) // write it to the demo file Com_DPrintf ("signon message length: %i\n", buf.cursize); len = LittleLong (buf.cursize); - fwrite (&len, 4, 1, svs.demofile); - fwrite (buf.data, buf.cursize, 1, svs.demofile); + Qwrite (svs.demofile, &len, 4); + Qwrite (svs.demofile, buf.data, buf.cursize); // the rest of the demo file will be individual frames } @@ -974,7 +974,7 @@ void SV_ServerStop_f (void) Com_Printf ("Not doing a serverrecord.\n"); return; } - fclose (svs.demofile); + Qclose (svs.demofile); svs.demofile = NULL; Com_Printf ("Recording completed.\n"); } diff --git a/server/sv_ents.c b/server/sv_ents.c index 3df6c4a..117e739 100644 --- a/server/sv_ents.c +++ b/server/sv_ents.c @@ -721,7 +721,7 @@ void SV_RecordDemoMessage (void) // now write the entire message to the file, prefixed by the length len = LittleLong (buf.cursize); - fwrite (&len, 4, 1, svs.demofile); - fwrite (buf.data, buf.cursize, 1, svs.demofile); + Qwrite (svs.demofile, &len, 4); + Qwrite (svs.demofile, buf.data, buf.cursize); } diff --git a/server/sv_init.c b/server/sv_init.c index c41382a..275f30d 100644 --- a/server/sv_init.c +++ b/server/sv_init.c @@ -117,7 +117,7 @@ SV_CheckForSavegame void SV_CheckForSavegame (void) { char name[MAX_OSPATH]; - FILE *f; + QFile *f; int i; if (sv_noreload->value) @@ -127,11 +127,11 @@ void SV_CheckForSavegame (void) return; Com_sprintf (name, sizeof(name), "%s/save/current/%s.sav", FS_Gamedir(), sv.name); - f = fopen (name, "rb"); + f = Qopen (name, "rb"); if (!f) return; // no savegame - fclose (f); + Qclose (f); SV_ClearWorld (); @@ -178,7 +178,7 @@ void SV_SpawnServer (char *server, char *spawnpoint, server_state_t serverstate, Com_DPrintf ("SpawnServer: %s\n",server); if (sv.demofile) - fclose (sv.demofile); + Qclose (sv.demofile); svs.spawncount++; // any partially connected client will be // restarted diff --git a/server/sv_main.c b/server/sv_main.c index 590aa67..9f7ff34 100644 --- a/server/sv_main.c +++ b/server/sv_main.c @@ -1042,7 +1042,7 @@ void SV_Shutdown (char *finalmsg, qboolean reconnect) // free current level if (sv.demofile) - fclose (sv.demofile); + Qclose (sv.demofile); memset (&sv, 0, sizeof(sv)); Com_SetServerState (sv.state); @@ -1052,7 +1052,7 @@ void SV_Shutdown (char *finalmsg, qboolean reconnect) if (svs.client_entities) Z_Free (svs.client_entities); if (svs.demofile) - fclose (svs.demofile); + Qclose (svs.demofile); memset (&svs, 0, sizeof(svs)); } diff --git a/server/sv_send.c b/server/sv_send.c index 70aeb14..ca3e841 100644 --- a/server/sv_send.c +++ b/server/sv_send.c @@ -441,7 +441,7 @@ void SV_DemoCompleted (void) { if (sv.demofile) { - fclose (sv.demofile); + Qclose (sv.demofile); sv.demofile = NULL; } SV_Nextserver (); @@ -505,8 +505,8 @@ void SV_SendClientMessages (void) else { // get the next message - r = fread (&msglen, 4, 1, sv.demofile); - if (r != 1) + r = Qread (sv.demofile, &msglen, 4); + if (r != 4) { SV_DemoCompleted (); return; @@ -519,8 +519,8 @@ void SV_SendClientMessages (void) } if (msglen > MAX_MSGLEN) Com_Error (ERR_DROP, "SV_SendClientMessages: msglen > MAX_MSGLEN"); - r = fread (msgbuf, msglen, 1, sv.demofile); - if (r != 1) + r = Qread (sv.demofile, msgbuf, msglen); + if (r != msglen) { SV_DemoCompleted (); return; diff --git a/solaris/sys_solaris.c b/solaris/sys_solaris.c index 0890750..bd52c01 100644 --- a/solaris/sys_solaris.c +++ b/solaris/sys_solaris.c @@ -56,7 +56,7 @@ void Sys_ConsoleOutput (char *string) if (nostdout && nostdout->value) return; - fputs(string, stdout); + Qputs(string, stdout); } void Sys_Printf (char *fmt, ...) diff --git a/win32/glw_imp.c b/win32/glw_imp.c index 943d878..3ddf69a 100644 --- a/win32/glw_imp.c +++ b/win32/glw_imp.c @@ -323,7 +323,7 @@ void GLimp_Shutdown( void ) if ( glw_state.log_fp ) { - fclose( glw_state.log_fp ); + Qclose( glw_state.log_fp ); glw_state.log_fp = 0; } diff --git a/win32/glw_win.h b/win32/glw_win.h index ba7aa2b..e11ae67 100644 --- a/win32/glw_win.h +++ b/win32/glw_win.h @@ -39,7 +39,7 @@ typedef struct qboolean allowdisplaydepthchange; qboolean mcd_accelerated; - FILE *log_fp; + QFile *log_fp; } glwstate_t; extern glwstate_t glw_state; diff --git a/win32/qgl_win.c b/win32/qgl_win.c index 09da1e9..f062768 100644 --- a/win32/qgl_win.c +++ b/win32/qgl_win.c @@ -3440,7 +3440,7 @@ void GLimp_EnableLogging( qboolean enable ) asctime( newtime ); Com_sprintf( buffer, sizeof(buffer), "%s/gl.log", ri.FS_Gamedir() ); - glw_state.log_fp = fopen( buffer, "wt" ); + glw_state.log_fp = Qopen( buffer, "wt" ); fprintf( glw_state.log_fp, "%s\n", asctime( newtime ) ); } diff --git a/win32/sys_win.c b/win32/sys_win.c index 02e5b90..f14dfb3 100644 --- a/win32/sys_win.c +++ b/win32/sys_win.c @@ -140,7 +140,7 @@ char *Sys_ScanForCD (void) static qboolean done; #ifndef DEMO char drive[4]; - FILE *f; + QFile *f; char test[MAX_QPATH]; if (done) // don't re-check @@ -162,10 +162,10 @@ char *Sys_ScanForCD (void) // where activision put the stuff... sprintf (cddir, "%sinstall\\data", drive); sprintf (test, "%sinstall\\data\\quake2.exe", drive); - f = fopen(test, "r"); + f = Qopen(test, "r"); if (f) { - fclose (f); + Qclose (f); if (GetDriveType (drive) == DRIVE_CDROM) return cddir; }