VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/path/RTPathFindCommon.cpp@ 85374

Last change on this file since 85374 was 85374, checked in by vboxsync, 5 years ago

IPRT/RTPathFindCommon: Added another check for the current path in array.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1/* $Id: RTPathFindCommon.cpp 85374 2020-07-17 15:44:59Z vboxsync $ */
2/** @file
3 * IPRT - RTPathFindCommon implementations.
4 */
5
6/*
7 * Copyright (C) 2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include "internal/iprt.h"
32#include <iprt/assert.h>
33#include <iprt/errcore.h>
34#include <iprt/path.h>
35
36
37RTDECL(size_t) RTPathFindCommonEx(const char * const *papcszPaths, size_t cPaths, char szSeparator)
38{
39 AssertPtrReturn(papcszPaths, 0);
40 AssertReturn(cPaths, 0);
41 AssertReturn(szSeparator != '\0', 0);
42
43 const char *pcszRef = papcszPaths[0]; /* The reference we're comparing with. */
44
45 size_t cch = 0;
46 do
47 {
48 for (size_t i = 0; i < cPaths; ++i)
49 {
50 const char *pcszPath = papcszPaths[i];
51 if ( pcszPath
52 && pcszPath[cch]
53 && pcszPath[cch] == pcszRef[cch])
54 continue;
55
56 while ( cch
57 && pcszRef[--cch] != szSeparator) { }
58
59 return cch ? cch + 1 : 0;
60 }
61 }
62 while (++cch);
63
64 return 0;
65}
66RT_EXPORT_SYMBOL(RTPathFindCommonEx);
67
68
69RTDECL(size_t) RTPathFindCommon(const char * const *papcszPaths, size_t cPaths)
70{
71 return RTPathFindCommonEx(papcszPaths, cPaths, RTPATH_SLASH);
72}
73RT_EXPORT_SYMBOL(RTPathFindCommon);
74
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette