aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/yosys.cc
diff options
context:
space:
mode:
authorMiodrag Milanović <mmicko@gmail.com>2022-07-27 14:16:46 +0200
committerGitHub <noreply@github.com>2022-07-27 14:16:46 +0200
commit29a5947bf83c8011e62cc859a0a832ee8ab690ee (patch)
tree0a894b3a5c42fff225f703d472ef4edbce3d3f86 /kernel/yosys.cc
parentbc012995b44ca9a68524ae3a1ecb4b871d1436c9 (diff)
downloadyosys-29a5947bf83c8011e62cc859a0a832ee8ab690ee.tar.gz
yosys-29a5947bf83c8011e62cc859a0a832ee8ab690ee.tar.bz2
yosys-29a5947bf83c8011e62cc859a0a832ee8ab690ee.zip
Make all compile under OpenBSD (#3423)
Co-authored-by: Josuah Demangeon <me@josuah.net>
Diffstat (limited to 'kernel/yosys.cc')
-rw-r--r--kernel/yosys.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/kernel/yosys.cc b/kernel/yosys.cc
index c532115d8..11df235e4 100644
--- a/kernel/yosys.cc
+++ b/kernel/yosys.cc
@@ -871,6 +871,35 @@ std::string proc_self_dirname()
{
return "/";
}
+#elif defined(__OpenBSD__)
+char yosys_path[PATH_MAX];
+char *yosys_argv0;
+
+std::string proc_self_dirname(void)
+{
+ char buf[PATH_MAX + 1] = "", *path, *p;
+ // if case argv[0] contains a valid path, return it
+ if (strlen(yosys_path) > 0) {
+ p = strrchr(yosys_path, '/');
+ snprintf(buf, sizeof buf, "%*s/", (int)(yosys_path - p), yosys_path);
+ return buf;
+ }
+ // if argv[0] does not, reconstruct the path out of $PATH
+ path = strdup(getenv("PATH"));
+ if (!path)
+ log_error("getenv(\"PATH\") failed: %s\n", strerror(errno));
+ for (p = strtok(path, ":"); p; p = strtok(NULL, ":")) {
+ snprintf(buf, sizeof buf, "%s/%s", p, yosys_argv0);
+ if (access(buf, X_OK) == 0) {
+ *(strrchr(buf, '/') + 1) = '\0';
+ free(path);
+ return buf;
+ }
+ }
+ free(path);
+ log_error("Can't determine yosys executable path\n.");
+ return NULL;
+}
#else
#error "Don't know how to determine process executable base path!"
#endif