FRIK_FILE sanity
Posted: Mon Jan 17, 2011 7:17 pm
If you've implemented FRIK_FILE you've probably noticed that opening a file in append mode is a thing of true evil. Let's bring that warm fuzzy glow of sanity to it.
First replace your PF_fopen with this version:
Now add this to sys_win.c (or whatever, depending on your platform):
And finally add this to sys.h:
No further explanation needed, I hope.
First replace your PF_fopen with this version:
Code: Select all
void PF_fopen (void)
{
char *p = G_STRING(OFS_PARM0);
int fmode = G_FLOAT (OFS_PARM1);
int h = 0;
switch (fmode)
{
case 0: // read
Sys_FileOpenRead (va("%s/%s",com_gamedir, p), &h);
break;
case 1: // append -- sane version
h = Sys_FileOpenAppend (va("%s/%s", com_gamedir, p));
break;
default: // write
h = Sys_FileOpenWrite (va("%s/%s", com_gamedir, p));
break;
}
// always common now
G_FLOAT (OFS_RETURN) = (float) h;
}
Code: Select all
int Sys_FileOpenAppend (char *path)
{
FILE *f;
int i;
i = findhandle ();
f = fopen (path, "ab");
// change this Sys_Error to something that works in your code
if (!f)
Sys_Error ("Error opening %s: %s", path, strerror (errno));
sys_handles[i] = f;
return i;
}
Code: Select all
int Sys_FileOpenAppend (char *path);