VirtualBox

source: vbox/trunk/include/iprt/stream.h@ 6000

Last change on this file since 6000 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/** @file
2 * innotek Portable Runtime - I/O Stream.
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_stream_h
27#define ___iprt_stream_h
28
29#include <iprt/cdefs.h>
30#include <iprt/types.h>
31#include <iprt/stdarg.h>
32
33__BEGIN_DECLS
34
35/** @defgroup grp_rt_stream RTStrm - File Streams
36 * @ingroup grp_rt
37 * @{
38 */
39
40/** Pointer to a stream. */
41typedef struct RTSTREAM *PRTSTREAM;
42
43/** Pointer to the standard input stream. */
44extern RTDATADECL(PRTSTREAM) g_pStdIn;
45
46/** Pointer to the standard error stream. */
47extern RTDATADECL(PRTSTREAM) g_pStdErr;
48
49/** Pointer to the standard output stream. */
50extern RTDATADECL(PRTSTREAM) g_pStdOut;
51
52
53/**
54 * Opens a file stream.
55 *
56 * @returns iprt status code.
57 * @param pszFilename Path to the file to open.
58 * @param pszMode The open mode. See fopen() standard.
59 * Format: <a|r|w>[+][b|t]
60 * @param ppStream Where to store the opened stream.
61 */
62RTR3DECL(int) RTStrmOpen(const char *pszFilename, const char *pszMode, PRTSTREAM *ppStream);
63
64/**
65 * Closes the specified stream.
66 *
67 * @returns iprt status code.
68 * @param pStream The stream to close.
69 */
70RTR3DECL(int) RTStrmClose(PRTSTREAM pStream);
71
72/**
73 * Reads from a file stream.
74 *
75 * @returns iprt status code.
76 * @param pStream The stream.
77 * @param pvBuf Where to put the read bits.
78 * Must be cbRead bytes or more.
79 * @param cbRead Number of bytes to read.
80 * @param pcbRead Where to store the number of bytes actually read.
81 * If NULL cbRead bytes are read or an error is returned.
82 */
83RTR3DECL(int) RTStrmReadEx(PRTSTREAM pStream, void *pvBuf, size_t cbRead, size_t *pcbRead);
84
85/**
86 * Writes to a file stream.
87 *
88 * @returns iprt status code.
89 * @param pStream The stream.
90 * @param pvBuf Where to get the bits to write from.
91 * @param cbWrite Number of bytes to write.
92 * @param pcbWritten Where to store the number of bytes actually written.
93 * If NULL cbWrite bytes are written or an error is returned.
94 */
95RTR3DECL(int) RTStrmWriteEx(PRTSTREAM pStream, const void *pvBuf, size_t cbWrite, size_t *pcbWritten);
96
97/**
98 * Reads from a file stream.
99 *
100 * @returns iprt status code.
101 * @param pStream The stream.
102 * @param pvBuf Where to put the read bits.
103 * Must be cbRead bytes or more.
104 * @param cbRead Number of bytes to read.
105 */
106DECLINLINE(int) RTStrmRead(PRTSTREAM pStream, void *pvBuf, size_t cbRead)
107{
108 return RTStrmReadEx(pStream, pvBuf, cbRead, NULL);
109}
110
111/**
112 * Writes to a file stream.
113 *
114 * @returns iprt status code.
115 * @param pStream The stream.
116 * @param pvBuf Where to get the bits to write from.
117 * @param cbWrite Number of bytes to write.
118 */
119DECLINLINE(int) RTStrmWrite(PRTSTREAM pStream, const void *pvBuf, size_t cbWrite)
120{
121 return RTStrmWriteEx(pStream, pvBuf, cbWrite, NULL);
122}
123
124/**
125 * Reads a character from a file stream.
126 *
127 * @returns The char as an unsigned char cast to int.
128 * @returns -1 on failure.
129 * @param pStream The stream.
130 */
131RTR3DECL(int) RTStrmGetCh(PRTSTREAM pStream);
132
133/**
134 * Writes a character to a file stream.
135 *
136 * @returns iprt status code.
137 * @param pStream The stream.
138 * @param ch The char to write.
139 */
140RTR3DECL(int) RTStrmPutCh(PRTSTREAM pStream, int ch);
141
142/**
143 * Writes a string to a file stream.
144 *
145 * @returns iprt status code.
146 * @param pStream The stream.
147 * @param pszString The string to write.
148 * No newlines or anything is appended or prepended.
149 * The terminating '\\0' is not written, of course.
150 */
151RTR3DECL(int) RTStrmPutStr(PRTSTREAM pStream, const char *pszString);
152
153/**
154 * Reads a line from a file stream.
155 * A line ends with a '\\n', '\\0' or the end of the file.
156 *
157 * @returns iprt status code.
158 * @returns VINF_BUFFER_OVERFLOW if the buffer wasn't big enough to read an entire line.
159 * @param pStream The stream.
160 * @param pszString Where to store the line.
161 * The line will *NOT* contain any '\\n'.
162 * @param cchString The size of the string buffer.
163 */
164RTR3DECL(int) RTStrmGetLine(PRTSTREAM pStream, char *pszString, size_t cchString);
165
166/**
167 * Flushes a stream.
168 *
169 * @returns iprt status code.
170 * @param pStream The stream to flush.
171 */
172RTR3DECL(int) RTStrmFlush(PRTSTREAM pStream);
173
174/**
175 * Prints a formatted string to the specified stream.
176 *
177 * @returns Number of bytes printed.
178 * @param pStream The stream to print to.
179 * @param pszFormat Runtime format string.
180 * @param ... Arguments specified by pszFormat.
181 */
182RTR3DECL(int) RTStrmPrintf(PRTSTREAM pStream, const char *pszFormat, ...);
183
184/**
185 * Prints a formatted string to the specified stream.
186 *
187 * @returns Number of bytes printed.
188 * @param pStream The stream to print to.
189 * @param pszFormat Runtime format string.
190 * @param args Arguments specified by pszFormat.
191 */
192RTR3DECL(int) RTStrmPrintfV(PRTSTREAM pStream, const char *pszFormat, va_list args);
193
194/**
195 * Prints a formatted string to the standard output stream (g_pStdOut).
196 *
197 * @returns Number of bytes printed.
198 * @param pszFormat Runtime format string.
199 * @param ... Arguments specified by pszFormat.
200 */
201RTR3DECL(int) RTPrintf(const char *pszFormat, ...);
202
203/**
204 * Prints a formatted string to the standard output stream (g_pStdOut).
205 *
206 * @returns Number of bytes printed.
207 * @param pszFormat Runtime format string.
208 * @param args Arguments specified by pszFormat.
209 */
210RTR3DECL(int) RTPrintfV(const char *pszFormat, va_list args);
211
212/** @} */
213
214__END_DECLS
215
216#endif
217
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