commit:     e423a9f20007493d134cae3f3bd0b665faedcf83
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri Dec 29 09:18:57 2017 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri Dec 29 11:16:31 2017 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=e423a9f2

q_main: implement executable path resolution for Darwin and Solaris

 q.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/q.c b/q.c
index ea1fb4d..ff79643 100644
--- a/q.c
+++ b/q.c
@@ -6,6 +6,10 @@
  * Copyright 2005-2014 Mike Frysinger  - <[email protected]>
  */
 
+#if defined(__MACH__)
+#include <libproc.h>
+#endif
+
 #define Q_FLAGS "irmM:" COMMON_FLAGS
 static struct option const q_long_opts[] = {
        {"install",       no_argument, NULL, 'i'},
@@ -115,7 +119,21 @@ int q_main(int argc, char **argv)
                if (!quiet)
                        printf("Installing symlinks:\n");
 
+#if defined(__MACH__)
+               rret = proc_pidpath(getpid(), buf, sizeof(buf));
+               if (rret != -1)
+                       rret = strlen(buf);
+#elif defined(__sun) && defined(__SVR4)
+               prog = getexecname();
+               rret = strlen(prog);
+               if (rret > sizeof(buf) - 1) {
+                       rret = -1;
+               } else {
+                       strncpy(buf, prog, rret);
+               }
+#else
                rret = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
+#endif
                if (rret == -1) {
                        warnfp("haha no symlink love for you");
                        return 1;

Reply via email to