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

@ -42,6 +42,10 @@
static int read_custom_table_file(char *);
/*
* Read builtin configuration tables.
* Return 0 on success, -1 on failure.
*/
int
read_builtin_tables(void)
{
@ -56,7 +60,7 @@ read_builtin_tables(void)
*/
for (ep = empfile; ep->name; ep++) {
if (!EF_IS_GAME_STATE(ep->uid) && ep->file) {
if ((fp = fopen(ep->file, "r")) == NULL) {
if ((fp = fopenat(ep->file, "r", builtindir)) == NULL) {
fprintf(stderr, "Can't open %s for reading (%s)\n",
ep->file, strerror(errno));
return -1;
@ -107,7 +111,7 @@ read_custom_table_file(char *fname)
int lineno, res, n;
FILE *fp;
if (!(fp = fopen(fname, "r"))) {
if (!(fp = fopenat(fname, "r", configdir))) {
fprintf(stderr, "Can't open config table %s for reading (%s)\n",
fname, strerror(errno));
return -1;