VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/vfs/vfsmisc.cpp

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1/* $Id: vfsmisc.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT - Virtual File System, Misc functions with heavy dependencies.
4 */
5
6/*
7 * Copyright (C) 2010-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include "internal/iprt.h"
42#include <iprt/vfs.h>
43
44#include <iprt/assert.h>
45#include <iprt/errcore.h>
46#include <iprt/file.h>
47#include <iprt/handle.h>
48
49
50
51RTDECL(int) RTVfsIoStrmFromStdHandle(RTHANDLESTD enmStdHandle, uint64_t fOpen, bool fLeaveOpen,
52 PRTVFSIOSTREAM phVfsIos)
53{
54 /*
55 * Input validation.
56 */
57 AssertPtrReturn(phVfsIos, VERR_INVALID_POINTER);
58 *phVfsIos = NIL_RTVFSIOSTREAM;
59 AssertReturn( enmStdHandle == RTHANDLESTD_INPUT
60 || enmStdHandle == RTHANDLESTD_OUTPUT
61 || enmStdHandle == RTHANDLESTD_ERROR,
62 VERR_INVALID_PARAMETER);
63 AssertReturn(!(fOpen & ~RTFILE_O_VALID_MASK), VERR_INVALID_PARAMETER);
64 if (enmStdHandle == RTHANDLESTD_INPUT)
65 fOpen |= RTFILE_O_READ;
66 else
67 fOpen |= RTFILE_O_WRITE;
68
69 /*
70 * Open the handle and see what we get back.
71 */
72 RTHANDLE h;
73 int rc = RTHandleGetStandard(enmStdHandle, fLeaveOpen, &h);
74 if (RT_SUCCESS(rc))
75 {
76 switch (h.enmType)
77 {
78 case RTHANDLETYPE_FILE:
79 rc = RTVfsIoStrmFromRTFile(h.u.hFile, fOpen, fLeaveOpen, phVfsIos);
80 break;
81
82 case RTHANDLETYPE_PIPE:
83 rc = RTVfsIoStrmFromRTPipe(h.u.hPipe, fLeaveOpen, phVfsIos);
84 break;
85
86 case RTHANDLETYPE_SOCKET:
87 /** @todo */
88 rc = VERR_NOT_IMPLEMENTED;
89 break;
90
91 default:
92 rc = VERR_NOT_IMPLEMENTED;
93 break;
94 }
95 }
96
97 return rc;
98}
99
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use