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:
parent
4bb23dd1a6
commit
b76e5a5eed
4 changed files with 30 additions and 17 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue