3
A brief file description
5
@section license License
7
Licensed to the Apache Software Foundation (ASF) under one
8
or more contributor license agreements. See the NOTICE file
9
distributed with this work for additional information
10
regarding copyright ownership. The ASF licenses this file
11
to you under the Apache License, Version 2.0 (the
12
"License"); you may not use this file except in compliance
13
with the License. You may obtain a copy of the License at
15
http://www.apache.org/licenses/LICENSE-2.0
17
Unless required by applicable law or agreed to in writing, software
18
distributed under the License is distributed on an "AS IS" BASIS,
19
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
See the License for the specific language governing permissions and
21
limitations under the License.
27
static Layout *layout = NULL;
33
ink_assert("need to call create_default_layout before accessing" "default_layout()");
39
Layout::create(const char *prefix)
42
layout = NEW(new Layout(prefix));
47
layout_relative(const char *root, const char *file)
51
if (ink_filepath_merge(path, PATH_MAX, root, file,
52
INK_FILEPATH_TRUENAME)) {
56
ink_error("Cannot merge path '%s' above the root '%s'\n", file, root);
57
} else if (err == E2BIG) {
58
ink_error("Excedding file name length limit of %d characters\n", PATH_MAX);
61
// TODO: Make some pretty errors.
62
ink_error("Cannot merge '%s' with '%s' error=%d\n", file, root, err);
70
Layout::relative(const char *file)
72
return layout_relative(prefix, file);
76
Layout::relative(char *buf, size_t bufsz, const char *file)
80
if (ink_filepath_merge(path, PATH_MAX, prefix, file,
81
INK_FILEPATH_TRUENAME)) {
85
ink_error("Cannot merge path '%s' above the root '%s'\n", file, prefix);
86
} else if (err == E2BIG) {
87
ink_error("Excedding file name length limit of %d characters\n", PATH_MAX);
90
// TODO: Make some pretty errors.
91
ink_error("Cannot merge '%s' with '%s' error=%d\n", file, prefix, err);
95
size_t path_len = strlen(path) + 1;
96
if (path_len > bufsz) {
97
ink_error("Provided buffer is too small: %d, required %d\n",
106
Layout::relative_to(const char *dir, const char *file)
108
return layout_relative(dir, file);
112
Layout::relative_to(char *buf, size_t bufsz, const char *dir, const char *file)
116
if (ink_filepath_merge(path, PATH_MAX, dir, file,
117
INK_FILEPATH_TRUENAME)) {
121
ink_error("Cannot merge path '%s' above the root '%s'\n", file, dir);
122
} else if (err == E2BIG) {
123
ink_error("Excedding file name length limit of %d characters\n", PATH_MAX);
126
// TODO: Make some pretty errors.
127
ink_error("Cannot merge '%s' with '%s' error=%d\n", file, dir, err);
131
size_t path_len = strlen(path) + 1;
132
if (path_len > bufsz) {
133
ink_error("Provided buffer is too small: %d, required %d\n",
141
Layout::Layout(const char *_prefix)
144
prefix = xstrdup(_prefix);
151
if ((env_path = getenv("TS_ROOT"))) {
152
len = strlen(env_path);
153
if ((len + 1) > PATH_MAX) {
154
ink_error("TS_ROOT environment variable is too big: %d, max %d\n",
158
strcpy(path, env_path);
159
while (len > 1 && path[len - 1] == '/') {
160
path[len - 1] = '\0';
164
// Use compile time --prefix
165
ink_strncpy(path, PREFIX, sizeof(path));
168
if (access(path, R_OK) == -1) {
169
ink_error("unable to access() TS_ROOT '%s': %d, %s\n",
170
path, errno, strerror(errno));
173
prefix = xstrdup(path);
175
exec_prefix = layout_relative(prefix, EXEC_PREFIX);
176
bindir = layout_relative(prefix, BINDIR);
177
sbindir = layout_relative(prefix, SBINDIR);
178
sysconfdir = layout_relative(prefix, SYSCONFDIR);
179
datadir = layout_relative(prefix, DATADIR);
180
includedir = layout_relative(prefix, INCLUDEDIR);
181
libdir = layout_relative(prefix, LIBDIR);
182
libexecdir = layout_relative(prefix, LIBEXECDIR);
183
localstatedir = layout_relative(prefix, LOCALSTATEDIR);
184
sharedstatedir = layout_relative(prefix, SHAREDSTATEDIR);
185
runtimedir = layout_relative(prefix, RUNTIMEDIR);
186
logdir = layout_relative(prefix, LOGDIR);
187
mandir = layout_relative(prefix, MANDIR);
188
infodir = layout_relative(prefix, INFODIR);
189
cachedir = layout_relative(prefix, CACHEDIR);
192
// TODO: Use a propper Debug logging
194
#define PrintSTR(var) \
195
fprintf(stdout, "%18s = '%s'\n", "--" #var, (var == NULL? "NULL" : var));
197
fprintf(stdout, "Layout configuration\n");
199
PrintSTR(exec_prefix);
202
PrintSTR(sysconfdir);
204
PrintSTR(includedir);
206
PrintSTR(libexecdir);
207
PrintSTR(localstatedir);
208
PrintSTR(sharedstatedir);
209
PrintSTR(runtimedir);
220
#define SafeFree(x) \
224
SafeFree(exec_prefix);
227
SafeFree(sysconfdir);
229
SafeFree(includedir);
231
SafeFree(libexecdir);
232
SafeFree(localstatedir);
233
SafeFree(sharedstatedir);
234
SafeFree(runtimedir);