Compare commits

...

8 Commits

Author SHA1 Message Date
6706e7e4c5 Merge branch 'master' of gitlab.2:f1x1t/whereami 2019-10-05 13:39:20 +03:00
08c6afcba2 Патч для GCC < 4.8 2019-10-05 13:38:11 +03:00
bd6cff26dd Установка заголовков 2019-10-05 12:03:41 +03:00
093a2efc08 Merge branch 'wip-cpp' 2019-10-05 11:24:04 +03:00
Gregory Pakosz
f3a86fdf17 Merge pull request #16 from marcIhm/master
fixed NetBSD support
2019-01-07 10:49:40 +01:00
Jan Beich
4414eb5812 fixed NetBSD support
- assume NetBSD >= 8.0
- for NetBSD < 8.0, define WAI_USE_PROC_SELF_EXE
2019-01-07 10:47:08 +01:00
Gregory Pakosz
e64e8b379b dual licensed under both the WTFPLv2 and MIT licenses 2018-12-30 23:05:43 +01:00
Gregory Pakosz
73eb7856dd enabled and fixed -Wshadow and -Wuseless-cast offences 2018-11-06 14:57:03 +01:00
8 changed files with 65 additions and 26 deletions

View File

@ -50,6 +50,9 @@ 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)
@ -106,4 +109,7 @@ 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()

18
LICENSE.MIT Normal file
View 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.

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

@ -12,6 +12,8 @@ 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 -std=c99
CXXFLAGS := -O2 -g -Wall -pedantic -Werror
CFLAGS := -O2 -g -Wall -pedantic -Werror -Wshadow -std=c99
CXXFLAGS := -O2 -g -Wall -pedantic -Werror -Wshadow -Wuseless-cast
ifeq ($(platform),linux)
LDFLAGS += -ldl

View File

@ -18,6 +18,13 @@ 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,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
// 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;
}
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)
#elif defined(__linux__) || defined(__CYGWIN__) || defined(__sun) || defined(WAI_USE_PROC_SELF_EXE)
#include <stdio.h>
#include <stdlib.h>
@ -245,15 +245,13 @@ 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 (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");
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)
{
uint64_t addr = (uint64_t)(uintptr_t)WAI_RETURN_ADDRESS();
uint64_t addr = (uintptr_t)WAI_RETURN_ADDRESS();
if (low <= addr && addr <= high)
{
char* resolved;
@ -346,11 +344,15 @@ 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;
}
@ -415,8 +417,7 @@ 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];
@ -587,7 +588,11 @@ 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)
@ -626,8 +631,7 @@ 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,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
#ifndef WHEREAMI_H