From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41872) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WCkgd-0001i9-Bu for qemu-devel@nongnu.org; Mon, 10 Feb 2014 01:49:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WCkgX-0005l8-2T for qemu-devel@nongnu.org; Mon, 10 Feb 2014 01:49:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43347) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WCkgW-0005ks-Rl for qemu-devel@nongnu.org; Mon, 10 Feb 2014 01:49:41 -0500 From: Fam Zheng Date: Mon, 10 Feb 2014 14:49:01 +0800 Message-Id: <1392014941-15505-12-git-send-email-famz@redhat.com> In-Reply-To: <1392014941-15505-1-git-send-email-famz@redhat.com> References: <1392014941-15505-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH v20 11/11] oslib: port qemu_init_exec_dir to Darwin List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, mjt@tls.msk.ru, alex@alex.org.uk, pbonzini@redhat.com, mrezanin@redhat.com, vilanova@ac.upc.edu, rth@twiddle.net Signed-off-by: Paolo Bonzini Signed-off-by: Fam Zheng --- util/oslib-posix.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/util/oslib-posix.c b/util/oslib-posix.c index c2eeb4f..3214e44 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -59,6 +59,12 @@ extern int daemon(int, int); #include #include +/* Get declaration of _NSGetExecutablePath on MacOS X 10.2 or newer. */ +#if defined(__APPLE__) && defined(__MACH__) +#define ENUM_DYLD_BOOL +#include +#endif + #ifdef CONFIG_LINUX #include #endif @@ -307,6 +313,15 @@ void qemu_init_exec_dir(const char *argv0) p = buf; } } +#elif defined(__APPLE__) && defined(__MACH__) + { + char result[PATH_MAX]; + uint32_t length = PATH_MAX; + if (_NSGetExecutablePath(result, &length) != 0 || result[0] != '/') { + return; + } + p = realpath(result, buf); + } #endif /* If we don't have any way of figuring out the actual executable location then try argv[0]. */ -- 1.8.5.4