LAL  7.5.0.1-b72065a
whereami.h
Go to the documentation of this file.
1 // (‑●‑●)> dual licensed under the WTFPL v2 and MIT licenses
2 // without any warranty.
3 // by Gregory Pakosz (@gpakosz)
4 // https://github.com/gpakosz/whereami
5 
6 #ifndef WHEREAMI_H
7 #define WHEREAMI_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 #ifndef WAI_FUNCSPEC
14  #define WAI_FUNCSPEC
15 #endif
16 #ifndef WAI_PREFIX
17 #define WAI_PREFIX(function) wai_##function
18 #endif
19 
20 /**
21  * Returns the path to the current executable.
22  *
23  * Usage:
24  * - first call `int length = wai_getExecutablePath(NULL, 0, NULL);` to
25  * retrieve the length of the path
26  * - allocate the destination buffer with `path = (char*)malloc(length + 1);`
27  * - call `wai_getExecutablePath(path, length, NULL)` again to retrieve the
28  * path
29  * - add a terminal NUL character with `path[length] = '\0';`
30  *
31  * @param out destination buffer, optional
32  * @param capacity destination buffer capacity
33  * @param dirname_length optional recipient for the length of the dirname part
34  * of the path.
35  *
36  * @return the length of the executable path on success (without a terminal NUL
37  * character), otherwise `-1`
38  */
40 int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length);
41 
42 /**
43  * Returns the path to the current module
44  *
45  * Usage:
46  * - first call `int length = wai_getModulePath(NULL, 0, NULL);` to retrieve
47  * the length of the path
48  * - allocate the destination buffer with `path = (char*)malloc(length + 1);`
49  * - call `wai_getModulePath(path, length, NULL)` again to retrieve the path
50  * - add a terminal NUL character with `path[length] = '\0';`
51  *
52  * @param out destination buffer, optional
53  * @param capacity destination buffer capacity
54  * @param dirname_length optional recipient for the length of the dirname part
55  * of the path.
56  *
57  * @return the length of the module path on success (without a terminal NUL
58  * character), otherwise `-1`
59  */
61 int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length);
62 
63 #ifdef __cplusplus
64 }
65 #endif
66 
67 #endif // #ifndef WHEREAMI_H
WAI_FUNCSPEC int WAI_PREFIX() getExecutablePath(char *out, int capacity, int *dirname_length)
Returns the path to the current executable.
WAI_FUNCSPEC int WAI_PREFIX() getModulePath(char *out, int capacity, int *dirname_length)
Returns the path to the current module.
#define WAI_PREFIX(function)
Definition: whereami.h:17
#define WAI_FUNCSPEC
Definition: whereami.h:14