aboutsummaryrefslogtreecommitdiff
path: root/odb/odb.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-02-22 15:09:35 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-05-27 09:33:45 -0400
commitd23cf3a7591d48b924af0bedf65d01c8f75e5924 (patch)
tree788d98d6b3d12e6ecf66c4dab7544fd6d48177cd /odb/odb.cxx
parentd89d5e198222b0183aee506d58185d61e91aed33 (diff)
Search in outer directories for default options file
Diffstat (limited to 'odb/odb.cxx')
-rw-r--r--odb/odb.cxx26
1 files 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);