Describe dummy test model. Work on OpenFlow intro.
[openvswitch] / lib / dirs.c.in
1 #line 2 "@srcdir@/lib/dirs.c.in"
2 /*
3  * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <config.h>
19 #include "dirs.h"
20 #include <stdlib.h>
21 #include "util.h"
22
23 struct directory {
24     const char *value;          /* Actual value; NULL if not yet determined. */
25     const char *default_value;  /* Default value. */
26     const char *var_name;       /* Environment variable to override default. */
27 };
28
29 static const char *
30 get_dir(struct directory *d)
31 {
32     if (!d->value) {
33         d->value = getenv(d->var_name);
34         if (!d->value || !d->value[0]) {
35             d->value = d->default_value;
36         }
37     }
38     return d->value;
39 }
40
41 const char *
42 ovs_sysconfdir(void)
43 {
44     static struct directory d = { NULL, @sysconfdir@, "OVS_SYSCONFDIR" };
45     return get_dir(&d);
46 }
47
48 const char *
49 ovs_pkgdatadir(void)
50 {
51     static struct directory d = { NULL, @pkgdatadir@, "OVS_PKGDATADIR" };
52     return get_dir(&d);
53 }
54
55 const char *
56 ovs_rundir(void)
57 {
58     static struct directory d = { NULL, @RUNDIR@, "OVS_RUNDIR" };
59     return get_dir(&d);
60 }
61
62 const char *
63 ovs_logdir(void)
64 {
65     static struct directory d = { NULL, @LOGDIR@, "OVS_LOGDIR" };
66     return get_dir(&d);
67 }
68
69 const char *
70 ovs_dbdir(void)
71 {
72     static const char *dbdir;
73     if (!dbdir) {
74         dbdir = getenv("OVS_DBDIR");
75         if (!dbdir || !dbdir[0]) {
76             char *sysconfdir = getenv("OVS_SYSCONFDIR");
77
78             dbdir = (sysconfdir
79                      ? xasprintf("%s/openvswitch", sysconfdir)
80                      : @DBDIR@);
81         }
82     }
83     return dbdir;
84 }
85
86 const char *
87 ovs_bindir(void)
88 {
89     static struct directory d = { NULL, @bindir@, "OVS_BINDIR" };
90     return get_dir(&d);
91 }