Compare commits

..

No commits in common. "master" and "wip-cpp" have entirely different histories.

8 changed files with 26 additions and 65 deletions

View File

@ -50,9 +50,6 @@ if(BUILD_EXAMPLES)
endif()
endif()
install(FILES ${CMAKE_SOURCE_DIR}/src/whereami.h COMPONENT headers
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
if(PKG_CONFIG_FOUND)
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)
@ -109,7 +106,4 @@ if(CMAKE_CXX_COMPILER)
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)
endif()
install(FILES ${CMAKE_SOURCE_DIR}/src/whereami++.h COMPONENT headers
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()

View File

@ -1,15 +1,15 @@
--------------------------------------------------------------------------------
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
1. Bla bla bla

View File

@ -1,18 +0,0 @@
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.

View File

@ -12,8 +12,6 @@ Supported platforms:
- Android
- QNX Neutrino
- FreeBSD
- NetBSD
- DragonFly BSD
- SunOS
Just drop `whereami.h` and `whereami.c` into your build and get started. (see

View File

@ -45,8 +45,8 @@ buildir := $(realpath .)/build
binsubdir := $(platform)-$(architecture)
bindir := $(prefix)/bin/$(binsubdir)
CFLAGS := -O2 -g -Wall -pedantic -Werror -Wshadow -std=c99
CXXFLAGS := -O2 -g -Wall -pedantic -Werror -Wshadow -Wuseless-cast
CFLAGS := -O2 -g -Wall -pedantic -Werror -std=c99
CXXFLAGS := -O2 -g -Wall -pedantic -Werror
ifeq ($(platform),linux)
LDFLAGS += -ldl

View File

@ -18,13 +18,6 @@ typedef WHEREAMI_STRING_T whereami_string_t;
#define WHEREAMI_CXX11
#endif
#if defined(__GNUC__)
# if !((__GNUC__ * 100 + __GNUC_MINOR__) < 408)
#undef WHEREAMI_CXX11
# endif
#endif
namespace whereami {
class whereami_path_t

View File

@ -1,6 +1,4 @@
// (‑●‑●)> dual licensed under the WTFPL v2 and MIT licenses
// without any warranty.
// by Gregory Pakosz (@gpakosz)
// (‑●‑●)> released under the WTFPL v2 license, by Gregory Pakosz (@gpakosz)
// https://github.com/gpakosz/whereami
// in case you want to #include "whereami.c" in a larger compilation unit
@ -138,13 +136,15 @@ static int WAI_PREFIX(getModulePath_)(HMODULE module, char* out, int capacity, i
return length;
}
WAI_NOINLINE WAI_FUNCSPEC
WAI_NOINLINE
WAI_FUNCSPEC
int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
{
return WAI_PREFIX(getModulePath_)(NULL, out, capacity, dirname_length);
}
WAI_NOINLINE WAI_FUNCSPEC
WAI_NOINLINE
WAI_FUNCSPEC
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
{
HMODULE module;
@ -165,7 +165,7 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
return length;
}
#elif defined(__linux__) || defined(__CYGWIN__) || defined(__sun) || defined(WAI_USE_PROC_SELF_EXE)
#elif defined(__linux__) || defined(__CYGWIN__) || defined(__sun)
#include <stdio.h>
#include <stdlib.h>
@ -245,13 +245,15 @@ int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
#include <unistd.h>
#endif
WAI_NOINLINE WAI_FUNCSPEC
WAI_NOINLINE
WAI_FUNCSPEC
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
{
int length = -1;
FILE* maps = NULL;
int i;
for (int r = 0; r < WAI_PROC_SELF_MAPS_RETRY; ++r)
for (i = 0; i < WAI_PROC_SELF_MAPS_RETRY; ++i)
{
maps = fopen(WAI_PROC_SELF_MAPS, "r");
if (!maps)
@ -272,7 +274,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)
{
uint64_t addr = (uintptr_t)WAI_RETURN_ADDRESS();
uint64_t addr = (uint64_t)(uintptr_t)WAI_RETURN_ADDRESS();
if (low <= addr && addr <= high)
{
char* resolved;
@ -344,15 +346,11 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
}
fclose(maps);
maps = NULL;
if (length != -1)
break;
}
if (maps)
fclose(maps);
return length;
}
@ -417,7 +415,8 @@ int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
return length;
}
WAI_NOINLINE WAI_FUNCSPEC
WAI_NOINLINE
WAI_FUNCSPEC
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
{
char buffer[PATH_MAX];
@ -588,11 +587,7 @@ int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
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 };
#endif
size_t size = sizeof(buffer1);
if (sysctl(mib, (u_int)(sizeof(mib) / sizeof(mib[0])), path, &size, NULL, 0) != 0)
@ -631,7 +626,8 @@ int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
return length;
}
WAI_NOINLINE WAI_FUNCSPEC
WAI_NOINLINE
WAI_FUNCSPEC
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
{
char buffer[PATH_MAX];

View File

@ -1,6 +1,4 @@
// (‑●‑●)> dual licensed under the WTFPL v2 and MIT licenses
// without any warranty.
// by Gregory Pakosz (@gpakosz)
// (‑●‑●)> released under the WTFPL v2 license, by Gregory Pakosz (@gpakosz)
// https://github.com/gpakosz/whereami
#ifndef WHEREAMI_H