mCRL2
Loading...
Searching...
No Matches
basename.h
Go to the documentation of this file.
1// Author(s): Frank Stappers
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
11
12#ifndef MCRL2_BASENAME_H
13#define MCRL2_BASENAME_H
14
16
17#include <cstdio>
18#include <string>
20
21#ifdef MCRL2_PLATFORM_LINUX
22#include <unistd.h>
23#endif
24
25#ifdef MCRL2_PLATFORM_WINDOWS
26#include <windows.h>
27#endif
28
29#ifdef MCRL2_PLATFORM_MAC
30#include <mach-o/dyld.h>
31#endif
32
33namespace mcrl2
34{
35
36namespace utilities
37{
38
41 inline std::string get_executable_basename()
42 {
43 std::string path;
44#ifdef MCRL2_PLATFORM_LINUX
45 path = "";
46 pid_t pid = getpid();
47 char buf[10];
48 sprintf(buf,"%d",pid);
49 std::string _link = "/proc/";
50 _link.append(buf);
51 _link.append("/exe");
52 char proc[512];
53 int ch = readlink(_link.c_str(),proc,512);
54 if (ch != -1)
55 {
56 proc[ch] = 0;
57 path = proc;
58 std::string::size_type t = path.find_last_of("/");
59 path = path.substr(0,t);
60 }
61#endif // MCRL2_PLATFORM_LINUX
62
63#ifdef MCRL2_PLATFORM_MAC
64 char* pathbuf = NULL;
65 uint32_t bufsize = 0;
66 _NSGetExecutablePath(pathbuf, &bufsize);
67 pathbuf = new char[bufsize];
68 if (_NSGetExecutablePath(pathbuf, &bufsize) != 0)
69 {
70 throw mcrl2::runtime_error("Could not retrieve path to main executable (_NSGetExecutablePath returned nonzero).");
71 }
72 path = pathbuf;
73 delete[] pathbuf;
74 std::string::size_type t = path.find_last_of("/");
75 path = path.substr(0,t);
76#endif //MCRL2_PLATFORM_MAC
77
78#ifdef MCRL2_PLATFORM_WINDOWS
79 char buffer[MAX_PATH]; //always use MAX_PATH for filepaths
80 GetModuleFileName(NULL, buffer, sizeof(buffer));
81 path = buffer;
82 std::string::size_type t = path.find_last_of("\\");
83 path = path.substr(0,t);
84#endif // MCRL2_PLATFORM_WINDOWS
85
86 return path;
87 }
88}
89
90}
91
92
93#endif //MCRL2_BASENAME_H
Standard exception class for reporting runtime errors.
Definition exception.h:27
Exception classes for use in libraries and tools.
@ proc
Definition linearise.cpp:79
std::string get_executable_basename()
Returns the basename of a tool.
Definition basename.h:41
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72