File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 22
22
extern " C" {
23
23
#endif
24
24
25
+ /* *
26
+ * Reads a single character from the input stream.
27
+ *
28
+ * @param input_stream Pointer to the input stream to read from.
29
+ * @return The character read as an unsigned char cast to an int, or EOF on end-of-file or error.
30
+ */
31
+ int fossil_io_getc (FILE *input_stream);
32
+
25
33
/* *
26
34
* Reads a line from the input stream and stores it into the buffer pointed to by 'buf'.
27
35
*
@@ -171,6 +179,16 @@ namespace fossil {
171
179
*/
172
180
class Input {
173
181
public:
182
+ /* *
183
+ * Reads a single character from the input stream.
184
+ *
185
+ * @param input_stream Pointer to the input stream to read from.
186
+ * @return The character read as an unsigned char cast to an int, or EOF on end-of-file or error.
187
+ */
188
+ static int getc (FILE *input_stream) {
189
+ return fossil_io_getc (input_stream);
190
+ }
191
+
174
192
/* *
175
193
* Reads a line from the input stream and stores it into the buffer pointed to by 'buf'.
176
194
*
Original file line number Diff line number Diff line change @@ -88,6 +88,20 @@ void fossil_io_show_progress(int progress) {
88
88
fflush (stdout );
89
89
}
90
90
91
+ int fossil_io_getc (FILE * input_stream ) {
92
+ if (input_stream == NULL ) {
93
+ fprintf (stderr , "Error: Invalid input stream.\n" );
94
+ return EOF ;
95
+ }
96
+
97
+ int c = fgetc (input_stream );
98
+ if (c == EOF && ferror (input_stream )) {
99
+ fprintf (stderr , "Error: Failed to read from input stream.\n" );
100
+ }
101
+
102
+ return c ;
103
+ }
104
+
91
105
// Function to get a sanitized line of input from a provided stream (or stdin by default)
92
106
char * fossil_io_gets_from_stream (char * buf , size_t size , FILE * input_stream ) {
93
107
if (buf == NULL || size == 0 || input_stream == NULL ) {
You can’t perform that action at this time.
0 commit comments