VirtualBox

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

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

rebranding: IPRT files again.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 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
37__BEGIN_DECLS
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 * Closes the specified stream.
70 *
71 * @returns iprt status code.
72 * @param pStream The stream to close.
73 */
74RTR3DECL(int) RTStrmClose(PRTSTREAM pStream);
75
76/**
77 * Reads from a file stream.
78 *
79 * @returns iprt status code.
80 * @param pStream The stream.
81 * @param pvBuf Where to put the read bits.
82 * Must be cbRead bytes or more.
83 * @param cbRead Number of bytes to read.
84 * @param pcbRead Where to store the number of bytes actually read.
85 * If NULL cbRead bytes are read or an error is returned.
86 */
87RTR3DECL(int) RTStrmReadEx(PRTSTREAM pStream, void *pvBuf, size_t cbRead, size_t *pcbRead);
88
89/**
90 * Writes to a file stream.
91 *
92 * @returns iprt status code.
93 * @param pStream The stream.
94 * @param pvBuf Where to get the bits to write from.
95 * @param cbWrite Number of bytes to write.
96 * @param pcbWritten Where to store the number of bytes actually written.
97 * If NULL cbWrite bytes are written or an error is returned.
98 */
99RTR3DECL(int) RTStrmWriteEx(PRTSTREAM pStream, const void *pvBuf, size_t cbWrite, size_t *pcbWritten);
100
101/**
102 * Reads from a file stream.
103 *
104 * @returns iprt status code.
105 * @param pStream The stream.
106 * @param pvBuf Where to put the read bits.
107 * Must be cbRead bytes or more.
108 * @param cbRead Number of bytes to read.
109 */
110DECLINLINE(int) RTStrmRead(PRTSTREAM pStream, void *pvBuf, size_t cbRead)
111{
112 return RTStrmReadEx(pStream, pvBuf, cbRead, NULL);
113}
114
115/**
116 * Writes to a file stream.
117 *
118 * @returns iprt status code.
119 * @param pStream The stream.
120 * @param pvBuf Where to get the bits to write from.
121 * @param cbWrite Number of bytes to write.
122 */
123DECLINLINE(int) RTStrmWrite(PRTSTREAM pStream, const void *pvBuf, size_t cbWrite)
124{
125 return RTStrmWriteEx(pStream, pvBuf, cbWrite, NULL);
126}
127
128/**
129 * Reads a character from a file stream.
130 *
131 * @returns The char as an unsigned char cast to int.
132 * @returns -1 on failure.
133 * @param pStream The stream.
134 */
135RTR3DECL(int) RTStrmGetCh(PRTSTREAM pStream);
136
137/**
138 * Writes a character to a file stream.
139 *
140 * @returns iprt status code.
141 * @param pStream The stream.
142 * @param ch The char to write.
143 */
144RTR3DECL(int) RTStrmPutCh(PRTSTREAM pStream, int ch);
145
146/**
147 * Writes a string to a file stream.
148 *
149 * @returns iprt status code.
150 * @param pStream The stream.
151 * @param pszString The string to write.
152 * No newlines or anything is appended or prepended.
153 * The terminating '\\0' is not written, of course.
154 */
155RTR3DECL(int) RTStrmPutStr(PRTSTREAM pStream, const char *pszString);
156
157/**
158 * Reads a line from a file stream.
159 * A line ends with a '\\n', '\\0' or the end of the file.
160 *
161 * @returns iprt status code.
162 * @returns VINF_BUFFER_OVERFLOW if the buffer wasn't big enough to read an entire line.
163 * @param pStream The stream.
164 * @param pszString Where to store the line.
165 * The line will *NOT* contain any '\\n'.
166 * @param cchString The size of the string buffer.
167 */
168RTR3DECL(int) RTStrmGetLine(PRTSTREAM pStream, char *pszString, size_t cchString);
169
170/**
171 * Flushes a stream.
172 *
173 * @returns iprt status code.
174 * @param pStream The stream to flush.
175 */
176RTR3DECL(int) RTStrmFlush(PRTSTREAM pStream);
177
178/**
179 * Prints a formatted string to the specified stream.
180 *
181 * @returns Number of bytes printed.
182 * @param pStream The stream to print to.
183 * @param pszFormat Runtime format string.
184 * @param ... Arguments specified by pszFormat.
185 */
186RTR3DECL(int) RTStrmPrintf(PRTSTREAM pStream, const char *pszFormat, ...);
187
188/**
189 * Prints a formatted string to the specified stream.
190 *
191 * @returns Number of bytes printed.
192 * @param pStream The stream to print to.
193 * @param pszFormat Runtime format string.
194 * @param args Arguments specified by pszFormat.
195 */
196RTR3DECL(int) RTStrmPrintfV(PRTSTREAM pStream, const char *pszFormat, va_list args);
197
198/**
199 * Prints a formatted string to the standard output stream (g_pStdOut).
200 *
201 * @returns Number of bytes printed.
202 * @param pszFormat Runtime format string.
203 * @param ... Arguments specified by pszFormat.
204 */
205RTR3DECL(int) RTPrintf(const char *pszFormat, ...);
206
207/**
208 * Prints a formatted string to the standard output stream (g_pStdOut).
209 *
210 * @returns Number of bytes printed.
211 * @param pszFormat Runtime format string.
212 * @param args Arguments specified by pszFormat.
213 */
214RTR3DECL(int) RTPrintfV(const char *pszFormat, va_list args);
215
216/** @} */
217
218__END_DECLS
219
220#endif
221
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