{"id":13531016,"url":"https://github.com/gpakosz/whereami","last_synced_at":"2025-04-04T15:09:32.680Z","repository":{"id":24831961,"uuid":"28246617","full_name":"gpakosz/whereami","owner":"gpakosz","description":"Locate the current running executable and the current running module/library on the file system 🔎","archived":false,"fork":false,"pushed_at":"2024-08-26T15:01:18.000Z","size":55,"stargazers_count":486,"open_issues_count":5,"forks_count":65,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-03-28T14:06:51.562Z","etag":null,"topics":["c","cpp","dladdr","executable-path","getexecutablepath","getmodulefilename","introspection","library","plugins"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gpakosz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/funding.yml","license":"LICENSE.MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"gpakosz"}},"created_at":"2014-12-19T21:16:27.000Z","updated_at":"2025-03-15T06:45:00.000Z","dependencies_parsed_at":"2024-01-03T04:00:28.950Z","dependency_job_id":"a4f3d3be-60cf-4239-be1e-65b3e9ad643a","html_url":"https://github.com/gpakosz/whereami","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpakosz%2Fwhereami","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpakosz%2Fwhereami/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpakosz%2Fwhereami/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpakosz%2Fwhereami/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gpakosz","download_url":"https://codeload.github.com/gpakosz/whereami/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198463,"owners_count":20900080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","cpp","dladdr","executable-path","getexecutablepath","getmodulefilename","introspection","library","plugins"],"created_at":"2024-08-01T07:00:59.069Z","updated_at":"2025-04-04T15:09:32.655Z","avatar_url":"https://github.com/gpakosz.png","language":"C","funding_links":["https://github.com/sponsors/gpakosz"],"categories":["Utilities","公用事业","Libraries","C++"],"sub_categories":["YAML","C"],"readme":"# Where Am I?\n\nA drop-in two files library to locate the current executable and the current\nmodule on the file system.\n\nSupported platforms:\n\n- Windows\n- Linux\n- Mac\n- iOS\n- Android\n- QNX Neutrino\n- FreeBSD\n- NetBSD\n- DragonFly BSD\n- SunOS\n- OpenBSD\n\nJust drop `whereami.h` and `whereami.c` into your build and get started. (see\nalso [customizing compilation])\n\n[customizing compilation]: #customizing-compilation\n\n--------------------------------------------------------------------------------\n\n## Usage\n\n- `wai_getExecutablePath()` returns the path of the enclosing executable\n- `wai_getModulePath()` returns the path of the enclosing module\n\nExample usage:\n\n- first call `int length = wai_getExecutablePath(NULL, 0, NULL);` to retrieve\n the length of the path\n- allocate the destination buffer with `path = (char*)malloc(length + 1);`\n- call `wai_getExecutablePath(path, length, \u0026dirname_length)` again to retrieve\n the path\n- add a terminal `NUL` character with `path[length] = '\\0';`\n\nHere is the output of the example:\n\n    $ make -j -C _gnu-make\n    $ cp ./bin/mac-x86_64/library.dylib /tmp/\n    $ ./bin/mac-x86_64/executable --load-library=/tmp/library.dylib\n\n    executable path: /Users/gregory/Projects/whereami/bin/mac-x86_64/executable\n      dirname: /Users/gregory/Projects/whereami/bin/mac-x86_64\n      basename: executable\n    module path: /Users/gregory/Projects/whereami/bin/mac-x86_64/executable\n      dirname: /Users/gregory/Projects/whereami/bin/mac-x86_64\n      basename: executable\n\n    library loaded\n    executable path: /Users/gregory/Projects/whereami/bin/mac-x86_64/executable\n      dirname: /Users/gregory/Projects/whereami/bin/mac-x86_64\n      basename: executable\n    module path: /private/tmp/library.dylib\n      dirname: /private/tmp\n      basename: library.dylib\n    library unloaded\n\n--------------------------------------------------------------------------------\n\n## Customizing compilation\n\nYou can customize the library's behavior by defining the following macros:\n\n- `WAI_FUNCSPEC`\n- `WAI_PREFIX`\n- `WAI_MALLOC`\n- `WAI_REALLOC`\n- `WAI_FREE`\n\n## Compiling for Windows\n\nThere is a Visual Studio 2015 solution in the `_win-vs14/` folder.\n\n## Compiling for Linux or Mac\n\nThere is a GNU Make 3.81 `MakeFile` in the `_gnu-make/` folder:\n\n    $ make -j -C _gnu-make/\n\n## Compiling for Mac\n\nSee above if you want to compile from command line. Otherwise there is an Xcode\nproject located in the `_mac-xcode/` folder.\n\n## Compiling for iOS\n\nThere is an Xcode project located in the `_ios-xcode/` folder.\n\nIf you prefer compiling from command line and deploying to a jailbroken device\nthrough SSH, use:\n\n    $ make -j -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'\"\n\n## Compiling for Android\n\nYou will have to install the Android NDK, and point the `$NDK_ROOT` environment\nvariable to the NDK path: e.g. `export NDK_ROOT=/opt/android-ndk` (without a\ntrailing `/` character).\n\nNext, the easy way is to make a standalone Android toolchain with the following\ncommand:\n\n    $ $NDK_ROOT/build/tools/make_standalone_toolchain.py --arch=arm64 --api 21 --install-dir=/tmp/android-toolchain\n\nNow you can compile the example by running:\n\n    $ make -j -C _gnu-make/ platform=android architecture=arm64 CC=/tmp/android-toolchain/bin/aarch64-linux-android-gcc CXX=/tmp/android-toolchain/bin/aarch64-linux-android-g++\n\nLoading page aligned library straight from APKs is supported. To test, use the\nfollowing:\n\n    $ zip -Z store app bin/android/library.so\n    $ zipalign -v -f -p 4 ./app.zip ./app.apk\n\nThen copy `bin/android/executable` and `app.apk` to your Android device and\nthere launch:\n\n    $ ./executable --load-library=$PWD/app.apk!/bin/android/library.so\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpakosz%2Fwhereami","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgpakosz%2Fwhereami","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpakosz%2Fwhereami/lists"}