VirtualBox

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

Last change on this file since 34066 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 KB
Line 
1/** @file
2 * IPRT - I/O Stream.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Oracle Corporation
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
33RT_C_DECLS_BEGIN
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 * Opens a file stream.
66 *
67 * @returns iprt status code.
68 * @param pszMode The open mode. See fopen() standard.
69 * Format: <a|r|w>[+][b|t]
70 * @param ppStream Where to store the opened stream.
71 * @param pszFilenameFmt Filename path format string.
72 * @param args Arguments to the format string.
73 */
74RTR3DECL(int) RTStrmOpenFV(const char *pszMode, PRTSTREAM *ppStream, const char *pszFilenameFmt, va_list args);
75
76/**
77 * Opens a file stream.
78 *
79 * @returns iprt status code.
80 * @param pszMode The open mode. See fopen() standard.
81 * Format: <a|r|w>[+][b|t]
82 * @param ppStream Where to store the opened stream.
83 * @param pszFilenameFmt Filename path format string.
84 * @param ... Arguments to the format string.
85 */
86RTR3DECL(int) RTStrmOpenF(const char *pszMode, PRTSTREAM *ppStream, const char *pszFilenameFmt, ...);
87
88/**
89 * Closes the specified stream.
90 *
91 * @returns iprt status code.
92 * @param pStream The stream to close.
93 */
94RTR3DECL(int) RTStrmClose(PRTSTREAM pStream);
95
96/**
97 * Get the pending error of the stream.
98 *
99 * @returns iprt status code. of the stream.
100 * @param pStream The stream.
101 */
102RTR3DECL(int) RTStrmError(PRTSTREAM pStream);
103
104/**
105 * Clears stream error condition.
106 *
107 * All stream operations save RTStrmClose and this will fail
108 * while an error is asserted on the stream
109 *
110 * @returns iprt status code.
111 * @param pStream The stream.
112 */
113RTR3DECL(int) RTStrmClearError(PRTSTREAM pStream);
114
115/**
116 * Rewinds the stream.
117 *
118 * Stream errors will be reset on success.
119 *
120 * @returns IPRT status code.
121 *
122 * @param pStream The stream.
123 *
124 * @remarks Not all streams are rewindable and that behavior is currently
125 * undefined for those.
126 */
127RTR3DECL(int) RTStrmRewind(PRTSTREAM pStream);
128
129/**
130 * Reads from a file stream.
131 *
132 * @returns iprt status code.
133 * @param pStream The stream.
134 * @param pvBuf Where to put the read bits.
135 * Must be cbRead bytes or more.
136 * @param cbRead Number of bytes to read.
137 * @param pcbRead Where to store the number of bytes actually read.
138 * If NULL cbRead bytes are read or an error is returned.
139 */
140RTR3DECL(int) RTStrmReadEx(PRTSTREAM pStream, void *pvBuf, size_t cbRead, size_t *pcbRead);
141
142/**
143 * Writes to a file stream.
144 *
145 * @returns iprt status code.
146 * @param pStream The stream.
147 * @param pvBuf Where to get the bits to write from.
148 * @param cbWrite Number of bytes to write.
149 * @param pcbWritten Where to store the number of bytes actually written.
150 * If NULL cbWrite bytes are written or an error is returned.
151 */
152RTR3DECL(int) RTStrmWriteEx(PRTSTREAM pStream, const void *pvBuf, size_t cbWrite, size_t *pcbWritten);
153
154/**
155 * Reads from a file stream.
156 *
157 * @returns iprt status code.
158 * @param pStream The stream.
159 * @param pvBuf Where to put the read bits.
160 * Must be cbRead bytes or more.
161 * @param cbRead Number of bytes to read.
162 */
163DECLINLINE(int) RTStrmRead(PRTSTREAM pStream, void *pvBuf, size_t cbRead)
164{
165 return RTStrmReadEx(pStream, pvBuf, cbRead, NULL);
166}
167
168/**
169 * Writes to a file stream.
170 *
171 * @returns iprt status code.
172 * @param pStream The stream.
173 * @param pvBuf Where to get the bits to write from.
174 * @param cbWrite Number of bytes to write.
175 */
176DECLINLINE(int) RTStrmWrite(PRTSTREAM pStream, const void *pvBuf, size_t cbWrite)
177{
178 return RTStrmWriteEx(pStream, pvBuf, cbWrite, NULL);
179}
180
181/**
182 * Reads a character from a file stream.
183 *
184 * @returns The char as an unsigned char cast to int.
185 * @returns -1 on failure.
186 * @param pStream The stream.
187 */
188RTR3DECL(int) RTStrmGetCh(PRTSTREAM pStream);
189
190/**
191 * Writes a character to a file stream.
192 *
193 * @returns iprt status code.
194 * @param pStream The stream.
195 * @param ch The char to write.
196 */
197RTR3DECL(int) RTStrmPutCh(PRTSTREAM pStream, int ch);
198
199/**
200 * Writes a string to a file stream.
201 *
202 * @returns iprt status code.
203 * @param pStream The stream.
204 * @param pszString The string to write.
205 * No newlines or anything is appended or prepended.
206 * The terminating '\\0' is not written, of course.
207 */
208RTR3DECL(int) RTStrmPutStr(PRTSTREAM pStream, const char *pszString);
209
210/**
211 * Reads a line from a file stream.
212 * A line ends with a '\\n', '\\0' or the end of the file.
213 *
214 * @returns iprt status code.
215 * @returns VINF_BUFFER_OVERFLOW if the buffer wasn't big enough to read an entire line.
216 * @param pStream The stream.
217 * @param pszString Where to store the line.
218 * The line will *NOT* contain any '\\n'.
219 * @param cchString The size of the string buffer.
220 */
221RTR3DECL(int) RTStrmGetLine(PRTSTREAM pStream, char *pszString, size_t cchString);
222
223/**
224 * Flushes a stream.
225 *
226 * @returns iprt status code.
227 * @param pStream The stream to flush.
228 */
229RTR3DECL(int) RTStrmFlush(PRTSTREAM pStream);
230
231/**
232 * Prints a formatted string to the specified stream.
233 *
234 * @returns Number of bytes printed.
235 * @param pStream The stream to print to.
236 * @param pszFormat Runtime format string.
237 * @param ... Arguments specified by pszFormat.
238 */
239RTR3DECL(int) RTStrmPrintf(PRTSTREAM pStream, const char *pszFormat, ...);
240
241/**
242 * Prints a formatted string to the specified stream.
243 *
244 * @returns Number of bytes printed.
245 * @param pStream The stream to print to.
246 * @param pszFormat Runtime format string.
247 * @param args Arguments specified by pszFormat.
248 */
249RTR3DECL(int) RTStrmPrintfV(PRTSTREAM pStream, const char *pszFormat, va_list args);
250
251/**
252 * Prints a formatted string to the standard output stream (g_pStdOut).
253 *
254 * @returns Number of bytes printed.
255 * @param pszFormat Runtime format string.
256 * @param ... Arguments specified by pszFormat.
257 */
258RTR3DECL(int) RTPrintf(const char *pszFormat, ...);
259
260/**
261 * Prints a formatted string to the standard output stream (g_pStdOut).
262 *
263 * @returns Number of bytes printed.
264 * @param pszFormat Runtime format string.
265 * @param args Arguments specified by pszFormat.
266 */
267RTR3DECL(int) RTPrintfV(const char *pszFormat, va_list args);
268
269/** @} */
270
271RT_C_DECLS_END
272
273#endif
274
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