Make conftab.c independent of the current directory

read_builtin_tables() wanted to run in builtindir, and
read_custom_tables() wanted to run in configdir.  Bothersome.  Use new
fopenat() to relax those requirements.

The chdir() satisfying them are now superflous, remove them.
This commit is contained in:
Markus Armbruster 2008-02-03 21:43:49 +01:00
parent 4bb23dd1a6
commit b76e5a5eed
4 changed files with 30 additions and 17 deletions

View file

@ -71,3 +71,26 @@ fname_is_abs(const char *fname)
return fname[0] == '/';
#endif
}
/*
* Open a stream like fopen(), optionally relative to a directory.
* This is exactly like fopen(), except FNAME is interpreted relative
* to DIR if that is neither null nor empty.
*/
FILE *
fopenat(const char *fname, const char *mode, const char *dir)
{
char *fnat;
FILE *fp;
fnat = fnameat(fname, dir);
if (!fnat)
return NULL;
fp = fopen(fnat, mode);
if (fnat != fname)
free(fnat);
return fp;
}