f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync/* $Id$ */
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync/** @file
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync * IPRT - rtProcInitName, Darwin.
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync */
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync/*
c58f1213e628a545081c70e26c6b67a841cff880vboxsync * Copyright (C) 2006-2010 Oracle Corporation
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync *
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync * available from http://www.virtualbox.org. This file is free software;
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync * you can redistribute it and/or modify it under the terms of the GNU
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync * General Public License (GPL) as published by the Free Software
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync *
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync * The contents of this file may alternatively be used under the terms
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync * of the Common Development and Distribution License Version 1.0
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync * VirtualBox OSE distribution, in which case the provisions of the
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync * CDDL are applicable instead of those of the GPL.
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync *
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync * You may elect to license modified versions of this file under the
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync * terms and conditions of either the GPL or the CDDL or both.
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync */
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync/*******************************************************************************
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync* Header Files *
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync*******************************************************************************/
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync#define LOG_GROUP RTLOGGROUP_PROCESS
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync#ifdef RT_OS_DARWIN
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync# include <mach-o/dyld.h>
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync#endif
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync
48414a1eddf0756cc156dabb19707c382fb064bfvboxsync#include <stdlib.h>
48414a1eddf0756cc156dabb19707c382fb064bfvboxsync#include <limits.h>
48414a1eddf0756cc156dabb19707c382fb064bfvboxsync#include <errno.h>
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync#include <iprt/string.h>
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync#include <iprt/assert.h>
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync#include <iprt/err.h>
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync#include <iprt/path.h>
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync#include "internal/process.h"
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync#include "internal/path.h"
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsyncDECLHIDDEN(int) rtProcInitExePath(char *pszPath, size_t cchPath)
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync{
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync /*
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync * Query the image name from the dynamic linker, convert and return it.
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync */
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync const char *pszImageName = _dyld_get_image_name(0);
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync AssertReturn(pszImageName, VERR_INTERNAL_ERROR);
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync
48414a1eddf0756cc156dabb19707c382fb064bfvboxsync char szTmpPath[PATH_MAX + 1];
48414a1eddf0756cc156dabb19707c382fb064bfvboxsync const char *psz = realpath(pszImageName, szTmpPath);
48414a1eddf0756cc156dabb19707c382fb064bfvboxsync int rc;
48414a1eddf0756cc156dabb19707c382fb064bfvboxsync if (psz)
48414a1eddf0756cc156dabb19707c382fb064bfvboxsync rc = rtPathFromNativeCopy(pszPath, cchPath, szTmpPath, NULL);
48414a1eddf0756cc156dabb19707c382fb064bfvboxsync else
48414a1eddf0756cc156dabb19707c382fb064bfvboxsync rc = RTErrConvertFromErrno(errno);
92453c7e11969eccff568c08178524f057247426vboxsync AssertMsgRCReturn(rc, ("rc=%Rrc pszLink=\"%s\"\nhex: %.*Rhxs\n", rc, pszPath, strlen(pszImageName), pszPath), rc);
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync return VINF_SUCCESS;
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync}
f0f603c5fba5a342c00101bbaf5fad0bbd44fb55vboxsync