VirtualBox

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

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

*: s/RT_\(BEGIN|END\)_DECLS/RT_C_DECLS_\1/g

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 KB
Line 
1/** @file
2 * IPRT - I/O Stream.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___iprt_stream_h
31#define ___iprt_stream_h
32
33#include <iprt/cdefs.h>
34#include <iprt/types.h>
35#include <iprt/stdarg.h>
36
37RT_C_DECLS_BEGIN
38
39/** @defgroup grp_rt_stream RTStrm - File Streams
40 * @ingroup grp_rt
41 * @{
42 */
43
44/** Pointer to a stream. */
45typedef struct RTSTREAM *PRTSTREAM;
46
47/** Pointer to the standard input stream. */
48extern RTDATADECL(PRTSTREAM) g_pStdIn;
49
50/** Pointer to the standard error stream. */
51extern RTDATADECL(PRTSTREAM) g_pStdErr;
52
53/** Pointer to the standard output stream. */
54extern RTDATADECL(PRTSTREAM) g_pStdOut;
55
56
57/**
58 * Opens a file stream.
59 *
60 * @returns iprt status code.
61 * @param pszFilename Path to the file to open.
62 * @param pszMode The open mode. See fopen() standard.
63 * Format: <a|r|w>[+][b|t]
64 * @param ppStream Where to store the opened stream.
65 */
66RTR3DECL(int) RTStrmOpen(const char *pszFilename, const char *pszMode, PRTSTREAM *ppStream);
67
68/**
69 * Opens a file stream.
70 *
71 * @returns iprt status code.
72 * @param pszMode The open mode. See fopen() standard.
73 * Format: <a|r|w>[+][b|t]
74 * @param ppStream Where to store the opened stream.
75 * @param pszFilenameFmt Filename path format string.
76 * @param args Arguments to the format string.
77 */
78RTR3DECL(int) RTStrmOpenFV(const char *pszMode, PRTSTREAM *ppStream, const char *pszFilenameFmt, va_list args);
79
80/**
81 * Opens a file stream.
82 *
83 * @returns iprt status code.
84 * @param pszMode The open mode. See fopen() standard.
85 * Format: <a|r|w>[+][b|t]
86 * @param ppStream Where to store the opened stream.
87 * @param pszFilenameFmt Filename path format string.
88 * @param ... Arguments to the format string.
89 */
90RTR3DECL(int) RTStrmOpenF(const char *pszMode, PRTSTREAM *ppStream, const char *pszFilenameFmt, ...);
91
92/**
93 * Closes the specified stream.
94 *
95 * @returns iprt status code.
96 * @param pStream The stream to close.
97 */
98RTR3DECL(int) RTStrmClose(PRTSTREAM pStream);
99
100/**
101 * Get the pending error of the stream.
102 *
103 * @returns iprt status code. of the stream.
104 * @param pStream The stream.
105 */
106RTR3DECL(int) RTStrmError(PRTSTREAM pStream);
107
108/**
109 * Clears stream error condition.
110 *
111 * All stream operations save RTStrmClose and this will fail
112 * while an error is asserted on the stream
113 *
114 * @returns iprt status code.
115 * @param pStream The stream.
116 */
117RTR3DECL(int) RTStrmClearError(PRTSTREAM pStream);
118
119/**
120 * Reads from a file stream.
121 *
122 * @returns iprt status code.
123 * @param pStream The stream.
124 * @param pvBuf Where to put the read bits.
125 * Must be cbRead bytes or more.
126 * @param cbRead Number of bytes to read.
127 * @param pcbRead Where to store the number of bytes actually read.
128 * If NULL cbRead bytes are read or an error is returned.
129 */
130RTR3DECL(int) RTStrmReadEx(PRTSTREAM pStream, void *pvBuf, size_t cbRead, size_t *pcbRead);
131
132/**
133 * Writes to a file stream.
134 *
135 * @returns iprt status code.
136 * @param pStream The stream.
137 * @param pvBuf Where to get the bits to write from.
138 * @param cbWrite Number of bytes to write.
139 * @param pcbWritten Where to store the number of bytes actually written.
140 * If NULL cbWrite bytes are written or an error is returned.
141 */
142RTR3DECL(int) RTStrmWriteEx(PRTSTREAM pStream, const void *pvBuf, size_t cbWrite, size_t *pcbWritten);
143
144/**
145 * Reads from a file stream.
146 *
147 * @returns iprt status code.
148 * @param pStream The stream.
149 * @param pvBuf Where to put the read bits.
150 * Must be cbRead bytes or more.
151 * @param cbRead Number of bytes to read.
152 */
153DECLINLINE(int) RTStrmRead(PRTSTREAM pStream, void *pvBuf, size_t cbRead)
154{
155 return RTStrmReadEx(pStream, pvBuf, cbRead, NULL);
156}
157
158/**
159 * Writes to a file stream.
160 *
161 * @returns iprt status code.
162 * @param pStream The stream.
163 * @param pvBuf Where to get the bits to write from.
164 * @param cbWrite Number of bytes to write.
165 */
166DECLINLINE(int) RTStrmWrite(PRTSTREAM pStream, const void *pvBuf, size_t cbWrite)
167{
168 return RTStrmWriteEx(pStream, pvBuf, cbWrite, NULL);
169}
170
171/**
172 * Reads a character from a file stream.
173 *
174 * @returns The char as an unsigned char cast to int.
175 * @returns -1 on failure.
176 * @param pStream The stream.
177 */
178RTR3DECL(int) RTStrmGetCh(PRTSTREAM pStream);
179
180/**
181 * Writes a character to a file stream.
182 *
183 * @returns iprt status code.
184 * @param pStream The stream.
185 * @param ch The char to write.
186 */
187RTR3DECL(int) RTStrmPutCh(PRTSTREAM pStream, int ch);
188
189/**
190 * Writes a string to a file stream.
191 *
192 * @returns iprt status code.
193 * @param pStream The stream.
194 * @param pszString The string to write.
195 * No newlines or anything is appended or prepended.
196 * The terminating '\\0' is not written, of course.
197 */
198RTR3DECL(int) RTStrmPutStr(PRTSTREAM pStream, const char *pszString);
199
200/**
201 * Reads a line from a file stream.
202 * A line ends with a '\\n', '\\0' or the end of the file.
203 *
204 * @returns iprt status code.
205 * @returns VINF_BUFFER_OVERFLOW if the buffer wasn't big enough to read an entire line.
206 * @param pStream The stream.
207 * @param pszString Where to store the line.
208 * The line will *NOT* contain any '\\n'.
209 * @param cchString The size of the string buffer.
210 */
211RTR3DECL(int) RTStrmGetLine(PRTSTREAM pStream, char *pszString, size_t cchString);
212
213/**
214 * Flushes a stream.
215 *
216 * @returns iprt status code.
217 * @param pStream The stream to flush.
218 */
219RTR3DECL(int) RTStrmFlush(PRTSTREAM pStream);
220
221/**
222 * Prints a formatted string to the specified stream.
223 *
224 * @returns Number of bytes printed.
225 * @param pStream The stream to print to.
226 * @param pszFormat Runtime format string.
227 * @param ... Arguments specified by pszFormat.
228 */
229RTR3DECL(int) RTStrmPrintf(PRTSTREAM pStream, const char *pszFormat, ...);
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 args Arguments specified by pszFormat.
238 */
239RTR3DECL(int) RTStrmPrintfV(PRTSTREAM pStream, const char *pszFormat, va_list args);
240
241/**
242 * Prints a formatted string to the standard output stream (g_pStdOut).
243 *
244 * @returns Number of bytes printed.
245 * @param pszFormat Runtime format string.
246 * @param ... Arguments specified by pszFormat.
247 */
248RTR3DECL(int) RTPrintf(const char *pszFormat, ...);
249
250/**
251 * Prints a formatted string to the standard output stream (g_pStdOut).
252 *
253 * @returns Number of bytes printed.
254 * @param pszFormat Runtime format string.
255 * @param args Arguments specified by pszFormat.
256 */
257RTR3DECL(int) RTPrintfV(const char *pszFormat, va_list args);
258
259/** @} */
260
261RT_C_DECLS_END
262
263#endif
264
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