1 | /** @file
|
---|
2 | *
|
---|
3 | * InnoTek Portable Runtime - I/O Stream.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * If you received this file as part of a commercial VirtualBox
|
---|
18 | * distribution, then only the terms of your commercial VirtualBox
|
---|
19 | * license agreement apply instead of the previous paragraph.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef __iprt_stream_h__
|
---|
23 | #define __iprt_stream_h__
|
---|
24 |
|
---|
25 | #include <iprt/cdefs.h>
|
---|
26 | #include <iprt/types.h>
|
---|
27 | #include <iprt/stdarg.h>
|
---|
28 |
|
---|
29 | __BEGIN_DECLS
|
---|
30 |
|
---|
31 | /** @defgroup grp_rt_stream RTStrm - File Streams
|
---|
32 | * @ingroup grp_rt
|
---|
33 | * @{
|
---|
34 | */
|
---|
35 |
|
---|
36 | /** Pointer to a stream. */
|
---|
37 | typedef struct RTSTREAM *PRTSTREAM;
|
---|
38 |
|
---|
39 | /** Pointer to the standard input stream. */
|
---|
40 | extern RTDATADECL(PRTSTREAM) g_pStdIn;
|
---|
41 |
|
---|
42 | /** Pointer to the standard error stream. */
|
---|
43 | extern RTDATADECL(PRTSTREAM) g_pStdErr;
|
---|
44 |
|
---|
45 | /** Pointer to the standard output stream. */
|
---|
46 | extern RTDATADECL(PRTSTREAM) g_pStdOut;
|
---|
47 |
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Opens a file stream.
|
---|
51 | *
|
---|
52 | * @returns iprt status code.
|
---|
53 | * @param pszFilename Path to the file to open.
|
---|
54 | * @param pszMode The open mode. See fopen() standard.
|
---|
55 | * Format: <a|r|w>[+][b|t]
|
---|
56 | * @param ppStream Where to store the opened stream.
|
---|
57 | */
|
---|
58 | RTR3DECL(int) RTStrmOpen(const char *pszFilename, const char *pszMode, PRTSTREAM *ppStream);
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Closes the specified stream.
|
---|
62 | *
|
---|
63 | * @returns iprt status code.
|
---|
64 | * @param pStream The stream to close.
|
---|
65 | */
|
---|
66 | RTR3DECL(int) RTStrmClose(PRTSTREAM pStream);
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Reads from a file stream.
|
---|
70 | *
|
---|
71 | * @returns iprt status code.
|
---|
72 | * @param pStream The stream.
|
---|
73 | * @param pvBuf Where to put the read bits.
|
---|
74 | * Must be cbRead bytes or more.
|
---|
75 | * @param cbRead Number of bytes to read.
|
---|
76 | * @param pcbRead Where to store the number of bytes actually read.
|
---|
77 | * If NULL cbRead bytes are read or an error is returned.
|
---|
78 | */
|
---|
79 | RTR3DECL(int) RTStrmReadEx(PRTSTREAM pStream, void *pvBuf, size_t cbRead, size_t *pcbRead);
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Writes to a file stream.
|
---|
83 | *
|
---|
84 | * @returns iprt status code.
|
---|
85 | * @param pStream The stream.
|
---|
86 | * @param pvBuf Where to get the bits to write from.
|
---|
87 | * @param cbWrite Number of bytes to write.
|
---|
88 | * @param pcbWritten Where to store the number of bytes actually written.
|
---|
89 | * If NULL cbWrite bytes are written or an error is returned.
|
---|
90 | */
|
---|
91 | RTR3DECL(int) RTStrmWriteEx(PRTSTREAM pStream, const void *pvBuf, size_t cbWrite, size_t *pcbWritten);
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * Reads from a file stream.
|
---|
95 | *
|
---|
96 | * @returns iprt status code.
|
---|
97 | * @param pStream The stream.
|
---|
98 | * @param pvBuf Where to put the read bits.
|
---|
99 | * Must be cbRead bytes or more.
|
---|
100 | * @param cbRead Number of bytes to read.
|
---|
101 | */
|
---|
102 | DECLINLINE(int) RTStrmRead(PRTSTREAM pStream, void *pvBuf, size_t cbRead)
|
---|
103 | {
|
---|
104 | return RTStrmReadEx(pStream, pvBuf, cbRead, NULL);
|
---|
105 | }
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * Writes to a file stream.
|
---|
109 | *
|
---|
110 | * @returns iprt status code.
|
---|
111 | * @param pStream The stream.
|
---|
112 | * @param pvBuf Where to get the bits to write from.
|
---|
113 | * @param cbWrite Number of bytes to write.
|
---|
114 | */
|
---|
115 | DECLINLINE(int) RTStrmWrite(PRTSTREAM pStream, const void *pvBuf, size_t cbWrite)
|
---|
116 | {
|
---|
117 | return RTStrmWriteEx(pStream, pvBuf, cbWrite, NULL);
|
---|
118 | }
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Reads a character from a file stream.
|
---|
122 | *
|
---|
123 | * @returns The char as an unsigned char cast to int.
|
---|
124 | * @returns -1 on failure.
|
---|
125 | * @param pStream The stream.
|
---|
126 | */
|
---|
127 | RTR3DECL(int) RTStrmGetCh(PRTSTREAM pStream);
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Writes a character to a file stream.
|
---|
131 | *
|
---|
132 | * @returns iprt status code.
|
---|
133 | * @param pStream The stream.
|
---|
134 | * @param ch The char to write.
|
---|
135 | */
|
---|
136 | RTR3DECL(int) RTStrmPutCh(PRTSTREAM pStream, int ch);
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * Writes a string to a file stream.
|
---|
140 | *
|
---|
141 | * @returns iprt status code.
|
---|
142 | * @param pStream The stream.
|
---|
143 | * @param pszString The string to write.
|
---|
144 | * No newlines or anything is appended or prepended.
|
---|
145 | * The terminating '\\0' is not written, of course.
|
---|
146 | */
|
---|
147 | RTR3DECL(int) RTStrmPutStr(PRTSTREAM pStream, const char *pszString);
|
---|
148 |
|
---|
149 | /**
|
---|
150 | * Reads a line from a file stream.
|
---|
151 | * A line ends with a '\\n', '\\0' or the end of the file.
|
---|
152 | *
|
---|
153 | * @returns iprt status code.
|
---|
154 | * @returns VINF_BUFFER_OVERFLOW if the buffer wasn't big enough to read an entire line.
|
---|
155 | * @param pStream The stream.
|
---|
156 | * @param pszString Where to store the line.
|
---|
157 | * The line will *NOT* contain any '\\n'.
|
---|
158 | * @param cchString The size of the string buffer.
|
---|
159 | */
|
---|
160 | RTR3DECL(int) RTStrmGetLine(PRTSTREAM pStream, char *pszString, size_t cchString);
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * Flushes a stream.
|
---|
164 | *
|
---|
165 | * @returns iprt status code.
|
---|
166 | * @param pStream The stream to flush.
|
---|
167 | */
|
---|
168 | RTR3DECL(int) RTStrmFlush(PRTSTREAM pStream);
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * Prints a formatted string to the specified stream.
|
---|
172 | *
|
---|
173 | * @returns Number of bytes printed.
|
---|
174 | * @param pStream The stream to print to.
|
---|
175 | * @param pszFormat Runtime format string.
|
---|
176 | * @param ... Arguments specified by pszFormat.
|
---|
177 | */
|
---|
178 | RTR3DECL(int) RTStrmPrintf(PRTSTREAM pStream, const char *pszFormat, ...);
|
---|
179 |
|
---|
180 | /**
|
---|
181 | * Prints a formatted string to the specified stream.
|
---|
182 | *
|
---|
183 | * @returns Number of bytes printed.
|
---|
184 | * @param pStream The stream to print to.
|
---|
185 | * @param pszFormat Runtime format string.
|
---|
186 | * @param args Arguments specified by pszFormat.
|
---|
187 | */
|
---|
188 | RTR3DECL(int) RTStrmPrintfV(PRTSTREAM pStream, const char *pszFormat, va_list args);
|
---|
189 |
|
---|
190 | /**
|
---|
191 | * Prints a formatted string to the standard output stream (g_pStdOut).
|
---|
192 | *
|
---|
193 | * @returns Number of bytes printed.
|
---|
194 | * @param pszFormat Runtime format string.
|
---|
195 | * @param ... Arguments specified by pszFormat.
|
---|
196 | */
|
---|
197 | RTR3DECL(int) RTPrintf(const char *pszFormat, ...);
|
---|
198 |
|
---|
199 | /**
|
---|
200 | * Prints a formatted string to the standard output stream (g_pStdOut).
|
---|
201 | *
|
---|
202 | * @returns Number of bytes printed.
|
---|
203 | * @param pszFormat Runtime format string.
|
---|
204 | * @param args Arguments specified by pszFormat.
|
---|
205 | */
|
---|
206 | RTR3DECL(int) RTPrintfV(const char *pszFormat, va_list args);
|
---|
207 |
|
---|
208 | /** @} */
|
---|
209 |
|
---|
210 | __END_DECLS
|
---|
211 |
|
---|
212 | #endif
|
---|
213 |
|
---|