git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fallback on _NSGetExecutablePath to get the executable path if using argv[0] fails
@ 2010-11-29 16:57 Jeremy Huddleston
  2010-11-29 17:09 ` Thiago Farina
  0 siblings, 1 reply; 14+ messages in thread
From: Jeremy Huddleston @ 2010-11-29 16:57 UTC (permalink / raw)
  To: git


Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
Reviewed-by: Matt Wright <mww@apple.com>
---
 exec_cmd.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/exec_cmd.c b/exec_cmd.c
index bf22570..1e24a8f 100644
--- a/exec_cmd.c
+++ b/exec_cmd.c
@@ -3,6 +3,10 @@
 #include "quote.h"
 #define MAX_ARGS	32
 
+#if defined(__APPLE__) && defined(RUNTIME_PREFIX)
+#include <mach-o/dyld.h>
+#endif
+
 extern char **environ;
 static const char *argv_exec_path;
 static const char *argv0_path;
@@ -53,6 +57,19 @@ const char *git_extract_argv0_path(const char *argv0)
 	if (slash >= argv0) {
 		argv0_path = xstrndup(argv0, slash - argv0);
 		return slash + 1;
+#ifdef __APPLE__
+	} else {
+		char new_argv0[PATH_MAX];
+		uint32_t new_argv0_s = PATH_MAX;
+		if(_NSGetExecutablePath(new_argv0, &new_argv0_s) == 0) {
+			slash = new_argv0 + new_argv0_s;
+			while (new_argv0 <= slash && !is_dir_sep(*slash))
+		                slash--;
+
+			if (slash >= new_argv0)
+				argv0_path = xstrndup(new_argv0, slash - new_argv0);
+		}
+#endif
 	}
 
 	return argv0;
-- 
1.7.3.2

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2010-12-03  7:50 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-29 16:57 [PATCH] Fallback on _NSGetExecutablePath to get the executable path if using argv[0] fails Jeremy Huddleston
2010-11-29 17:09 ` Thiago Farina
2010-11-29 17:12   ` Jonathan Nieder
2010-11-29 18:29     ` [PATCH updated] " Jeremy Huddleston
2010-11-29 18:49       ` Jonathan Nieder
2010-11-29 20:24         ` Junio C Hamano
2010-11-29 21:02           ` Jeremy Huddleston
2010-11-29 18:34     ` [PATCH] " Jeremy Huddleston
2010-11-29 18:50       ` Jonathan Nieder
2010-11-29 20:07         ` Jeremy Huddleston
2010-11-29 20:19           ` Jonathan Nieder
2010-11-29 23:13     ` Kevin Ballard
2010-12-03  7:42       ` Jonathan Nieder
2010-12-03  7:50         ` Kevin Ballard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).