1 | /* $Id: RTPathFilename.cpp 48935 2013-10-07 21:19:37Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - RTPathFilename
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2012 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. 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/path.h>
|
---|
33 |
|
---|
34 | #include <iprt/assert.h>
|
---|
35 |
|
---|
36 |
|
---|
37 |
|
---|
38 | RTDECL(char *) RTPathFilename(const char *pszPath)
|
---|
39 | {
|
---|
40 | return RTPathFilenameEx(pszPath, RTPATH_STYLE);
|
---|
41 | }
|
---|
42 | RT_EXPORT_SYMBOL(RTPathFilename);
|
---|
43 |
|
---|
44 |
|
---|
45 | RTDECL(char *) RTPathFilenameEx(const char *pszPath, uint32_t fFlags)
|
---|
46 | {
|
---|
47 | const char *psz = pszPath;
|
---|
48 | const char *pszName = pszPath;
|
---|
49 |
|
---|
50 | Assert(RTPATH_STR_F_IS_VALID(fFlags, 0 /*no extra flags*/));
|
---|
51 | fFlags &= RTPATH_STR_F_STYLE_MASK;
|
---|
52 | if (fFlags == RTPATH_STR_F_STYLE_HOST)
|
---|
53 | fFlags = RTPATH_STYLE;
|
---|
54 | if (fFlags == RTPATH_STR_F_STYLE_DOS)
|
---|
55 | {
|
---|
56 | for (;; psz++)
|
---|
57 | {
|
---|
58 | switch (*psz)
|
---|
59 | {
|
---|
60 | /* handle separators. */
|
---|
61 | case ':':
|
---|
62 | case '\\':
|
---|
63 | case '/':
|
---|
64 | pszName = psz + 1;
|
---|
65 | break;
|
---|
66 |
|
---|
67 | /* the end */
|
---|
68 | case '\0':
|
---|
69 | if (*pszName)
|
---|
70 | return (char *)(void *)pszName;
|
---|
71 | return NULL;
|
---|
72 | }
|
---|
73 | }
|
---|
74 | }
|
---|
75 | else
|
---|
76 | {
|
---|
77 | Assert(fFlags == RTPATH_STR_F_STYLE_UNIX);
|
---|
78 | for (;; psz++)
|
---|
79 | {
|
---|
80 | switch (*psz)
|
---|
81 | {
|
---|
82 | /* handle separators. */
|
---|
83 | case '/':
|
---|
84 | pszName = psz + 1;
|
---|
85 | break;
|
---|
86 |
|
---|
87 | /* the end */
|
---|
88 | case '\0':
|
---|
89 | if (*pszName)
|
---|
90 | return (char *)(void *)pszName;
|
---|
91 | return NULL;
|
---|
92 | }
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|
96 | /* not reached */
|
---|
97 | }
|
---|
98 | RT_EXPORT_SYMBOL(RTPathFilenameEx);
|
---|
99 |
|
---|