OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mapdpath.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _MAPDPATH_H
18 #define _MAPDPATH_H
19 
20 #include <boost/filesystem/path.hpp>
21 #include "Logger.h"
22 
23 #ifdef __APPLE__
24 #include <libproc.h>
25 #else
26 #include <linux/limits.h>
27 #endif
28 #include <unistd.h>
29 
30 inline std::string mapd_root_abs_path() {
31 #ifdef __APPLE__
32  char abs_exe_path[PROC_PIDPATHINFO_MAXSIZE] = {0};
33  auto path_len = proc_pidpath(getpid(), abs_exe_path, sizeof(abs_exe_path));
34 #else
35  char abs_exe_path[PATH_MAX] = {0};
36  auto path_len = readlink("/proc/self/exe", abs_exe_path, sizeof(abs_exe_path));
37 #endif
38  CHECK_GT(path_len, 0);
39  CHECK_LT(static_cast<size_t>(path_len), sizeof(abs_exe_path));
40  boost::filesystem::path abs_exe_dir(std::string(abs_exe_path, path_len));
41  abs_exe_dir.remove_filename();
42 #ifdef XCODE
43  const auto mapd_root = abs_exe_dir.parent_path().parent_path();
44 #else
45  const auto mapd_root = abs_exe_dir.parent_path();
46 #endif
47  return mapd_root.string();
48 }
49 
50 #endif // _MAPDPATH_H
std::string mapd_root_abs_path()
Definition: mapdpath.h:30
#define CHECK_GT(x, y)
Definition: Logger.h:202
#define CHECK_LT(x, y)
Definition: Logger.h:200