1 | /* $Id: RTPathParentLength.cpp.h 82968 2020-02-04 10:35:17Z 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-2020 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | *
|
---|
19 | * The contents of this file may alternatively be used under the terms
|
---|
20 | * of the Common Development and Distribution License Version 1.0
|
---|
21 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
22 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
23 | * CDDL are applicable instead of those of the GPL.
|
---|
24 | *
|
---|
25 | * You may elect to license modified versions of this file under the
|
---|
26 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #include "rtpath-root-length-template.cpp.h"
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * @copydoc RTPathParentLengthEx
|
---|
33 | */
|
---|
34 | static size_t RTPATH_STYLE_FN(rtPathParentLength)(const char *pszPath, uint32_t fFlags)
|
---|
35 | {
|
---|
36 | /*
|
---|
37 | * Determin the length of the root component so we can make sure
|
---|
38 | * we don't try ascend higher than it.
|
---|
39 | */
|
---|
40 | size_t const cchRoot = RTPATH_STYLE_FN(rtPathRootLengthEx)(pszPath, fFlags);
|
---|
41 |
|
---|
42 | /*
|
---|
43 | * Rewind to the start of the final component.
|
---|
44 | */
|
---|
45 | size_t cch = strlen(pszPath);
|
---|
46 |
|
---|
47 | /* Trailing slashes: */
|
---|
48 | while (cch > cchRoot && RTPATH_IS_SLASH(pszPath[cch - 1]))
|
---|
49 | cch--;
|
---|
50 |
|
---|
51 | /* The component: */
|
---|
52 | while (cch > cchRoot && !RTPATH_IS_SEP(pszPath[cch - 1]))
|
---|
53 | cch--;
|
---|
54 |
|
---|
55 | /* Done! */
|
---|
56 | return cch;
|
---|
57 | }
|
---|
58 |
|
---|