VirtualBox

source: vbox/trunk/src/VBox/Runtime/nt/RTNtPathExpand8dot3PathA.cpp@ 93115

Last change on this file since 93115 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1/* $Id: RTNtPathExpand8dot3PathA.cpp 93115 2022-01-01 11:31:46Z vboxsync $ */
2/** @file
3 * IPRT - Native NT, RTNtPathExpand8dot3PathA.
4 */
5
6/*
7 * Copyright (C) 2006-2022 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_FS
32#ifdef IN_SUP_HARDENED_R3
33# include <iprt/nt/nt-and-windows.h>
34#else
35# include <iprt/nt/nt.h>
36#endif
37
38#include <iprt/err.h>
39#include <iprt/string.h>
40#include <iprt/path.h>
41#include <iprt/utf16.h>
42
43
44
45/**
46 * Wrapper around RTNtPathExpand8dot3Path that allocates a buffer instead of
47 * working on the input buffer.
48 *
49 * @returns IPRT status code, see RTNtPathExpand8dot3Path().
50 * @param pUniStrSrc The path to fix up. MaximumLength is the max buffer
51 * length.
52 * @param fPathOnly Whether to only process the path and leave the filename
53 * as passed in.
54 * @param pUniStrDst Output string. On success, the caller must use
55 * RTUtf16Free to free what the Buffer member points to.
56 * This is all zeros and NULL on failure.
57 */
58RTDECL(int) RTNtPathExpand8dot3PathA(PCUNICODE_STRING pUniStrSrc, bool fPathOnly, PUNICODE_STRING pUniStrDst)
59{
60 /* Guess a reasonable size for the final version. */
61 size_t const cbShort = pUniStrSrc->Length;
62 size_t cbLong = RT_MIN(_64K - 1, cbShort * 8);
63 if (cbLong < RTPATH_MAX)
64 cbLong = RTPATH_MAX * 2;
65 AssertCompile(RTPATH_MAX * 2 < _64K);
66
67 pUniStrDst->Buffer = (WCHAR *)RTUtf16Alloc(cbLong);
68 if (pUniStrDst->Buffer != NULL)
69 {
70 /* Copy over the short name and fix it up. */
71 pUniStrDst->MaximumLength = (uint16_t)cbLong;
72 pUniStrDst->Length = (uint16_t)cbShort;
73 memcpy(pUniStrDst->Buffer, pUniStrSrc->Buffer, cbShort);
74 pUniStrDst->Buffer[cbShort / sizeof(WCHAR)] = '\0';
75 int rc = RTNtPathExpand8dot3Path(pUniStrDst, fPathOnly);
76 if (RT_SUCCESS(rc))
77 return rc;
78
79 /* We failed, bail. */
80 RTUtf16Free(pUniStrDst->Buffer);
81 pUniStrDst->Buffer = NULL;
82 }
83 pUniStrDst->Length = 0;
84 pUniStrDst->MaximumLength = 0;
85 return VERR_NO_UTF16_MEMORY;
86}
87
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