{"id":20392836,"url":"https://github.com/sde-gui/libmypath","last_synced_at":"2026-04-27T18:32:23.886Z","repository":{"id":69810783,"uuid":"431548598","full_name":"sde-gui/libmypath","owner":"sde-gui","description":"A small library that helps your application to locate the application's data files under Linux and other Unix-like OSes","archived":false,"fork":false,"pushed_at":"2021-11-25T09:02:32.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-16T02:43:33.461Z","etag":null,"topics":["freebsd","linux","netbsd","portable-apps"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sde-gui.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2021-11-24T16:06:53.000Z","updated_at":"2023-10-27T16:55:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"c2f24963-25bd-4cd5-9f1d-3c580e31a4f9","html_url":"https://github.com/sde-gui/libmypath","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sde-gui/libmypath","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sde-gui%2Flibmypath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sde-gui%2Flibmypath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sde-gui%2Flibmypath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sde-gui%2Flibmypath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sde-gui","download_url":"https://codeload.github.com/sde-gui/libmypath/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sde-gui%2Flibmypath/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32349479,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-27T17:12:42.749Z","status":"ssl_error","status_checked_at":"2026-04-27T17:12:41.658Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["freebsd","linux","netbsd","portable-apps"],"created_at":"2024-11-15T03:46:15.894Z","updated_at":"2026-04-27T18:32:23.871Z","avatar_url":"https://github.com/sde-gui.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Libmypath v0.1.0\n\nA small library that helps your application to locate the application's data files.\n\nLibmypath attempts to locate the executable file path of the running application. On Unix systems, there's no reliable way for an application to retrieve a path to its own executable image or any other application-related files. Usually paths are either hard-coded into the application binary or passed as command-line parameters.\n\nThere are several methods to locate the application path. Libmypath tries the following:\n\n1. If procfs is mounted at /proc, libmypath reads the path from procfs.\n2. Libmypath uses dladdr() to read the file name of the mapped executable image.\n3. As the last resort, libmypath attemts to guess the path based on the value of *argv\\[0\\]* and the *PATH* environent variable.\n\n# Supported operating systems and environments\n\nThe library targets:\n\n* Linux\n* FreeBSD\n* NetBSD\n\nMay work for other Unix-like systems as well.\n\nMore systems will probably be tested in the future.\n\n# Usage\n\nLibmypath is not intended for building as a shared object and installing into `{/,/usr,/usr/local}lib`. Just drop it into your application's source code and use it directly.\n\nOn Linux, provide `-ldl` option for the linker in order to make `dladdr()` symbol available. Refer to OS-specific manuals on other systems.\n\nWhen linking the application statically or on systems where `dladdr()` is unavailable, `#define MYPATH_DISABLE_DLADDR` to disable linking to that symbol. (Normally the option looks like `-DMYPATH_DISABLE_DLADDR` for gcc, clang or another gcc-compatible compiler.)\n\n# Test app\n\nSee `build_test_app.sh`. Edit it, if necessary, to make the app building under your OS. Build the app and make sure the detection logic works as expected. Report issues, if any.\n\n# Portability issues\n\n* `procfs` is not in POSIX.\n* `dladdr()` is not in POSIX.\n* `argv[0]` can generally contain an arbitrary string and not an actual command name.\n\n# Layouts of procfs on different systems\n\nLinux:\n\n```\n    /proc/self -\u003e [pid]\n    /proc/[pid]/exe -\u003e [path]\n```\n\nFreeBSD:\n\n```\n    /proc/curproc -\u003e [pid]\n    /proc/[pid]/file -\u003e [path]\n```\n\nNetBSD:\n\n```\n    /proc/self -\u003e curproc\n    /proc/curproc -\u003e [pid]\n    /proc/[pid]/exe -\u003e [path]\n```\n\nLibmypath tries all the mentioned procfs layouts in order and doesn't apply any compile-time or run-time OS-detection logic.\n\n# dladdr() issues\n\n1. `man 3 dladdr` under FreeBSD reports:\n\n\u003e This implementation is bug-compatible with the Solaris implementation.\n\u003e In particular, the following bugs are present:\n\n\u003e If addr lies in the main executable rather than in a shared library,\n\u003e the pathname returned in dli_fname may not be correct.  The pathname\n\u003e is taken directly from argv\\[0\\] of the calling process.  When executing\n\u003e a program specified by its full pathname, most shells set argv\\[0\\]\n\u003e to the pathname.  But this is not required of shells or guaranteed by\n\u003e the operating system.\n\nI've not tested if other systems behave the same or not. If they do, `dladdr()` is just a verbose way to say `argv[0]`, and `argv[0]` isn't guaranteed to containg a valid command name. If they don't, `dladdr()` is more reliable way to get the path. Anyway, there MAY be some systems now or in the future that return the real path on `dladdr()`.\n\n2. \"In dynamically linked programs, the address of a global function will point to its program linkage table entry, rather than to the entry point of the function itself. This causes most global functions to appear to be defined within the main executable, rather than in the shared libraries where the actual code resides.\"\n\nThe third issue does not affect Libmypath since Libmypath does not cover cases of shared libraries. But if you will implement path detection method for shared libraries (in fact, dladdr() is the only possible method for this), be aware. Pass a pointer to a global variable into dladdr(), not to a global function. A pointer to a variable actually contains an address within the data section of your shared library, while pointer to global function may point to some trampoline code.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsde-gui%2Flibmypath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsde-gui%2Flibmypath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsde-gui%2Flibmypath/lists"}