1 | /* $Id: RTPathParentLength.cpp.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - RTPathParentLength - Code Template.
|
---|
4 | *
|
---|
5 | * This file included multiple times with different path style macros.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2019-2023 Oracle and/or its affiliates.
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox base platform packages, as
|
---|
12 | * available from https://www.virtualbox.org.
|
---|
13 | *
|
---|
14 | * This program is free software; you can redistribute it and/or
|
---|
15 | * modify it under the terms of the GNU General Public License
|
---|
16 | * as published by the Free Software Foundation, in version 3 of the
|
---|
17 | * License.
|
---|
18 | *
|
---|
19 | * This program is distributed in the hope that it will be useful, but
|
---|
20 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
22 | * General Public License for more details.
|
---|
23 | *
|
---|
24 | * You should have received a copy of the GNU General Public License
|
---|
25 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
26 | *
|
---|
27 | * The contents of this file may alternatively be used under the terms
|
---|
28 | * of the Common Development and Distribution License Version 1.0
|
---|
29 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
30 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
31 | * CDDL are applicable instead of those of the GPL.
|
---|
32 | *
|
---|
33 | * You may elect to license modified versions of this file under the
|
---|
34 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
35 | *
|
---|
36 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
37 | */
|
---|
38 |
|
---|
39 | #include "rtpath-root-length-template.cpp.h"
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * @copydoc RTPathParentLengthEx
|
---|
43 | */
|
---|
44 | static size_t RTPATH_STYLE_FN(rtPathParentLength)(const char *pszPath, uint32_t fFlags)
|
---|
45 | {
|
---|
46 | /*
|
---|
47 | * Determin the length of the root component so we can make sure
|
---|
48 | * we don't try ascend higher than it.
|
---|
49 | */
|
---|
50 | size_t const cchRoot = RTPATH_STYLE_FN(rtPathRootLengthEx)(pszPath, fFlags);
|
---|
51 |
|
---|
52 | /*
|
---|
53 | * Rewind to the start of the final component.
|
---|
54 | */
|
---|
55 | size_t cch = strlen(pszPath);
|
---|
56 |
|
---|
57 | /* Trailing slashes: */
|
---|
58 | while (cch > cchRoot && RTPATH_IS_SLASH(pszPath[cch - 1]))
|
---|
59 | cch--;
|
---|
60 |
|
---|
61 | /* The component: */
|
---|
62 | while (cch > cchRoot && !RTPATH_IS_SEP(pszPath[cch - 1]))
|
---|
63 | cch--;
|
---|
64 |
|
---|
65 | /* Done! */
|
---|
66 | return cch;
|
---|
67 | }
|
---|
68 |
|
---|