Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
6706e7e4c5 | |||
08c6afcba2 | |||
bd6cff26dd | |||
093a2efc08 | |||
|
f3a86fdf17 | ||
|
4414eb5812 | ||
|
e64e8b379b | ||
|
73eb7856dd |
@ -50,6 +50,9 @@ if(BUILD_EXAMPLES)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
install(FILES ${CMAKE_SOURCE_DIR}/src/whereami.h COMPONENT headers
|
||||||
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||||
|
|
||||||
if(PKG_CONFIG_FOUND)
|
if(PKG_CONFIG_FOUND)
|
||||||
configure_file(${CMAKE_SOURCE_DIR}/pkgconfig/whereami.pc.in ${CMAKE_BINARY_DIR}/whereami.pc)
|
configure_file(${CMAKE_SOURCE_DIR}/pkgconfig/whereami.pc.in ${CMAKE_BINARY_DIR}/whereami.pc)
|
||||||
install(FILES ${CMAKE_BINARY_DIR}/whereami.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
install(FILES ${CMAKE_BINARY_DIR}/whereami.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||||
@ -106,4 +109,7 @@ if(CMAKE_CXX_COMPILER)
|
|||||||
configure_file(${CMAKE_SOURCE_DIR}/pkgconfig/whereamipp.pc.in ${CMAKE_BINARY_DIR}/whereamipp.pc)
|
configure_file(${CMAKE_SOURCE_DIR}/pkgconfig/whereamipp.pc.in ${CMAKE_BINARY_DIR}/whereamipp.pc)
|
||||||
install(FILES ${CMAKE_BINARY_DIR}/whereamipp.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
install(FILES ${CMAKE_BINARY_DIR}/whereamipp.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
install(FILES ${CMAKE_SOURCE_DIR}/src/whereami++.h COMPONENT headers
|
||||||
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||||
endif()
|
endif()
|
||||||
|
18
LICENSE.MIT
Normal file
18
LICENSE.MIT
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
Copyright Gregory Pakosz
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@ -12,6 +12,8 @@ Supported platforms:
|
|||||||
- Android
|
- Android
|
||||||
- QNX Neutrino
|
- QNX Neutrino
|
||||||
- FreeBSD
|
- FreeBSD
|
||||||
|
- NetBSD
|
||||||
|
- DragonFly BSD
|
||||||
- SunOS
|
- SunOS
|
||||||
|
|
||||||
Just drop `whereami.h` and `whereami.c` into your build and get started. (see
|
Just drop `whereami.h` and `whereami.c` into your build and get started. (see
|
||||||
|
@ -45,8 +45,8 @@ buildir := $(realpath .)/build
|
|||||||
binsubdir := $(platform)-$(architecture)
|
binsubdir := $(platform)-$(architecture)
|
||||||
bindir := $(prefix)/bin/$(binsubdir)
|
bindir := $(prefix)/bin/$(binsubdir)
|
||||||
|
|
||||||
CFLAGS := -O2 -g -Wall -pedantic -Werror -std=c99
|
CFLAGS := -O2 -g -Wall -pedantic -Werror -Wshadow -std=c99
|
||||||
CXXFLAGS := -O2 -g -Wall -pedantic -Werror
|
CXXFLAGS := -O2 -g -Wall -pedantic -Werror -Wshadow -Wuseless-cast
|
||||||
|
|
||||||
ifeq ($(platform),linux)
|
ifeq ($(platform),linux)
|
||||||
LDFLAGS += -ldl
|
LDFLAGS += -ldl
|
||||||
|
@ -18,6 +18,13 @@ typedef WHEREAMI_STRING_T whereami_string_t;
|
|||||||
#define WHEREAMI_CXX11
|
#define WHEREAMI_CXX11
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
# if !((__GNUC__ * 100 + __GNUC_MINOR__) < 408)
|
||||||
|
#undef WHEREAMI_CXX11
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace whereami {
|
namespace whereami {
|
||||||
|
|
||||||
class whereami_path_t
|
class whereami_path_t
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
// (‑●‑●)> released under the WTFPL v2 license, by Gregory Pakosz (@gpakosz)
|
// (‑●‑●)> dual licensed under the WTFPL v2 and MIT licenses
|
||||||
|
// without any warranty.
|
||||||
|
// by Gregory Pakosz (@gpakosz)
|
||||||
// https://github.com/gpakosz/whereami
|
// https://github.com/gpakosz/whereami
|
||||||
|
|
||||||
// in case you want to #include "whereami.c" in a larger compilation unit
|
// in case you want to #include "whereami.c" in a larger compilation unit
|
||||||
@ -136,15 +138,13 @@ static int WAI_PREFIX(getModulePath_)(HMODULE module, char* out, int capacity, i
|
|||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
WAI_NOINLINE
|
WAI_NOINLINE WAI_FUNCSPEC
|
||||||
WAI_FUNCSPEC
|
|
||||||
int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
|
int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
|
||||||
{
|
{
|
||||||
return WAI_PREFIX(getModulePath_)(NULL, out, capacity, dirname_length);
|
return WAI_PREFIX(getModulePath_)(NULL, out, capacity, dirname_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
WAI_NOINLINE
|
WAI_NOINLINE WAI_FUNCSPEC
|
||||||
WAI_FUNCSPEC
|
|
||||||
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
|
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
|
||||||
{
|
{
|
||||||
HMODULE module;
|
HMODULE module;
|
||||||
@ -165,7 +165,7 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
|
|||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(__linux__) || defined(__CYGWIN__) || defined(__sun)
|
#elif defined(__linux__) || defined(__CYGWIN__) || defined(__sun) || defined(WAI_USE_PROC_SELF_EXE)
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -245,15 +245,13 @@ int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
WAI_NOINLINE
|
WAI_NOINLINE WAI_FUNCSPEC
|
||||||
WAI_FUNCSPEC
|
|
||||||
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
|
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
|
||||||
{
|
{
|
||||||
int length = -1;
|
int length = -1;
|
||||||
FILE* maps = NULL;
|
FILE* maps = NULL;
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < WAI_PROC_SELF_MAPS_RETRY; ++i)
|
for (int r = 0; r < WAI_PROC_SELF_MAPS_RETRY; ++r)
|
||||||
{
|
{
|
||||||
maps = fopen(WAI_PROC_SELF_MAPS, "r");
|
maps = fopen(WAI_PROC_SELF_MAPS, "r");
|
||||||
if (!maps)
|
if (!maps)
|
||||||
@ -274,7 +272,7 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
|
|||||||
|
|
||||||
if (sscanf(buffer, "%" PRIx64 "-%" PRIx64 " %s %" PRIx64 " %x:%x %u %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8)
|
if (sscanf(buffer, "%" PRIx64 "-%" PRIx64 " %s %" PRIx64 " %x:%x %u %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8)
|
||||||
{
|
{
|
||||||
uint64_t addr = (uint64_t)(uintptr_t)WAI_RETURN_ADDRESS();
|
uint64_t addr = (uintptr_t)WAI_RETURN_ADDRESS();
|
||||||
if (low <= addr && addr <= high)
|
if (low <= addr && addr <= high)
|
||||||
{
|
{
|
||||||
char* resolved;
|
char* resolved;
|
||||||
@ -346,11 +344,15 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fclose(maps);
|
fclose(maps);
|
||||||
|
maps = NULL;
|
||||||
|
|
||||||
if (length != -1)
|
if (length != -1)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (maps)
|
||||||
|
fclose(maps);
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,8 +417,7 @@ int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
|
|||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
WAI_NOINLINE
|
WAI_NOINLINE WAI_FUNCSPEC
|
||||||
WAI_FUNCSPEC
|
|
||||||
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
|
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
|
||||||
{
|
{
|
||||||
char buffer[PATH_MAX];
|
char buffer[PATH_MAX];
|
||||||
@ -587,7 +588,11 @@ int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
|
|||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
#if defined(__NetBSD__)
|
||||||
|
int mib[4] = { CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME };
|
||||||
|
#else
|
||||||
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
|
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
|
||||||
|
#endif
|
||||||
size_t size = sizeof(buffer1);
|
size_t size = sizeof(buffer1);
|
||||||
|
|
||||||
if (sysctl(mib, (u_int)(sizeof(mib) / sizeof(mib[0])), path, &size, NULL, 0) != 0)
|
if (sysctl(mib, (u_int)(sizeof(mib) / sizeof(mib[0])), path, &size, NULL, 0) != 0)
|
||||||
@ -626,8 +631,7 @@ int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
|
|||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
WAI_NOINLINE
|
WAI_NOINLINE WAI_FUNCSPEC
|
||||||
WAI_FUNCSPEC
|
|
||||||
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
|
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
|
||||||
{
|
{
|
||||||
char buffer[PATH_MAX];
|
char buffer[PATH_MAX];
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
// (‑●‑●)> released under the WTFPL v2 license, by Gregory Pakosz (@gpakosz)
|
// (‑●‑●)> dual licensed under the WTFPL v2 and MIT licenses
|
||||||
|
// without any warranty.
|
||||||
|
// by Gregory Pakosz (@gpakosz)
|
||||||
// https://github.com/gpakosz/whereami
|
// https://github.com/gpakosz/whereami
|
||||||
|
|
||||||
#ifndef WHEREAMI_H
|
#ifndef WHEREAMI_H
|
||||||
|
Loading…
Reference in New Issue
Block a user