VirtualBox

source: vbox/trunk/src/VBox/Runtime/generic/RTPathGetCurrentDrive-generic.cpp@ 63942

Last change on this file since 63942 was 62477, checked in by vboxsync, 8 years ago

(C) 2016

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/* $Id: RTPathGetCurrentDrive-generic.cpp 62477 2016-07-22 18:27:37Z vboxsync $ */
2/** @file
3 * IPRT - RTPathGetCurrentDrive, generic implementation.
4 */
5
6/*
7 * Copyright (C) 2014-2016 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#define LOG_GROUP RTLOGGROUP_PATH
32#include <iprt/path.h>
33#include "internal/iprt.h"
34
35#include <iprt/ctype.h>
36#include <iprt/err.h>
37#include <iprt/string.h>
38#include "internal/path.h"
39
40
41RTDECL(int) RTPathGetCurrentDrive(char *pszPath, size_t cbPath)
42{
43#ifdef HAVE_DRIVE
44 /*
45 * Query the current directroy and extract the wanted information from it.
46 */
47 int rc = RTPathGetCurrent(pszPath, cbPath);
48 if (RT_SUCCESS(rc))
49 {
50 /*
51 * Drive letter? Chop off at root slash.
52 */
53 if (pszPath[0] && RTPATH_IS_VOLSEP(pszPath[1]))
54 {
55 pszPath[2] = '\0';
56 return rc;
57 }
58
59 /*
60 * UNC? Chop off after share.
61 */
62 if ( RTPATH_IS_SLASH(pszPath[0])
63 && RTPATH_IS_SLASH(pszPath[1])
64 && !RTPATH_IS_SLASH(pszPath[2])
65 && pszPath[2])
66 {
67 /* Work thru the server name. */
68 size_t off = 3;
69 while (!RTPATH_IS_SLASH(pszPath[off]) && pszPath[off])
70 off++;
71 size_t offServerSlash = off;
72
73 /* Is there a share name? */
74 if (RTPATH_IS_SLASH(pszPath[off]))
75 {
76 while (RTPATH_IS_SLASH(pszPath[off]))
77 off++;
78 if (pszPath[off])
79 {
80 /* Work thru the share name. */
81 while (!RTPATH_IS_SLASH(pszPath[off]) && pszPath[off])
82 off++;
83 }
84 /* No share name, chop at server name. */
85 else
86 off = offServerSlash;
87 }
88 }
89 return VERR_INTERNAL_ERROR_4;
90 }
91 return rc;
92
93#else /* !HAVE_DRIVE */
94 /*
95 * No drive letters on this system, return empty string.
96 */
97 if (cbPath > 0)
98 {
99 *pszPath = '\0';
100 return VINF_SUCCESS;
101 }
102 return VERR_BUFFER_OVERFLOW;
103#endif /* !HAVE_DRIVE */
104}
105RT_EXPORT_SYMBOL(RTPathGetCurrentDrive);
106
Note: See TracBrowser for help on using the repository browser.

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