From 76a7a85f8bbd6d360491469fe2c73218a7bcca5d Mon Sep 17 00:00:00 2001 From: Gregory Pakosz Date: Thu, 5 Mar 2015 20:15:02 +0100 Subject: [PATCH] initial commit --- .gitattributes | 30 ++ .gitignore | 5 + LICENSE | 25 + README.md | 117 ++++ _gnu-make/Makefile | 65 +++ _ios-xcode/.gitignore | 2 + _ios-xcode/WhereAmI-Info.plist | 45 ++ _ios-xcode/WhereAmI.xcodeproj/project.pbxproj | 327 +++++++++++ .../contents.xcworkspacedata | 7 + _mac-xcode/.gitignore | 2 + _mac-xcode/WhereAmI.xcodeproj/project.pbxproj | 333 ++++++++++++ .../contents.xcworkspacedata | 7 + _win-vs12/.gitignore | 8 + _win-vs12/Common.props | 40 ++ _win-vs12/Debug.props | 21 + _win-vs12/Executable.vcxproj | 114 ++++ _win-vs12/Library.vcxproj | 113 ++++ _win-vs12/Release.props | 39 ++ _win-vs12/WhereAmI.sln | 38 ++ _win-vs12/x64.props | 16 + _win-vs12/x86.props | 19 + example/executable.c | 123 +++++ example/library.c | 83 +++ src/whereami.c | 506 ++++++++++++++++++ src/whereami.h | 64 +++ 25 files changed, 2149 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 _gnu-make/Makefile create mode 100644 _ios-xcode/.gitignore create mode 100644 _ios-xcode/WhereAmI-Info.plist create mode 100644 _ios-xcode/WhereAmI.xcodeproj/project.pbxproj create mode 100644 _ios-xcode/WhereAmI.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 _mac-xcode/.gitignore create mode 100644 _mac-xcode/WhereAmI.xcodeproj/project.pbxproj create mode 100644 _mac-xcode/WhereAmI.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 _win-vs12/.gitignore create mode 100644 _win-vs12/Common.props create mode 100644 _win-vs12/Debug.props create mode 100644 _win-vs12/Executable.vcxproj create mode 100644 _win-vs12/Library.vcxproj create mode 100644 _win-vs12/Release.props create mode 100644 _win-vs12/WhereAmI.sln create mode 100644 _win-vs12/x64.props create mode 100644 _win-vs12/x86.props create mode 100644 example/executable.c create mode 100644 example/library.c create mode 100644 src/whereami.c create mode 100644 src/whereami.h diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8b92a98 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,30 @@ +* text=auto + +# sources +*.h text diff=cpp +*.c text diff=cpp +*.cpp text diff=cpp +*.rb text diff=ruby +*.html text diff=html +*.m text diff=objc + +# shell scripts +*.sh eol=lf + +# GNU Makefile +Makefile text eol=lf + +# Autotools +*.am text eol=lf + +# Android +*.mk text eol=lf + +# Xcode files +*.pbxproj text eol=lf merge=union + +# Visual Studio files +*.sln text eol=crlf merge=union +*.vcxproj text eol=crlf merge=union +*.vcxproj.filters text eol=crlf merge=union +*.props text eol=crlf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d8107df --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.DS_Store +*~ +*.swp + +/bin diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1c594b3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,25 @@ +-------------------------------------------------------------------------------- + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + + 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 + + 0. You just DO WHAT THE FUCK YOU WANT TO. + 1. Bla bla bla + 2. Montesqieu et camembert, vive la France, zut alors! + +-------------------------------------------------------------------------------- + +WTFPLv2 is very permissive, see http://www.wtfpl.net/faq/ + +However, if this WTFPLV2 is REALLY a blocker and is the reason you can't use +this project, contact me and I'll dual license it. + +-------------------------------------------------------------------------------- diff --git a/README.md b/README.md new file mode 100644 index 0000000..91ca935 --- /dev/null +++ b/README.md @@ -0,0 +1,117 @@ +# Where Am I? + +A drop-in two files library to locate the current executable and the current +module on the file system. + +Supported platforms: + +- Windows +- Linux +- Mac +- iOS +- Android +- QNX Neutrino + +Just drop `whereami.h` and `whereami.c` into your build and get started. (see +also [customizing compilation]) + +[customizing compilation]: #customizing-compilation + +-------------------------------------------------------------------------------- + +## Usage + +- `wai_getExecutablePath()` returns the path of the enclosing executable +- `wai_getModulePath()` returns the path of the enclosing module + +Example usage: + +- first call `int length = wai_getExecutablePath(NULL, 0, NULL);` to retrieve + the length of the path +- allocate the destination buffer with `path = (char*)malloc(length + 1);` +- call `wai_getExecutablePath(path, length, &dirname_length)` again to retrieve + the path +- add a terminal `NUL` character with `path[length] = '\0';` + +Here is the output of the example: + + $ make -C _gnu-make + $ cp ./bin/mac-x86_64/library.dylib /tmp/ + $ ./bin/mac-x86_64/executable --load-library=/tmp/library.dylib + + executable path: /Users/gregory/Projects/whereami/bin/mac-x86_64/executable + dirname: /Users/gregory/Projects/whereami/bin/mac-x86_64 + basename: executable + module path: /Users/gregory/Projects/whereami/bin/mac-x86_64/executable + dirname: /Users/gregory/Projects/whereami/bin/mac-x86_64 + basename: executable + + library loaded + executable path: /Users/gregory/Projects/whereami/bin/mac-x86_64/executable + dirname: /Users/gregory/Projects/whereami/bin/mac-x86_64 + basename: executable + module path: /private/tmp/library.dylib + dirname: /private/tmp + basename: library.dylib + library unloaded + +-------------------------------------------------------------------------------- + +## Customizing compilation + +You can customize the library's behavior by defining the following macros: + +- `WAI_FUNCSPEC` +- `WAI_PREFIX` +- `WAI_MALLOC` +- `WAI_REALLOC` +- `WAI_FREE` + +## Compiling for Windows + +There is a Visual Studio 2013 solution in the `_win-vs12/` folder. + +## Compiling for Linux or Mac + +There is a GNU Make 3.81 `MakeFile` in the `_gnu-make/` folder: + + $ make -C _gnu-make/ + +## Compiling for Mac + +See above if you want to compile from command line. Otherwise there is an Xcode +project located in the `_mac-xcode/` folder. + +## Compiling for iOS + +There is an Xcode project located in the `_ios-xcode/` folder. + +If you prefer compiling from command line and deploying to a jailbroken device +through SSH, use: + + $ make -C _gnu-make/ binsubdir=ios CC="$(xcrun --sdk iphoneos --find clang) -isysroot $(xcrun --sdk iphoneos --show-sdk-path) -arch armv7 -arch armv7s -arch arm64" postbuild="codesign -s 'iPhone Developer'" + +## Compiling for Android + +You will have to install the Android NDK, and point the `$NDK_ROOT` environment +variable to the NDK path: e.g. `export NDK_ROOT=/opt/android-ndk` (without a +trailing `/` character). + +Next, the easy way is to make a standalone Android toolchain with the following +command: + + $ $NDK_ROOT/build/tools/make-standalone-toolchain.sh --system=$(uname -s | tr [A-Z] [a-z])-$(uname -m) --platform=android-3 --arch=arm --install-dir=/tmp/android + +Now you can compile the self test and self benchmark programs by running: + + $ make -C _gnu-make/ libsuffix=.so binsubdir=android CC=/tmp/android/bin/arm-linux-androideabi-gcc CFLAGS='-march=armv7-a -mfloat-abi=softfp -O2' + +-------------------------------------------------------------------------------- + +If you find this library useful and decide to use it in your own projects please +drop me a line [@gpakosz]. + +If you use it in a commercial project, consider using [Gittip]. + +[@gpakosz]: https://twitter.com/gpakosz +[Gittip]: https://www.gittip.com/gpakosz/ diff --git a/_gnu-make/Makefile b/_gnu-make/Makefile new file mode 100644 index 0000000..06fa115 --- /dev/null +++ b/_gnu-make/Makefile @@ -0,0 +1,65 @@ +.PHONY: build clean + +# directories +ifeq ($(realpath .),) + $(error your version of Make doesn't support $$(realpath names...) - please use GNU Make 3.81 or later) +endif + +ifeq ($(platform),) + __uname_s := $(shell sh -c 'uname -s 2>/dev/null | tr [A-Z] [a-z] || echo unknown-platform') + __uname_m := $(shell sh -c 'uname -m 2>/dev/null | tr [A-Z] [a-z] || echo unknown-architecture') + + ifeq ($(__uname_s),linux) + override platform := linux + override architecture := $(__uname_m) + endif + ifeq ($(__uname_s),darwin) + override platform := mac + override architecture := $(__uname_m) + endif +endif +ifeq ($(architecture),) + override architecture := unknown-architecture +endif + +prefix := $(realpath ..) +srcdir := $(realpath ../src) +exampledir := $(realpath ../example) +testdir := $(realpath ../test) +buildir := $(realpath .)/build +binsubdir := $(platform)-$(architecture) +bindir := $(prefix)/bin/$(binsubdir) + +CFLAGS := -O2 -g + +ifeq ($(platform),linux) +override LDFLAGS := $(LDFLAGS) -ldl +endif + +ifeq ($(platform),mac) +libsuffix := .dylib +else +libsuffix := .so +endif + +.PHONY: build-executable +build: build-executable +build-executable: $(bindir)/executable + +$(bindir)/executable: $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/executable.c + mkdir -p $(@D) + $(CC) -o $@ -I $(srcdir) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fpic $(filter-out %.h,$^) + $(if $(postbuild),$(postbuild) $@) + +.PHONY: build-library +build: build-library +build-library: $(bindir)/library$(libsuffix) + +$(bindir)/library$(libsuffix): $(srcdir)/whereami.c $(srcdir)/whereami.h $(exampledir)/library.c + mkdir -p $(@D) + $(CC) -shared -o $@ -I $(srcdir) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fpic $(filter-out %.h,$^) + $(if $(postbuild),$(postbuild) $@) + +clean: + rm -rf $(buildir) + rm -rf $(bindir) diff --git a/_ios-xcode/.gitignore b/_ios-xcode/.gitignore new file mode 100644 index 0000000..8e82f86 --- /dev/null +++ b/_ios-xcode/.gitignore @@ -0,0 +1,2 @@ +xcuserdata/ +xcshareddata/ diff --git a/_ios-xcode/WhereAmI-Info.plist b/_ios-xcode/WhereAmI-Info.plist new file mode 100644 index 0000000..df31a64 --- /dev/null +++ b/_ios-xcode/WhereAmI-Info.plist @@ -0,0 +1,45 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + ${PRODUCT_NAME} + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + net.pempek.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/_ios-xcode/WhereAmI.xcodeproj/project.pbxproj b/_ios-xcode/WhereAmI.xcodeproj/project.pbxproj new file mode 100644 index 0000000..4ff66fd --- /dev/null +++ b/_ios-xcode/WhereAmI.xcodeproj/project.pbxproj @@ -0,0 +1,327 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 1A1E0A8D1A4486A300611947 /* whereami.c in Sources */ = {isa = PBXBuildFile; fileRef = 1A1E0A8B1A4486A300611947 /* whereami.c */; }; + 1A1E0A8F1A4486A900611947 /* executable.c in Sources */ = {isa = PBXBuildFile; fileRef = 1A1E0A8E1A4486A900611947 /* executable.c */; }; + 1A1E0AAC1A4486FB00611947 /* library.c in Sources */ = {isa = PBXBuildFile; fileRef = 1A1E0AAB1A4486FB00611947 /* library.c */; }; + 1A1E0AAD1A44880600611947 /* whereami.c in Sources */ = {isa = PBXBuildFile; fileRef = 1A1E0A8B1A4486A300611947 /* whereami.c */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 1A1E0A921A4486E800611947 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = "include/$(PRODUCT_NAME)"; + dstSubfolderSpec = 16; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 1A1E0A891A44868400611947 /* WhereAmI-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "WhereAmI-Info.plist"; sourceTree = ""; }; + 1A1E0A8B1A4486A300611947 /* whereami.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = whereami.c; sourceTree = ""; }; + 1A1E0A8C1A4486A300611947 /* whereami.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = whereami.h; sourceTree = ""; }; + 1A1E0A8E1A4486A900611947 /* executable.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = executable.c; sourceTree = ""; }; + 1A1E0A941A4486E800611947 /* library.dylib */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = library.dylib; sourceTree = BUILT_PRODUCTS_DIR; }; + 1A1E0AAB1A4486FB00611947 /* library.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = library.c; sourceTree = ""; }; + 1A98F9C917A4018400BF09FF /* executable.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = executable.app; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 1A1E0A911A4486E800611947 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 1A98F9C617A4018400BF09FF /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 1A7335C3182EC2E000691A33 /* src */ = { + isa = PBXGroup; + children = ( + 1A1E0A8B1A4486A300611947 /* whereami.c */, + 1A1E0A8C1A4486A300611947 /* whereami.h */, + ); + name = src; + path = ../src; + sourceTree = ""; + }; + 1A7335C4182EC30100691A33 /* example */ = { + isa = PBXGroup; + children = ( + 1A1E0AAB1A4486FB00611947 /* library.c */, + 1A1E0A8E1A4486A900611947 /* executable.c */, + ); + name = example; + path = ../example; + sourceTree = ""; + }; + 1A98F9C017A4018400BF09FF = { + isa = PBXGroup; + children = ( + 1A1E0A891A44868400611947 /* WhereAmI-Info.plist */, + 1A7335C3182EC2E000691A33 /* src */, + 1A7335C4182EC30100691A33 /* example */, + 1A98F9CA17A4018400BF09FF /* Products */, + ); + sourceTree = ""; + }; + 1A98F9CA17A4018400BF09FF /* Products */ = { + isa = PBXGroup; + children = ( + 1A98F9C917A4018400BF09FF /* executable.app */, + 1A1E0A941A4486E800611947 /* library.dylib */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 1A1E0A931A4486E800611947 /* library */ = { + isa = PBXNativeTarget; + buildConfigurationList = 1A1E0AA51A4486E900611947 /* Build configuration list for PBXNativeTarget "library" */; + buildPhases = ( + 1A1E0A901A4486E800611947 /* Sources */, + 1A1E0A911A4486E800611947 /* Frameworks */, + 1A1E0A921A4486E800611947 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = library; + productName = library; + productReference = 1A1E0A941A4486E800611947 /* library.dylib */; + productType = "com.apple.product-type.library.static"; + }; + 1A98F9C817A4018400BF09FF /* executable */ = { + isa = PBXNativeTarget; + buildConfigurationList = 1A98F9E617A4018400BF09FF /* Build configuration list for PBXNativeTarget "executable" */; + buildPhases = ( + 1A98F9C517A4018400BF09FF /* Sources */, + 1A98F9C617A4018400BF09FF /* Frameworks */, + 1A98F9C717A4018400BF09FF /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = executable; + productName = WhereAmI; + productReference = 1A98F9C917A4018400BF09FF /* executable.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 1A98F9C117A4018400BF09FF /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0460; + ORGANIZATIONNAME = "Gregory Pakosz"; + TargetAttributes = { + 1A1E0A931A4486E800611947 = { + CreatedOnToolsVersion = 6.1.1; + }; + }; + }; + buildConfigurationList = 1A98F9C417A4018400BF09FF /* Build configuration list for PBXProject "WhereAmI" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 1A98F9C017A4018400BF09FF; + productRefGroup = 1A98F9CA17A4018400BF09FF /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 1A98F9C817A4018400BF09FF /* executable */, + 1A1E0A931A4486E800611947 /* library */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 1A98F9C717A4018400BF09FF /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 1A1E0A901A4486E800611947 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 1A1E0AAC1A4486FB00611947 /* library.c in Sources */, + 1A1E0AAD1A44880600611947 /* whereami.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 1A98F9C517A4018400BF09FF /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 1A1E0A8D1A4486A300611947 /* whereami.c in Sources */, + 1A1E0A8F1A4486A900611947 /* executable.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 1A1E0AA61A4486E900611947 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + EXECUTABLE_EXTENSION = dylib; + EXECUTABLE_PREFIX = ""; + MACH_O_TYPE = mh_dylib; + }; + name = Debug; + }; + 1A1E0AA71A4486E900611947 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + EXECUTABLE_EXTENSION = dylib; + EXECUTABLE_PREFIX = ""; + MACH_O_TYPE = mh_dylib; + }; + name = Release; + }; + 1A98F9E417A4018400BF09FF /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + ../src, + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + ); + INFOPLIST_FILE = "WhereAmI-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 5.0; + ONLY_ACTIVE_ARCH = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 1A98F9E517A4018400BF09FF /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + COPY_PHASE_STRIP = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_OPTIMIZATION_LEVEL = 2; + GCC_PREPROCESSOR_DEFINITIONS = NDEBUG; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + ../src, + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + ); + INFOPLIST_FILE = "WhereAmI-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 5.0; + OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 1A98F9E717A4018400BF09FF /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Debug; + }; + 1A98F9E817A4018400BF09FF /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 1A1E0AA51A4486E900611947 /* Build configuration list for PBXNativeTarget "library" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1A1E0AA61A4486E900611947 /* Debug */, + 1A1E0AA71A4486E900611947 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 1A98F9C417A4018400BF09FF /* Build configuration list for PBXProject "WhereAmI" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1A98F9E417A4018400BF09FF /* Debug */, + 1A98F9E517A4018400BF09FF /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 1A98F9E617A4018400BF09FF /* Build configuration list for PBXNativeTarget "executable" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1A98F9E717A4018400BF09FF /* Debug */, + 1A98F9E817A4018400BF09FF /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 1A98F9C117A4018400BF09FF /* Project object */; +} diff --git a/_ios-xcode/WhereAmI.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/_ios-xcode/WhereAmI.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..3524150 --- /dev/null +++ b/_ios-xcode/WhereAmI.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/_mac-xcode/.gitignore b/_mac-xcode/.gitignore new file mode 100644 index 0000000..8e82f86 --- /dev/null +++ b/_mac-xcode/.gitignore @@ -0,0 +1,2 @@ +xcuserdata/ +xcshareddata/ diff --git a/_mac-xcode/WhereAmI.xcodeproj/project.pbxproj b/_mac-xcode/WhereAmI.xcodeproj/project.pbxproj new file mode 100644 index 0000000..e3549d9 --- /dev/null +++ b/_mac-xcode/WhereAmI.xcodeproj/project.pbxproj @@ -0,0 +1,333 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 1A1E0A801A4484DC00611947 /* whereami.c in Sources */ = {isa = PBXBuildFile; fileRef = 1A1E0A7E1A4484DC00611947 /* whereami.c */; }; + 1A1E0A811A4484DC00611947 /* whereami.c in Sources */ = {isa = PBXBuildFile; fileRef = 1A1E0A7E1A4484DC00611947 /* whereami.c */; }; + 1A1E0A821A4484DC00611947 /* whereami.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A1E0A7F1A4484DC00611947 /* whereami.h */; }; + 1A1E0A851A4484ED00611947 /* executable.c in Sources */ = {isa = PBXBuildFile; fileRef = 1A1E0A831A4484EA00611947 /* executable.c */; }; + 1A1E0A861A4484EF00611947 /* library.c in Sources */ = {isa = PBXBuildFile; fileRef = 1A1E0A841A4484EA00611947 /* library.c */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 1A98F9FF17A4249200BF09FF /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 1A1E0A7A1A44841F00611947 /* library.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = library.dylib; sourceTree = BUILT_PRODUCTS_DIR; }; + 1A1E0A7E1A4484DC00611947 /* whereami.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = whereami.c; sourceTree = ""; }; + 1A1E0A7F1A4484DC00611947 /* whereami.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = whereami.h; sourceTree = ""; }; + 1A1E0A831A4484EA00611947 /* executable.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = executable.c; sourceTree = ""; }; + 1A1E0A841A4484EA00611947 /* library.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = library.c; sourceTree = ""; }; + 1A98FA0117A4249200BF09FF /* executable */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = executable; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 1A1E0A771A44841F00611947 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 1A98F9FE17A4249200BF09FF /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 1A42F178182EB9EF00F3880C /* src */ = { + isa = PBXGroup; + children = ( + 1A1E0A7E1A4484DC00611947 /* whereami.c */, + 1A1E0A7F1A4484DC00611947 /* whereami.h */, + ); + name = src; + path = ../src; + sourceTree = ""; + }; + 1A42F17A182EB9FE00F3880C /* example */ = { + isa = PBXGroup; + children = ( + 1A1E0A831A4484EA00611947 /* executable.c */, + 1A1E0A841A4484EA00611947 /* library.c */, + ); + name = example; + path = ../example; + sourceTree = ""; + }; + 1A98F9F817A4249200BF09FF = { + isa = PBXGroup; + children = ( + 1A42F178182EB9EF00F3880C /* src */, + 1A42F17A182EB9FE00F3880C /* example */, + 1A98FA0217A4249200BF09FF /* Products */, + ); + sourceTree = ""; + }; + 1A98FA0217A4249200BF09FF /* Products */ = { + isa = PBXGroup; + children = ( + 1A98FA0117A4249200BF09FF /* executable */, + 1A1E0A7A1A44841F00611947 /* library.dylib */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 1A1E0A781A44841F00611947 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 1A1E0A821A4484DC00611947 /* whereami.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 1A1E0A791A44841F00611947 /* library */ = { + isa = PBXNativeTarget; + buildConfigurationList = 1A1E0A7B1A44841F00611947 /* Build configuration list for PBXNativeTarget "library" */; + buildPhases = ( + 1A1E0A761A44841F00611947 /* Sources */, + 1A1E0A771A44841F00611947 /* Frameworks */, + 1A1E0A781A44841F00611947 /* Headers */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = library; + productName = library; + productReference = 1A1E0A7A1A44841F00611947 /* library.dylib */; + productType = "com.apple.product-type.library.dynamic"; + }; + 1A98FA0017A4249200BF09FF /* executable */ = { + isa = PBXNativeTarget; + buildConfigurationList = 1A98FA0A17A4249200BF09FF /* Build configuration list for PBXNativeTarget "executable" */; + buildPhases = ( + 1A98F9FD17A4249200BF09FF /* Sources */, + 1A98F9FE17A4249200BF09FF /* Frameworks */, + 1A98F9FF17A4249200BF09FF /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = executable; + productName = WhereAmI; + productReference = 1A98FA0117A4249200BF09FF /* executable */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 1A98F9F917A4249200BF09FF /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0610; + ORGANIZATIONNAME = "Gregory Pakosz"; + TargetAttributes = { + 1A1E0A791A44841F00611947 = { + CreatedOnToolsVersion = 6.1.1; + }; + }; + }; + buildConfigurationList = 1A98F9FC17A4249200BF09FF /* Build configuration list for PBXProject "WhereAmI" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 1A98F9F817A4249200BF09FF; + productRefGroup = 1A98FA0217A4249200BF09FF /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 1A98FA0017A4249200BF09FF /* executable */, + 1A1E0A791A44841F00611947 /* library */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 1A1E0A761A44841F00611947 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 1A1E0A811A4484DC00611947 /* whereami.c in Sources */, + 1A1E0A861A4484EF00611947 /* library.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 1A98F9FD17A4249200BF09FF /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 1A1E0A801A4484DC00611947 /* whereami.c in Sources */, + 1A1E0A851A4484ED00611947 /* executable.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 1A1E0A7C1A44841F00611947 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 1A1E0A7D1A44841F00611947 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; + 1A98FA0817A4249200BF09FF /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "compiler-default"; + CLANG_CXX_LIBRARY = "compiler-default"; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + ../src, + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + ); + MACOSX_DEPLOYMENT_TARGET = 10.8; + ONLY_ACTIVE_ARCH = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + }; + name = Debug; + }; + 1A98FA0917A4249200BF09FF /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "compiler-default"; + CLANG_CXX_LIBRARY = "compiler-default"; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_OPTIMIZATION_LEVEL = 2; + GCC_PREPROCESSOR_DEFINITIONS = NDEBUG; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + ../src, + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + ); + MACOSX_DEPLOYMENT_TARGET = 10.8; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + }; + name = Release; + }; + 1A98FA0B17A4249200BF09FF /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Debug; + }; + 1A98FA0C17A4249200BF09FF /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 1A1E0A7B1A44841F00611947 /* Build configuration list for PBXNativeTarget "library" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1A1E0A7C1A44841F00611947 /* Debug */, + 1A1E0A7D1A44841F00611947 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 1A98F9FC17A4249200BF09FF /* Build configuration list for PBXProject "WhereAmI" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1A98FA0817A4249200BF09FF /* Debug */, + 1A98FA0917A4249200BF09FF /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 1A98FA0A17A4249200BF09FF /* Build configuration list for PBXNativeTarget "executable" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1A98FA0B17A4249200BF09FF /* Debug */, + 1A98FA0C17A4249200BF09FF /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 1A98F9F917A4249200BF09FF /* Project object */; +} diff --git a/_mac-xcode/WhereAmI.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/_mac-xcode/WhereAmI.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..3524150 --- /dev/null +++ b/_mac-xcode/WhereAmI.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/_win-vs12/.gitignore b/_win-vs12/.gitignore new file mode 100644 index 0000000..135eda3 --- /dev/null +++ b/_win-vs12/.gitignore @@ -0,0 +1,8 @@ +/build +/ipch + +*.suo +*.sdf +*.opensdf +*.user +*.sln.docstates diff --git a/_win-vs12/Common.props b/_win-vs12/Common.props new file mode 100644 index 0000000..457886e --- /dev/null +++ b/_win-vs12/Common.props @@ -0,0 +1,40 @@ + + + + ..\bin\Windows$(PLATFORM_SUFFIX)-$(ARCH)$(CONF_SUFFIX) + ..\lib\Windows$(PLATFORM_SUFFIX)-$(ARCH)-vs11$(CONF_SUFFIX) + build\$(ProjectName)-win$(PLATFORM_SUFFIX)-$(ARCH)-vs11$(CONF_SUFFIX) + + + $(BUILD_DIR)\ + $(BIN_DIR)\ + false + + + + _CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + /we4013 /wd4820 /we4289 /wd4342 /wd4347 /wd4514 /we4545 /we4546 /we4547 /we4548 /we4549 /we4619 /we4623 /we4625 /we4626 /wd4710 /we4836 /we4905 /we4906 /we4928 /we4946 /wd4986 /wd4711 /wd4350 /wd4255 /wd4668 + NotUsing + true + EnableAllWarnings + false + + + true + Console + /time %(AdditionalOptions) + + + + + $(BIN_DIR) + + + $(LIB_DIR) + + + $(BUILD_DIR) + + + \ No newline at end of file diff --git a/_win-vs12/Debug.props b/_win-vs12/Debug.props new file mode 100644 index 0000000..116ddaf --- /dev/null +++ b/_win-vs12/Debug.props @@ -0,0 +1,21 @@ + + + + -Debug + + + + Disabled + Level3 + ProgramDatabase + MultiThreadedDebug + true + OnlyExplicitInline + + + + + $(CONF_SUFFIX) + + + diff --git a/_win-vs12/Executable.vcxproj b/_win-vs12/Executable.vcxproj new file mode 100644 index 0000000..46476d1 --- /dev/null +++ b/_win-vs12/Executable.vcxproj @@ -0,0 +1,114 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + + + + + + + + Win32Proj + WhereAmI + {4F614870-9A09-4661-9963-7DF73803240B} + + + + Application + true + v120_xp + + + Application + true + v120_xp + + + Application + false + v120_xp + true + + + Application + false + v120_xp + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ../src;%(AdditionalIncludeDirectories) + + + + + ../src;%(AdditionalIncludeDirectories) + + + + + /we4013 /wd4820 /we4289 /wd4342 /wd4347 /wd4514 /we4545 /we4546 /we4547 /we4548 /we4549 /we4619 /we4623 /we4625 /we4626 /wd4710 /we4836 /we4905 /we4906 /we4928 /we4946 /wd4986 /wd4711 /wd4350 /Qvec-report:2 + ../src;%(AdditionalIncludeDirectories) + /we4013 /wd4820 /we4289 /wd4342 /wd4347 /wd4514 /we4545 /we4546 /we4547 /we4548 /we4549 /we4619 /we4623 /we4625 /we4626 /wd4710 /we4836 /we4905 /we4906 /we4928 /we4946 /wd4986 /wd4711 /wd4350 /wd4255 /wd4668 /Qvec-report:2 + + + + + ../src;%(AdditionalIncludeDirectories) + /we4013 /wd4820 /we4289 /wd4342 /wd4347 /wd4514 /we4545 /we4546 /we4547 /we4548 /we4549 /we4619 /we4623 /we4625 /we4626 /wd4710 /we4836 /we4905 /we4906 /we4928 /we4946 /wd4986 /wd4711 /wd4350 /wd4255 /wd4668 /Qvec-report:2 + + + + + + diff --git a/_win-vs12/Library.vcxproj b/_win-vs12/Library.vcxproj new file mode 100644 index 0000000..5707405 --- /dev/null +++ b/_win-vs12/Library.vcxproj @@ -0,0 +1,113 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + + + + + + + + Win32Proj + WhereAmI + {D53572AD-B43A-4507-9BB2-F330F942912B} + + + + DynamicLibrary + true + v120_xp + + + DynamicLibrary + true + v120_xp + + + DynamicLibrary + false + true + v120_xp + + + DynamicLibrary + false + true + v120_xp + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ../src;%(AdditionalIncludeDirectories) + + + + + ../src;%(AdditionalIncludeDirectories) + + + + + ../src;%(AdditionalIncludeDirectories) + /we4013 /wd4820 /we4289 /wd4342 /wd4347 /wd4514 /we4545 /we4546 /we4547 /we4548 /we4549 /we4619 /we4623 /we4625 /we4626 /wd4710 /we4836 /we4905 /we4906 /we4928 /we4946 /wd4986 /wd4711 /wd4350 /wd4255 /wd4668 /Qvec-report:2 + + + + + ../src;%(AdditionalIncludeDirectories) + /we4013 /wd4820 /we4289 /wd4342 /wd4347 /wd4514 /we4545 /we4546 /we4547 /we4548 /we4549 /we4619 /we4623 /we4625 /we4626 /wd4710 /we4836 /we4905 /we4906 /we4928 /we4946 /wd4986 /wd4711 /wd4350 /wd4255 /wd4668 /Qvec-report:2 + + + + + + diff --git a/_win-vs12/Release.props b/_win-vs12/Release.props new file mode 100644 index 0000000..88bc1c2 --- /dev/null +++ b/_win-vs12/Release.props @@ -0,0 +1,39 @@ + + + + + + + false + + + + MaxSpeed + AnySuitable + true + Speed + true + true + true + NDEBUG;%(PreprocessorDefinitions) + true + Level3 + ProgramDatabase + MultiThreaded + false + /d2Zi+ %(AdditionalOptions) + + + UseLinkTimeCodeGeneration + true + + + true + + + + + $(CONF_SUFFIX) + + + diff --git a/_win-vs12/WhereAmI.sln b/_win-vs12/WhereAmI.sln new file mode 100644 index 0000000..20360e9 --- /dev/null +++ b/_win-vs12/WhereAmI.sln @@ -0,0 +1,38 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Executable", "Executable.vcxproj", "{4F614870-9A09-4661-9963-7DF73803240B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Library", "Library.vcxproj", "{D53572AD-B43A-4507-9BB2-F330F942912B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4F614870-9A09-4661-9963-7DF73803240B}.Debug|Win32.ActiveCfg = Debug|Win32 + {4F614870-9A09-4661-9963-7DF73803240B}.Debug|Win32.Build.0 = Debug|Win32 + {4F614870-9A09-4661-9963-7DF73803240B}.Debug|x64.ActiveCfg = Debug|x64 + {4F614870-9A09-4661-9963-7DF73803240B}.Debug|x64.Build.0 = Debug|x64 + {4F614870-9A09-4661-9963-7DF73803240B}.Release|Win32.ActiveCfg = Release|Win32 + {4F614870-9A09-4661-9963-7DF73803240B}.Release|Win32.Build.0 = Release|Win32 + {4F614870-9A09-4661-9963-7DF73803240B}.Release|x64.ActiveCfg = Release|x64 + {4F614870-9A09-4661-9963-7DF73803240B}.Release|x64.Build.0 = Release|x64 + {D53572AD-B43A-4507-9BB2-F330F942912B}.Debug|Win32.ActiveCfg = Debug|Win32 + {D53572AD-B43A-4507-9BB2-F330F942912B}.Debug|Win32.Build.0 = Debug|Win32 + {D53572AD-B43A-4507-9BB2-F330F942912B}.Debug|x64.ActiveCfg = Debug|x64 + {D53572AD-B43A-4507-9BB2-F330F942912B}.Debug|x64.Build.0 = Debug|x64 + {D53572AD-B43A-4507-9BB2-F330F942912B}.Release|Win32.ActiveCfg = Release|Win32 + {D53572AD-B43A-4507-9BB2-F330F942912B}.Release|Win32.Build.0 = Release|Win32 + {D53572AD-B43A-4507-9BB2-F330F942912B}.Release|x64.ActiveCfg = Release|x64 + {D53572AD-B43A-4507-9BB2-F330F942912B}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/_win-vs12/x64.props b/_win-vs12/x64.props new file mode 100644 index 0000000..9d4d031 --- /dev/null +++ b/_win-vs12/x64.props @@ -0,0 +1,16 @@ + + + + x64 + + + + MachineX64 + + + + + $(ARCH) + + + diff --git a/_win-vs12/x86.props b/_win-vs12/x86.props new file mode 100644 index 0000000..d1f9bd7 --- /dev/null +++ b/_win-vs12/x86.props @@ -0,0 +1,19 @@ + + + + x86 + + + + MachineX86 + + + StreamingSIMDExtensions2 + + + + + $(ARCH) + + + \ No newline at end of file diff --git a/example/executable.c b/example/executable.c new file mode 100644 index 0000000..afa39a3 --- /dev/null +++ b/example/executable.c @@ -0,0 +1,123 @@ +#include +#include +#include + +#include + +#if defined(_WIN32) + +#define WIN32_LEAN_AND_MEAN +#if defined(_MSC_VER) +#pragma warning(push, 3) +#endif +#include + +#define RTLD_LAZY 1 +#define RTLD_NOW 2 +#define RTLD_GLOBAL 4 +#define RTLD_LOCAL 8 + +static void* dlopen(const char* fileName, int mode) +{ + wchar_t buffer[MAX_PATH]; + + if (MultiByteToWideChar(CP_UTF8, 0, fileName, -1, buffer, sizeof(buffer) / sizeof(*buffer))) + { + wchar_t buffer_[MAX_PATH]; + + GetFullPathNameW(buffer, sizeof(buffer_) / sizeof(*buffer_), buffer_, NULL); + + return (void*)LoadLibraryW(buffer_); + } + + return NULL; +} + +static int dlclose(void* handle) +{ + return FreeLibrary((HMODULE)handle) ? 0 : -1; +} + +static const char* dlerror(void) +{ + DWORD error; + + error = GetLastError(); + + if (error) + { + static char message[1024]; + DWORD length; + + length = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), message, sizeof(message), NULL); + + return message; + } + + return "no error"; +} + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + +#else + +#include + +#endif + +int main(int argc, char** argv) +{ + char* path = NULL; + int length, dirname_length; + int i; + + length = wai_getExecutablePath(NULL, 0, &dirname_length); + if (length > 0) + { + path = malloc(length + 1); + wai_getExecutablePath(path, length, &dirname_length); + path[length] = '\0'; + + printf("executable path: %s\n", path); + path[dirname_length] = '\0'; + printf(" dirname: %s\n", path); + printf(" basename: %s\n", path + dirname_length + 1); + free(path); + } + + length = wai_getModulePath(NULL, 0, &dirname_length); + if (length > 0) + { + path = malloc(length + 1); + wai_getModulePath(path, length, &dirname_length); + path[length] = '\0'; + + printf("module path: %s\n", path); + path[dirname_length] = '\0'; + printf(" dirname: %s\n", path); + printf(" basename: %s\n", path + dirname_length + 1); + free(path); + } + + for (i = 1; i < argc; ++i) + { + if (strncmp(argv[i], "--load-library=", 15) == 0) + { + char* name = argv[i] + 15; + void* handle; + + printf("\n"); + + handle = dlopen(name, RTLD_NOW); + if (!handle) + printf("failed to load library: %s\n", dlerror()); + + if (handle) + dlclose(handle); + } + } + + return 0; +} diff --git a/example/library.c b/example/library.c new file mode 100644 index 0000000..b07e876 --- /dev/null +++ b/example/library.c @@ -0,0 +1,83 @@ +#include +#include + +#include + +#if defined(__GNUC__) +__attribute__((constructor)) +#endif +static void load() +{ + char* path = NULL; + int length, dirname_length; + + printf("library loaded\n"); + + length = wai_getExecutablePath(NULL, 0, &dirname_length); + if (length > 0) + { + path = malloc(length + 1); + wai_getExecutablePath(path, length, &dirname_length); + path[length] = '\0'; + + printf("executable path: %s\n", path); + path[dirname_length] = '\0'; + printf(" dirname: %s\n", path); + printf(" basename: %s\n", path + dirname_length + 1); + free(path); + } + + length = wai_getModulePath(NULL, 0, &dirname_length); + if (length > 0) + { + path = malloc(length + 1); + wai_getModulePath(path, length, &dirname_length); + path[length] = '\0'; + + printf("module path: %s\n", path); + path[dirname_length] = '\0'; + printf(" dirname: %s\n", path); + printf(" basename: %s\n", path + dirname_length + 1); + free(path); + } +} + +#if defined(__GNUC__) +__attribute__((destructor)) +#endif +static void unload() +{ + printf("library unloaded\n"); +} + +#if defined(_WIN32) + +#define WIN32_LEAN_AND_MEAN +#if defined(_MSC_VER) +#pragma warning(push, 3) +#include +#endif + +BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + load(); + break; + case DLL_THREAD_ATTACH: + break; + case DLL_THREAD_DETACH: + break; + case DLL_PROCESS_DETACH: + unload(); + break; + } + return TRUE; +} + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + +#endif diff --git a/src/whereami.c b/src/whereami.c new file mode 100644 index 0000000..80eda1e --- /dev/null +++ b/src/whereami.c @@ -0,0 +1,506 @@ +// (‑●‑●)> released under the WTFPL v2 license, by Gregory Pakosz (@gpakosz) + +// in case you want to #include "whereami.c" in a larger compilation unit +#if !defined(WHEREAMI_H) +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(WAI_MALLOC) || !defined(WAI_FREE) || !defined(WAI_REALLOC) +#include +#endif + +#if !defined(WAI_MALLOC) +#define WAI_MALLOC(size) malloc(size) +#endif + +#if !defined(WAI_FREE) +#define WAI_FREE(p) free(p) +#endif + +#if !defined(WAI_REALLOC) +#define WAI_REALLOC(p, size) realloc(p, size) +#endif + +#if defined(_WIN32) + +#define WIN32_LEAN_AND_MEAN +#if defined(_MSC_VER) +#pragma warning(push, 3) +#endif +#include +#include +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + +#ifndef WAI_NOINLINE +#ifdef _MSC_VER +#define WAI_NOINLINE __declspec(noinline) +#endif +#endif + +static int WAI_PREFIX(getModulePath_)(HMODULE module, char* out, int capacity, int* dirname_length) +{ + wchar_t buffer1[MAX_PATH]; + wchar_t buffer2[MAX_PATH]; + wchar_t* path = NULL; + int length = -1; + + for (;;) + { + DWORD size; + int length_; + + size = GetModuleFileNameW(module, buffer1, sizeof(buffer1) / sizeof(buffer1[0])); + + if (size == 0) + break; + else if (size == (DWORD)(sizeof(buffer1) / sizeof(buffer1[0]))) + { + DWORD size_ = size; + do + { + size_ *= 2; + path = (wchar_t*)WAI_REALLOC(path, sizeof(wchar_t) * size_); + size = GetModuleFileNameW(NULL, path, size_); + } while (size == size_); + } + else + path = buffer1; + + _wfullpath(buffer2, path, MAX_PATH); + length_ = WideCharToMultiByte(CP_UTF8, 0, buffer2, -1, out, (DWORD)capacity, NULL, NULL); + + if (length_ == 0) + length_ = WideCharToMultiByte(CP_UTF8, 0, buffer2, -1, NULL, (DWORD)0, NULL, NULL); + if (length_ == 0) + break; + + if (length_ <= capacity && dirname_length) + { + int i; + + for (i = length_ - 1; i >= 0; --i) + { + if (out[i] == '\\') + { + *dirname_length = i; + break; + } + } + } + + length = length_; + + break; + } + + if (path != buffer1) + WAI_FREE(path); + + return length; +} + +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 +int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) +{ + HMODULE module; + int length = -1; + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable: 4054) +#endif + if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCTSTR)_ReturnAddress(), &module)) +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + { + length = WAI_PREFIX(getModulePath_)(module, out, capacity, dirname_length); + } + + return length; +} + +#elif defined(__linux__) + +#include +#include +#include +#include +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif +#include + +#if !defined(WAI_PROC_SELF_EXE) +#define WAI_PROC_SELF_EXE "/proc/self/exe" +#endif + +#ifndef WAI_NOINLINE +#ifdef __GNUC__ +#define WAI_NOINLINE __attribute__((noinline)) +#endif +#endif + +WAI_FUNCSPEC +int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length) +{ + char buffer[PATH_MAX]; + char* resolved = NULL; + int length = -1; + + for (;;) + { + resolved = realpath(WAI_PROC_SELF_EXE, buffer); + if (!resolved) + break; + + length = (int)strlen(resolved); + if (length <= capacity) + { + memcpy(out, resolved, length); + + if (dirname_length) + { + int i; + + for (i = length - 1; i >= 0; --i) + { + if (out[i] == '/') + { + *dirname_length = i; + break; + } + } + } + } + + break; + } + + return length; +} + +#if !defined(WAI_PROC_SELF_MAPS_RETRY) +#define WAI_PROC_SELF_MAPS_RETRY 5 +#endif + +#if !defined(WAI_PROC_SELF_MAPS) +#define WAI_PROC_SELF_MAPS "/proc/self/maps" +#endif + +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) + { + maps = fopen(WAI_PROC_SELF_MAPS, "r"); + if (!maps) + break; + + for (;;) + { + char buffer[PATH_MAX < 1024 ? 1024 : PATH_MAX]; + uint64_t low, high; + char perms[5]; + uint64_t offset; + uint32_t major, minor; + char path[PATH_MAX]; + uint32_t inode; + int count; + + if (!fgets(buffer, sizeof(buffer), maps)) + break; + + 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) __builtin_extract_return_addr(__builtin_return_address(0)); + if (low <= addr && addr <= high) + { + char* resolved; + + resolved = realpath(path, buffer); + if (!resolved) + break; + + length = (int)strlen(resolved); + if (length <= capacity) + { + memcpy(out, resolved, length); + + if (dirname_length) + { + int i; + + for (i = length - 1; i >= 0; --i) + { + if (out[i] == '/') + { + *dirname_length = i; + break; + } + } + } + } + + break; + } + } + } + + fclose(maps); + + if (length != -1) + break; + } + + return length; +} + +#elif defined(__APPLE__) + +#define _DARWIN_BETTER_REALPATH +#include +#include +#include +#include +#include + +#ifndef WAI_NOINLINE +#ifdef __GNUC__ +#define WAI_NOINLINE __attribute__((noinline)) +#endif +#endif + +WAI_FUNCSPEC +int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length) +{ + char buffer1[PATH_MAX]; + char buffer2[PATH_MAX]; + char* path = buffer1; + char* resolved = NULL; + int length = -1; + + for (;;) + { + uint32_t size = (uint32_t)sizeof(buffer1); + if (_NSGetExecutablePath(path, &size) == -1) + { + path = (char*)WAI_MALLOC(size); + if (!_NSGetExecutablePath(path, &size)) + break; + } + + resolved = realpath(path, buffer2); + if (!resolved) + break; + + length = (int)strlen(resolved); + if (length <= capacity) + { + memcpy(out, resolved, length); + + if (dirname_length) + { + int i; + + for (i = length - 1; i >= 0; --i) + { + if (out[i] == '/') + { + *dirname_length = i; + break; + } + } + } + } + + break; + } + + if (path != buffer1) + WAI_FREE(path); + + return length; +} + +WAI_NOINLINE +WAI_FUNCSPEC +int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) +{ + char buffer[PATH_MAX]; + char* resolved = NULL; + int length = -1; + + for(;;) + { + Dl_info info; + + if (dladdr(__builtin_extract_return_addr(__builtin_return_address(0)), &info)) + { + resolved = realpath(info.dli_fname, buffer); + if (!resolved) + break; + + length = (int)strlen(resolved); + if (length <= capacity) + { + memcpy(out, resolved, length); + + if (dirname_length) + { + int i; + + for (i = length - 1; i >= 0; --i) + { + if (out[i] == '/') + { + *dirname_length = i; + break; + } + } + } + } + } + + break; + } + + return length; +} + +#elif defined(__QNXNTO__) + +#include +#include +#include +#include +#include + +#ifndef WAI_NOINLINE +#ifdef __GNUC__ +#define WAI_NOINLINE __attribute__((noinline)) +#endif +#endif + +#if !defined(WAI_PROC_SELF_EXE) +#define WAI_PROC_SELF_EXE "/proc/self/exefile" +#endif + +WAI_FUNCSPEC +int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length) +{ + char buffer1[PATH_MAX]; + char buffer2[PATH_MAX]; + char* resolved = NULL; + FILE* self_exe = NULL; + int length = -1; + + for (;;) + { + self_exe = fopen(WAI_PROC_SELF_EXE, "r"); + if (!self_exe) + break; + + if (!fgets(buffer1, sizeof(buffer1), self_exe)) + break; + + resolved = realpath(buffer1, buffer2); + if (!resolved) + break; + + length = (int)strlen(resolved); + if (length <= capacity) + { + memcpy(out, resolved, length); + + if (dirname_length) + { + int i; + + for (i = length - 1; i >= 0; --i) + { + if (out[i] == '/') + { + *dirname_length = i; + break; + } + } + } + } + + break; + } + + fclose(self_exe); + + return length; +} + +WAI_FUNCSPEC +int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) +{ + char buffer[PATH_MAX]; + char* resolved = NULL; + int length = -1; + + for(;;) + { + Dl_info info; + + if (dladdr(__builtin_extract_return_addr(__builtin_return_address(0)), &info)) + { + resolved = realpath(info.dli_fname, buffer); + if (!resolved) + break; + + length = (int)strlen(resolved); + if (length <= capacity) + { + memcpy(out, resolved, length); + + if (dirname_length) + { + int i; + + for (i = length - 1; i >= 0; --i) + { + if (out[i] == '/') + { + *dirname_length = i; + break; + } + } + } + } + } + + break; + } + + return length; +} + +#endif + +#ifdef __cplusplus +} +#endif diff --git a/src/whereami.h b/src/whereami.h new file mode 100644 index 0000000..b25c60a --- /dev/null +++ b/src/whereami.h @@ -0,0 +1,64 @@ +// (‑●‑●)> released under the WTFPL v2 license, by Gregory Pakosz (@gpakosz) + +#ifndef WHEREAMI_H +#define WHEREAMI_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef WAI_FUNCSPEC + #define WAI_FUNCSPEC +#endif +#ifndef WAI_PREFIX +#define WAI_PREFIX(function) wai_##function +#endif + +/** + * Returns the path to the current executable. + * + * Usage: + * - first call `int length = wai_getExecutablePath(NULL, 0, NULL);` to + * retrieve the length of the path + * - allocate the destination buffer with `path = (char*)malloc(length + 1);` + * - call `wai_getExecutablePath(path, length, NULL)` again to retrieve the + * path + * - add a terminal NUL character with `path[length] = '\0';` + * + * @param out destination buffer, optional + * @param capacity destination buffer capacity + * @param dirname_length optional recipient for the length of the dirname part + * of the path. + * + * @return the length of the executable path on success (without a terminal NUL + * character), otherwise `-1` + */ +WAI_FUNCSPEC +int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length); + +/** + * Returns the path to the current module + * + * Usage: + * - first call `int length = wai_getModulePath(NULL, 0, NULL);` to retrieve + * the length of the path + * - allocate the destination buffer with `path = (char*)malloc(length + 1);` + * - call `wai_getModulePath(path, length, NULL)` again to retrieve the path + * - add a terminal NUL character with `path[length] = '\0';` + * + * @param out destination buffer, optional + * @param capacity destination buffer capacity + * @param dirname_length optional recipient for the length of the dirname part + * of the path. + * + * @return the length of the module path on success (without a terminal NUL + * character), otherwise `-1` + */ +WAI_FUNCSPEC +int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length); + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef WHEREAMI_H