From d23cf3a7591d48b924af0bedf65d01c8f75e5924 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 22 Feb 2013 15:09:35 +0200 Subject: Search in outer directories for default options file --- odb/odb.cxx | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/odb/odb.cxx b/odb/odb.cxx index 577a904..4eb178b 100644 --- a/odb/odb.cxx +++ b/odb/odb.cxx @@ -246,12 +246,32 @@ main (int argc, char* argv[]) { path file (ODB_DEFAULT_OPTIONS_FILE); - // If the path is relative, then use the driver's path as a base. + // If the path is relative, then use the driver's path as a base. If + // the file is not found in that directory, then also try outer + // directory (so that we can find /etc if driver is in /usr/bin). // if (file.relative ()) { - path dp (driver_path (path (argv[0]))); - file = dp.directory () / file; + path dd (driver_path (path (argv[0])).directory ()); + + for (path d (dd);; d = d.directory ()) + { + path f (d / file); + // Check that the file exist without checking for permissions, etc. + // + struct stat s; + if (stat (f.string ().c_str (), &s) == 0 && S_ISREG (s.st_mode)) + { + file = f; + break; + } + + if (d.root ()) + break; + } + + if (file.relative ()) + file = dd / file; } int ac (3); -- cgit v1.1