cfgfile.c (CFG_ReadCvars): Also check for ferror(). Use FS_rewind()

instead of FS_fseek(). From Sander van Dijk.
cfgfile.c, cfgfile.h: synced with uhexen2 versions.

git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@564 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
sezero 2011-12-27 19:40:14 +00:00
parent a22c56b5ae
commit 96d60a3f51
2 changed files with 31 additions and 23 deletions

View file

@ -52,13 +52,12 @@ void CFG_ReadCvars (const char **vars, int num_vars)
do {
i = 0;
memset (buff, 0, sizeof(buff));
// we expect a line in the format that Cvar_WriteVariables
// writes to the config file. although I'm trying to be as
// much cautious as possible, if the user screws it up by
// editing it, it's his fault.
if (FS_fgets(buff, sizeof(buff), cfg_file))
{
// we expect a line in the format that Cvar_WriteVariables
// writes to the config file. although I'm trying to be as
// much cautious as possible, if the user screws it up by
// editing it, it's his fault.
// remove end-of-line characters
while (buff[i])
{
@ -99,7 +98,7 @@ void CFG_ReadCvars (const char **vars, int num_vars)
tmp = strchr(buff, '\"');
if (tmp)
{
Cvar_Set (vars[i], tmp+1);
Cvar_Set (vars[i], tmp + 1);
j++;
break;
}
@ -109,11 +108,20 @@ void CFG_ReadCvars (const char **vars, int num_vars)
if (j == num_vars)
break;
} while (!FS_feof(cfg_file));
} while (!FS_feof(cfg_file) && !FS_ferror(cfg_file));
FS_fseek (cfg_file, 0, SEEK_SET);
FS_rewind (cfg_file);
}
/*
===================
CFG_ReadCvarOverrides
convenience function, reading the "+" command line override
values of cvars in the given list. doesn't do anything with
the config file.
===================
*/
void CFG_ReadCvarOverrides (const char **vars, int num_vars)
{
char buff[64];
@ -148,20 +156,20 @@ void CFG_CloseConfig (void)
int CFG_OpenConfig (const char *cfg_name)
{
FILE *file;
long length;
qboolean pak;
FILE *f;
long length;
qboolean pak;
CFG_CloseConfig ();
length = (long) COM_FOpenFile (cfg_name, &file, NULL);
length = (long) COM_FOpenFile (cfg_name, &f, NULL);
pak = file_from_pak;
if (length == -1)
return -1;
cfg_file = (fshandle_t *) Z_Malloc(sizeof(fshandle_t));
cfg_file->file = file;
cfg_file->start = ftell(file);
cfg_file->file = f;
cfg_file->start = ftell(f);
cfg_file->pos = 0;
cfg_file->length = length;
cfg_file->pak = pak;

View file

@ -27,21 +27,21 @@
#define __CFGFILE_H
int CFG_OpenConfig (const char *cfg_name);
// opens the given config file and keeps it open
// until CFG_CloseConfig is called
// opens the given config file. only one open config file is
// kept: previosly opened one, if any, will be closed.
void CFG_CloseConfig (void);
// closes the currently open config file
// closes the currently open config file.
void CFG_ReadCvars (const char **vars, int num_vars);
// reads the values of cvars in the given list
// from the currently open config file
// reads the values of cvars in the given list from the opened
// config file.
void CFG_ReadCvarOverrides (const char **vars, int num_vars);
// reads the "+" command line override values of cvars
// in the given list. doesn't care about the config file.
// call this after CFG_ReadCvars() and before locking your
// cvars.
// convenience function, reading the "+" command line override
// values of cvars in the given list. doesn't do anything with
// the config file. call this after CFG_ReadCvars() and before
// locking your cvars.
#endif /* __CFGFILE_H */