[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Baked-in paths

From: Steffen Dettmer
Subject: Re: Baked-in paths
Date: Mon, 15 Mar 2010 16:59:32 +0100

On Sun, Mar 14, 2010 at 11:29 PM, Reuben Thomas <address@hidden> wrote:
> I have a C program which loads some scripts at runtime. These are
> stored in datadir (e.g. /usr/local/share/prog). But I also want to be
> able to run the program from its build directory.

We have some similar situations but failed to find one solution
working well in all cases.
For unit tests, we sometimes (run-time) re-configure the test
object. This might be as simple as:

  static const char *configPath_ = "/usr/local/share/prog";
  const char *getConfigPath(void) { return configPath_); }
  void setTestConfigPath(void) { configPath_ = "."; }

If the application has something like:

int main(int argc, char *argv[]) { return appXyzMain(argc, argv); }

the test can call appXyzMain with an argv containing `--data-dir=.' option.

Then there are cases where it seems suited to have a list of
directories where to search:

  const char *paths[] { "./tests/", "/usr/local/share/", "/usr/share" };

Some tools (helper scripts) even `guess' if they run from a
sandbox (e.g. by looking if a file Makefile exists in same
directory or compare $argv[0] with @prefix@, but all this seems
to be tricky and surely not portable).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]