VirtualBox

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

Last change on this file since 55420 was 54724, checked in by vboxsync, 10 years ago

Runtime/RTStream: Make it possible to disable echoing of typed characters from terminal input streams

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.0 KB
Line 
1/** @file
2 * IPRT - I/O Stream.
3 */
4
5/*
6 * Copyright (C) 2006-2012 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 * Changes the stream mode.
117 *
118 * @returns iprt status code.
119 * @param pStream The stream.
120 * @param fBinary The desired binary (@c true) / text mode (@c false).
121 * Pass -1 to leave it unchanged.
122 * @param fCurrentCodeSet Whether converting the stream from UTF-8 to the
123 * current code set is desired (@c true) or not (@c
124 * false). Pass -1 to leave this property unchanged.
125 */
126RTR3DECL(int) RTStrmSetMode(PRTSTREAM pStream, int fBinary, int fCurrentCodeSet);
127
128/**
129 * Returns the current echo mode.
130 * This works only for standard input streams.
131 *
132 * @returns iprt status code.
133 * @param pStream The stream.
134 * @param pfEchoChars Where to store the flag whether typed characters are echoed.
135 */
136RTR3DECL(int) RTStrmInputGetEchoChars(PRTSTREAM pStream, bool *pfEchoChars);
137
138/**
139 * Changes the behavior for echoing inpit characters on the command line.
140 * This works only for standard input streams.
141 *
142 * @returns iprt status code.
143 * @param pStream The stream.
144 * @param fEchoChars Flag whether echoing typed characters is wanted.
145 */
146RTR3DECL(int) RTStrmInputSetEchoChars(PRTSTREAM pStream, bool fEchoChars);
147
148/**
149 * Rewinds the stream.
150 *
151 * Stream errors will be reset on success.
152 *
153 * @returns IPRT status code.
154 *
155 * @param pStream The stream.
156 *
157 * @remarks Not all streams are rewindable and that behavior is currently
158 * undefined for those.
159 */
160RTR3DECL(int) RTStrmRewind(PRTSTREAM pStream);
161
162/**
163 * Reads from a file stream.
164 *
165 * @returns iprt status code.
166 * @param pStream The stream.
167 * @param pvBuf Where to put the read bits.
168 * Must be cbRead bytes or more.
169 * @param cbRead Number of bytes to read.
170 * @param pcbRead Where to store the number of bytes actually read.
171 * If NULL cbRead bytes are read or an error is returned.
172 */
173RTR3DECL(int) RTStrmReadEx(PRTSTREAM pStream, void *pvBuf, size_t cbRead, size_t *pcbRead);
174
175/**
176 * Writes to a file stream.
177 *
178 * @returns iprt status code.
179 * @param pStream The stream.
180 * @param pvBuf Where to get the bits to write from.
181 * @param cbWrite Number of bytes to write.
182 * @param pcbWritten Where to store the number of bytes actually written.
183 * If NULL cbWrite bytes are written or an error is returned.
184 */
185RTR3DECL(int) RTStrmWriteEx(PRTSTREAM pStream, const void *pvBuf, size_t cbWrite, size_t *pcbWritten);
186
187/**
188 * Reads from a file stream.
189 *
190 * @returns iprt status code.
191 * @param pStream The stream.
192 * @param pvBuf Where to put the read bits.
193 * Must be cbRead bytes or more.
194 * @param cbRead Number of bytes to read.
195 */
196DECLINLINE(int) RTStrmRead(PRTSTREAM pStream, void *pvBuf, size_t cbRead)
197{
198 return RTStrmReadEx(pStream, pvBuf, cbRead, NULL);
199}
200
201/**
202 * Writes to a file stream.
203 *
204 * @returns iprt status code.
205 * @param pStream The stream.
206 * @param pvBuf Where to get the bits to write from.
207 * @param cbWrite Number of bytes to write.
208 */
209DECLINLINE(int) RTStrmWrite(PRTSTREAM pStream, const void *pvBuf, size_t cbWrite)
210{
211 return RTStrmWriteEx(pStream, pvBuf, cbWrite, NULL);
212}
213
214/**
215 * Reads a character from a file stream.
216 *
217 * @returns The char as an unsigned char cast to int.
218 * @returns -1 on failure.
219 * @param pStream The stream.
220 */
221RTR3DECL(int) RTStrmGetCh(PRTSTREAM pStream);
222
223/**
224 * Writes a character to a file stream.
225 *
226 * @returns iprt status code.
227 * @param pStream The stream.
228 * @param ch The char to write.
229 */
230RTR3DECL(int) RTStrmPutCh(PRTSTREAM pStream, int ch);
231
232/**
233 * Writes a string to a file stream.
234 *
235 * @returns iprt status code.
236 * @param pStream The stream.
237 * @param pszString The string to write.
238 * No newlines or anything is appended or prepended.
239 * The terminating '\\0' is not written, of course.
240 */
241RTR3DECL(int) RTStrmPutStr(PRTSTREAM pStream, const char *pszString);
242
243/**
244 * Reads a line from a file stream.
245 *
246 * A line ends with a '\\n', '\\r\\n', '\\0' or the end of the file.
247 *
248 * @returns iprt status code.
249 * @retval VINF_BUFFER_OVERFLOW if the buffer wasn't big enough to read an
250 * entire line.
251 * @retval VERR_BUFFER_OVERFLOW if a lone '\\r' was encountered at the end of
252 * the buffer and we ended up dropping the following character.
253 *
254 * @param pStream The stream.
255 * @param pszString Where to store the line.
256 * The line will *NOT* contain any '\\n'.
257 * @param cbString The size of the string buffer.
258 */
259RTR3DECL(int) RTStrmGetLine(PRTSTREAM pStream, char *pszString, size_t cbString);
260
261/**
262 * Flushes a stream.
263 *
264 * @returns iprt status code.
265 * @param pStream The stream to flush.
266 */
267RTR3DECL(int) RTStrmFlush(PRTSTREAM pStream);
268
269/**
270 * Prints a formatted string to the specified stream.
271 *
272 * @returns Number of bytes printed.
273 * @param pStream The stream to print to.
274 * @param pszFormat Runtime format string.
275 * @param ... Arguments specified by pszFormat.
276 */
277RTR3DECL(int) RTStrmPrintf(PRTSTREAM pStream, const char *pszFormat, ...);
278
279/**
280 * Prints a formatted string to the specified stream.
281 *
282 * @returns Number of bytes printed.
283 * @param pStream The stream to print to.
284 * @param pszFormat Runtime format string.
285 * @param args Arguments specified by pszFormat.
286 */
287RTR3DECL(int) RTStrmPrintfV(PRTSTREAM pStream, const char *pszFormat, va_list args);
288
289/**
290 * Dumper vprintf-like function outputting to a stream.
291 *
292 * @param pvUser The stream to print to. NULL means standard output.
293 * @param pszFormat Runtime format string.
294 * @param va Arguments specified by pszFormat.
295 */
296RTR3DECL(void) RTStrmDumpPrintfV(void *pvUser, const char *pszFormat, va_list va);
297
298/**
299 * Prints a formatted string to the standard output stream (g_pStdOut).
300 *
301 * @returns Number of bytes printed.
302 * @param pszFormat Runtime format string.
303 * @param ... Arguments specified by pszFormat.
304 */
305RTR3DECL(int) RTPrintf(const char *pszFormat, ...);
306
307/**
308 * Prints a formatted string to the standard output stream (g_pStdOut).
309 *
310 * @returns Number of bytes printed.
311 * @param pszFormat Runtime format string.
312 * @param args Arguments specified by pszFormat.
313 */
314RTR3DECL(int) RTPrintfV(const char *pszFormat, va_list args);
315
316/** @} */
317
318RT_C_DECLS_END
319
320#endif
321
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