path.cpp revision 8c881d20e8dab28cf6ee0e31373112cc0ef7d6da
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * IPRT - Path Manipulation.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * available from http://www.virtualbox.org. This file is free software;
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * you can redistribute it and/or modify it under the terms of the GNU
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * General Public License (GPL) as published by the Free Software
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * The contents of this file may alternatively be used under the terms
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * of the Common Development and Distribution License Version 1.0
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * VirtualBox OSE distribution, in which case the provisions of the
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * CDDL are applicable instead of those of the GPL.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * You may elect to license modified versions of this file under the
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * terms and conditions of either the GPL or the CDDL or both.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * additional information or have any questions.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/*******************************************************************************
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync* Header Files *
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync*******************************************************************************/
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Strips the filename from a path. Truncates the given string in-place by overwriting the
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * last path separator character with a null byte in a platform-neutral way.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * @param pszPath Path from which filename should be extracted, will be truncated.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * If the string contains no path separator, it will be changed to a "." string.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /* handle separators. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /* the end */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /* no directory component */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /* only root. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /* will never get here */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Strips the extension from a path.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * @param pszPath Path which extension should be stripped.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /* handle separators. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /* the end */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /* will never get here */
RTDECL(size_t) RTPathParse(const char *pszPath, size_t *pcchDir, ssize_t *poffName, ssize_t *poffSuff)
for (;; psz++)
switch (*psz)
if (poffName)
if (poffSuff)
if (pszLastDot)
if (pcchDir)
off--;
for (;; psz++)
switch (*psz)
if (*pszName)
return (char *)(void *)pszName;
return NULL;
return NULL;
switch (*pszEnd)
for (;; psz++)
switch (*psz)
if (pszExt)
return (char *)(void *)pszExt;
return NULL;
return NULL;
if (!pszPath1)
if (!pszPath2)
int iDiff = 0;
iDiff = 0;
if (!uc1)
puszTmpPath1++;
puszTmpPath2++;
return iDiff;
if (!fLimit)
return NULL;
return NULL;
if (!pszPath)
pszEnd++;
pszEnd++;
pszEnd++;
pszEnd++;
pszEnd++;
/* This isn't quite right when looking at the above stuff, but it works assuming that '//' does not mean UNC. */
RTDECL(int) RTPathAbsEx(const char *pszBase, const char *pszPath, char *pszAbsPath, size_t cchAbsPath)
#if defined(RT_OS_WINDOWS)
return VERR_INVALID_NAME;
return VERR_FILENAME_TOO_LONG;
if (fRootSpec)
return NULL;
if (!pszAppend)
return VINF_SUCCESS;
if (!cchAppend)
return VINF_SUCCESS;
return VERR_BUFFER_OVERFLOW;
return VINF_SUCCESS;
bool fAddSlash = false;
return VERR_BUFFER_OVERFLOW;
return VERR_BUFFER_OVERFLOW;
return VERR_BUFFER_OVERFLOW;
pszPathEnd--;
return VERR_BUFFER_OVERFLOW;
return VINF_SUCCESS;
#ifndef RT_MINI
return VINF_SUCCESS;
return VERR_BUFFER_OVERFLOW;
char *pszUtf8Path;
int rc;
return rc;
char *pszUtf8Path;
int rc;
return rc;
* a common global directory where ld.so can found them.
char *pszUtf8Path;
int rc;
return rc;
char *pszUtf8Path;
int rc;
return rc;