VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/win/dir-win.cpp@ 48935

Last change on this file since 48935 was 48935, checked in by vboxsync, 11 years ago

Runtime: Whitespace and svn:keyword cleanups by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 4.4 KB
Line 
1/* $Id: dir-win.cpp 48935 2013-10-07 21:19:37Z vboxsync $ */
2/** @file
3 * IPRT - Directory, Windows.
4 */
5
6/*
7 * Copyright (C) 2006-2013 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_DIR
32#include <Windows.h>
33
34#include <iprt/dir.h>
35#include <iprt/path.h>
36#include <iprt/mem.h>
37#include <iprt/string.h>
38#include <iprt/assert.h>
39#include <iprt/err.h>
40#include <iprt/file.h>
41#include <iprt/log.h>
42#include "internal/fs.h"
43#include "internal/path.h"
44
45
46
47RTDECL(int) RTDirCreate(const char *pszPath, RTFMODE fMode, uint32_t fCreate)
48{
49 /*
50 * Validate the file mode.
51 */
52 int rc;
53 fMode = rtFsModeNormalize(fMode, pszPath, 0);
54 if (rtFsModeIsValidPermissions(fMode))
55 {
56 /*
57 * Convert to UTF-16.
58 */
59 PRTUTF16 pwszString;
60 rc = RTStrToUtf16(pszPath, &pwszString);
61 AssertRC(rc);
62 if (RT_SUCCESS(rc))
63 {
64 /*
65 * Create the directory.
66 */
67 if (CreateDirectoryW((LPCWSTR)pwszString, NULL))
68 rc = VINF_SUCCESS;
69 else
70 rc = RTErrConvertFromWin32(GetLastError());
71
72 /*
73 * Turn off indexing of directory through Windows Indexing Service
74 */
75 if (RT_SUCCESS(rc))
76 {
77 if (SetFileAttributesW((LPCWSTR)pwszString, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED))
78 rc = VINF_SUCCESS;
79 else
80 rc = RTErrConvertFromWin32(GetLastError());
81 }
82
83 RTUtf16Free(pwszString);
84 }
85 }
86 else
87 {
88 AssertMsgFailed(("Invalid file mode! %RTfmode\n", fMode));
89 rc = VERR_INVALID_FMODE;
90 }
91
92 LogFlow(("RTDirCreate(%p:{%s}, %RTfmode): returns %Rrc\n", pszPath, pszPath, fMode, rc));
93 return rc;
94}
95
96
97RTDECL(int) RTDirRemove(const char *pszPath)
98{
99 /*
100 * Convert to UTF-16.
101 */
102 PRTUTF16 pwszString;
103 int rc = RTStrToUtf16(pszPath, &pwszString);
104 AssertRC(rc);
105 if (RT_SUCCESS(rc))
106 {
107 /*
108 * Remove the directory.
109 */
110 if (RemoveDirectoryW((LPCWSTR)pwszString))
111 rc = VINF_SUCCESS;
112 else
113 rc = RTErrConvertFromWin32(GetLastError());
114
115 RTUtf16Free(pwszString);
116 }
117
118 LogFlow(("RTDirRemove(%p:{%s}): returns %Rrc\n", pszPath, pszPath, rc));
119 return rc;
120}
121
122
123RTDECL(int) RTDirFlush(const char *pszPath)
124{
125 return VERR_NOT_SUPPORTED;
126}
127
128
129RTDECL(int) RTDirRename(const char *pszSrc, const char *pszDst, unsigned fRename)
130{
131 /*
132 * Validate input.
133 */
134 AssertMsgReturn(VALID_PTR(pszSrc), ("%p\n", pszSrc), VERR_INVALID_POINTER);
135 AssertMsgReturn(VALID_PTR(pszDst), ("%p\n", pszDst), VERR_INVALID_POINTER);
136 AssertMsgReturn(*pszSrc, ("%p\n", pszSrc), VERR_INVALID_PARAMETER);
137 AssertMsgReturn(*pszDst, ("%p\n", pszDst), VERR_INVALID_PARAMETER);
138 AssertMsgReturn(!(fRename & ~RTPATHRENAME_FLAGS_REPLACE), ("%#x\n", fRename), VERR_INVALID_PARAMETER);
139
140 /*
141 * Call the worker.
142 */
143 int rc = rtPathWin32MoveRename(pszSrc, pszDst,
144 fRename & RTPATHRENAME_FLAGS_REPLACE ? MOVEFILE_REPLACE_EXISTING : 0,
145 RTFS_TYPE_DIRECTORY);
146
147 LogFlow(("RTDirRename(%p:{%s}, %p:{%s}, %#x): returns %Rrc\n", pszSrc, pszSrc, pszDst, pszDst, fRename, rc));
148 return rc;
149}
150
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