path.cpp revision fa1bb60e72e0f90a8bf676d5d824f51657d99ff8
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * IPRT - Path Manipulation.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * available from http://www.virtualbox.org. This file is free software;
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * you can redistribute it and/or modify it under the terms of the GNU
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * General Public License (GPL) as published by the Free Software
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * The contents of this file may alternatively be used under the terms
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * of the Common Development and Distribution License Version 1.0
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * VirtualBox OSE distribution, in which case the provisions of the
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * CDDL are applicable instead of those of the GPL.
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * You may elect to license modified versions of this file under the
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * terms and conditions of either the GPL or the CDDL or both.
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * additional information or have any questions.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync/*******************************************************************************
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync* Header Files *
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync*******************************************************************************/
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * Strips the filename from a path. Truncates the given string in-place by overwriting the
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * last path separator character with a null byte in a platform-neutral way.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * @param pszPath Path from which filename should be extracted, will be truncated.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * If the string contains no path separator, it will be changed to a "." string.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync /* handle separators. */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync /* the end */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync /* no directory component */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync /* only root. */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync /* will never get here */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * Strips the extension from a path.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * @param pszPath Path which extension should be stripped.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync /* handle separators. */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync /* the end */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync /* will never get here */
b4fc07ae3f394595370fc5ed6ab1c353a87259dbvboxsync * Parses a path.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * It figures the length of the directory component, the offset of
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * the file name and the location of the suffix dot.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * @returns The path length.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * @param pszPath Path to find filename in.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * @param pcbDir Where to put the length of the directory component.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * If no directory, this will be 0. Optional.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * @param poffName Where to store the filename offset.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * If empty string or if it's ending with a slash this
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * will be set to -1. Optional.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * @param poffSuff Where to store the suffix offset (the last dot).
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * If empty string or if it's ending with a slash this
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * will be set to -1. Optional.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * @param pfFlags Where to set flags returning more information about
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * the path. For the future. Optional.
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsyncRTDECL(size_t) RTPathParse(const char *pszPath, size_t *pcchDir, ssize_t *poffName, ssize_t *poffSuff)
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync /* handle separators. */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * The end. Complete the results.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync ssize_t offName = *pszName != '\0' ? pszName - pszPath : -1;
a0f8619bc2bbe3614578c21b5b50a88d2841e7aavboxsync while (off >= offRoot && RTPATH_IS_SLASH(pszPath[off]))
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync /* will never get here */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * Finds the filename in a path.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * @returns Pointer to filename within pszPath.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * @returns NULL if no filename (i.e. empty string or ends with a slash).
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync * @param pszPath Path to find filename in.
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync /* handle separators. */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync /* the end */
632b4638bd18092c6b8edb4e1028c9be112f5076vboxsync return (char *)(void *)pszName;
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;
/* 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;
#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;