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. */
|
---|
45 | typedef struct RTSTREAM *PRTSTREAM;
|
---|
46 |
|
---|
47 | /** Pointer to the standard input stream. */
|
---|
48 | extern RTDATADECL(PRTSTREAM) g_pStdIn;
|
---|
49 |
|
---|
50 | /** Pointer to the standard error stream. */
|
---|
51 | extern RTDATADECL(PRTSTREAM) g_pStdErr;
|
---|
52 |
|
---|
53 | /** Pointer to the standard output stream. */
|
---|
54 | extern 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 | */
|
---|
66 | RTR3DECL(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 | */
|
---|
78 | RTR3DECL(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 | */
|
---|
90 | RTR3DECL(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 | */
|
---|
98 | RTR3DECL(int) RTStrmClose(PRTSTREAM pStream);
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Reads from a file stream.
|
---|
102 | *
|
---|
103 | * @returns iprt status code.
|
---|
104 | * @param pStream The stream.
|
---|
105 | * @param pvBuf Where to put the read bits.
|
---|
106 | * Must be cbRead bytes or more.
|
---|
107 | * @param cbRead Number of bytes to read.
|
---|
108 | * @param pcbRead Where to store the number of bytes actually read.
|
---|
109 | * If NULL cbRead bytes are read or an error is returned.
|
---|
110 | */
|
---|
111 | RTR3DECL(int) RTStrmReadEx(PRTSTREAM pStream, void *pvBuf, size_t cbRead, size_t *pcbRead);
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Writes to a file stream.
|
---|
115 | *
|
---|
116 | * @returns iprt status code.
|
---|
117 | * @param pStream The stream.
|
---|
118 | * @param pvBuf Where to get the bits to write from.
|
---|
119 | * @param cbWrite Number of bytes to write.
|
---|
120 | * @param pcbWritten Where to store the number of bytes actually written.
|
---|
121 | * If NULL cbWrite bytes are written or an error is returned.
|
---|
122 | */
|
---|
123 | RTR3DECL(int) RTStrmWriteEx(PRTSTREAM pStream, const void *pvBuf, size_t cbWrite, size_t *pcbWritten);
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Reads from a file stream.
|
---|
127 | *
|
---|
128 | * @returns iprt status code.
|
---|
129 | * @param pStream The stream.
|
---|
130 | * @param pvBuf Where to put the read bits.
|
---|
131 | * Must be cbRead bytes or more.
|
---|
132 | * @param cbRead Number of bytes to read.
|
---|
133 | */
|
---|
134 | DECLINLINE(int) RTStrmRead(PRTSTREAM pStream, void *pvBuf, size_t cbRead)
|
---|
135 | {
|
---|
136 | return RTStrmReadEx(pStream, pvBuf, cbRead, NULL);
|
---|
137 | }
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * Writes to a file stream.
|
---|
141 | *
|
---|
142 | * @returns iprt status code.
|
---|
143 | * @param pStream The stream.
|
---|
144 | * @param pvBuf Where to get the bits to write from.
|
---|
145 | * @param cbWrite Number of bytes to write.
|
---|
146 | */
|
---|
147 | DECLINLINE(int) RTStrmWrite(PRTSTREAM pStream, const void *pvBuf, size_t cbWrite)
|
---|
148 | {
|
---|
149 | return RTStrmWriteEx(pStream, pvBuf, cbWrite, NULL);
|
---|
150 | }
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Reads a character from a file stream.
|
---|
154 | *
|
---|
155 | * @returns The char as an unsigned char cast to int.
|
---|
156 | * @returns -1 on failure.
|
---|
157 | * @param pStream The stream.
|
---|
158 | */
|
---|
159 | RTR3DECL(int) RTStrmGetCh(PRTSTREAM pStream);
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * Writes a character to a file stream.
|
---|
163 | *
|
---|
164 | * @returns iprt status code.
|
---|
165 | * @param pStream The stream.
|
---|
166 | * @param ch The char to write.
|
---|
167 | */
|
---|
168 | RTR3DECL(int) RTStrmPutCh(PRTSTREAM pStream, int ch);
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * Writes a string to a file stream.
|
---|
172 | *
|
---|
173 | * @returns iprt status code.
|
---|
174 | * @param pStream The stream.
|
---|
175 | * @param pszString The string to write.
|
---|
176 | * No newlines or anything is appended or prepended.
|
---|
177 | * The terminating '\\0' is not written, of course.
|
---|
178 | */
|
---|
179 | RTR3DECL(int) RTStrmPutStr(PRTSTREAM pStream, const char *pszString);
|
---|
180 |
|
---|
181 | /**
|
---|
182 | * Reads a line from a file stream.
|
---|
183 | * A line ends with a '\\n', '\\0' or the end of the file.
|
---|
184 | *
|
---|
185 | * @returns iprt status code.
|
---|
186 | * @returns VINF_BUFFER_OVERFLOW if the buffer wasn't big enough to read an entire line.
|
---|
187 | * @param pStream The stream.
|
---|
188 | * @param pszString Where to store the line.
|
---|
189 | * The line will *NOT* contain any '\\n'.
|
---|
190 | * @param cchString The size of the string buffer.
|
---|
191 | */
|
---|
192 | RTR3DECL(int) RTStrmGetLine(PRTSTREAM pStream, char *pszString, size_t cchString);
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * Flushes a stream.
|
---|
196 | *
|
---|
197 | * @returns iprt status code.
|
---|
198 | * @param pStream The stream to flush.
|
---|
199 | */
|
---|
200 | RTR3DECL(int) RTStrmFlush(PRTSTREAM pStream);
|
---|
201 |
|
---|
202 | /**
|
---|
203 | * Prints a formatted string to the specified stream.
|
---|
204 | *
|
---|
205 | * @returns Number of bytes printed.
|
---|
206 | * @param pStream The stream to print to.
|
---|
207 | * @param pszFormat Runtime format string.
|
---|
208 | * @param ... Arguments specified by pszFormat.
|
---|
209 | */
|
---|
210 | RTR3DECL(int) RTStrmPrintf(PRTSTREAM pStream, const char *pszFormat, ...);
|
---|
211 |
|
---|
212 | /**
|
---|
213 | * Prints a formatted string to the specified stream.
|
---|
214 | *
|
---|
215 | * @returns Number of bytes printed.
|
---|
216 | * @param pStream The stream to print to.
|
---|
217 | * @param pszFormat Runtime format string.
|
---|
218 | * @param args Arguments specified by pszFormat.
|
---|
219 | */
|
---|
220 | RTR3DECL(int) RTStrmPrintfV(PRTSTREAM pStream, const char *pszFormat, va_list args);
|
---|
221 |
|
---|
222 | /**
|
---|
223 | * Prints a formatted string to the standard output stream (g_pStdOut).
|
---|
224 | *
|
---|
225 | * @returns Number of bytes printed.
|
---|
226 | * @param pszFormat Runtime format string.
|
---|
227 | * @param ... Arguments specified by pszFormat.
|
---|
228 | */
|
---|
229 | RTR3DECL(int) RTPrintf(const char *pszFormat, ...);
|
---|
230 |
|
---|
231 | /**
|
---|
232 | * Prints a formatted string to the standard output stream (g_pStdOut).
|
---|
233 | *
|
---|
234 | * @returns Number of bytes printed.
|
---|
235 | * @param pszFormat Runtime format string.
|
---|
236 | * @param args Arguments specified by pszFormat.
|
---|
237 | */
|
---|
238 | RTR3DECL(int) RTPrintfV(const char *pszFormat, va_list args);
|
---|
239 |
|
---|
240 | /** @} */
|
---|
241 |
|
---|
242 | __END_DECLS
|
---|
243 |
|
---|
244 | #endif
|
---|
245 |
|
---|