nlib
Config_freebsd.h
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_CONFIG_FREEBSD_H_
4 #define INCLUDE_NN_NLIB_CONFIG_FREEBSD_H_
5 #ifndef INCLUDE_NN_NLIB_CONFIG_H_
6 # error do not include directly
7 #endif
8 
9 #if defined(__FreeBSD__)
10 #include <sys/param.h>
11 # if __FreeBSD_version < 1000000
12 # error nlib requires FreeBSD 10.0 or higher.
13 # endif
14 #endif
15 
16 #if defined(__clang__)
17 # include "nn/nlib/Config_clang.h"
18 # elif defined(__GNUC__)
19 # include "nn/nlib/Config_gcc.h"
20 #else
21 # error
22 #endif
23 
24 #define NLIB_HAS_VIRTUALMEMORY
25 
26 #include <sys/types.h>
27 #include <sys/sysctl.h>
28 #include <cxxabi.h>
29 
30 #define NLIB_PATHMAPPER_FORSAMPLE \
31  extern "C" char *getcwd(char *buf, size_t size); \
32  nlib_ns::NativePathMapper g_PathMapper; \
33  inline void InitPathMapperForSample() { \
34  int mib[4]; \
35  mib[0] = CTL_KERN; \
36  mib[1] = KERN_PROC; \
37  mib[2] = KERN_PROC_PATHNAME; \
38  mib[3] = -1; \
39  char dir[1024]; \
40  size_t cb = sizeof(dir); \
41  int err = sysctl(mib, 4, dir, &cb, NULL, 0); \
42  if (err != 0 || cb == 0 || nlib_strlen(dir) == 0) { \
43  char* cwd = getcwd(dir, 1024); \
44  if (cwd) { \
45  g_PathMapper.AddMap(cwd, "nlibpath:
46  g_PathMapper.AddMap(cwd, "nlibpath:
47  } \
48  } else { \
49  *const_cast<char*>(nlib_strrchr(dir, '/')) = '\0'; \
50  g_PathMapper.AddMap(dir, "nlibpath:
51  g_PathMapper.AddMap(dir, "nlibpath:
52  } \
53  }
54 
55 #define NLIB_MAINFUNC int main(int argc, char** argv) { \
56  bool result = SampleMain(argc, argv); nlib_printf(result ? "OK\n" : "NG\n"); \
57  return result ? 0 : 1; }
58 
59 #define NLIB_RETHROW_UNWIND catch (struct _Unwind_Exception&)
60 
61 #endif // INCLUDE_NN_NLIB_CONFIG_FREEBSD_H_