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 2222extern " C" {
2323#endif
2424
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+
2533/* *
2634 * Reads a line from the input stream and stores it into the buffer pointed to by 'buf'.
2735 *
@@ -171,6 +179,16 @@ namespace fossil {
171179 */
172180 class Input {
173181 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+
174192 /* *
175193 * Reads a line from the input stream and stores it into the buffer pointed to by 'buf'.
176194 *
Original file line number Diff line number Diff line change @@ -88,6 +88,20 @@ void fossil_io_show_progress(int progress) {
8888 fflush (stdout );
8989}
9090
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+
91105// Function to get a sanitized line of input from a provided stream (or stdin by default)
92106char * fossil_io_gets_from_stream (char * buf , size_t size , FILE * input_stream ) {
93107 if (buf == NULL || size == 0 || input_stream == NULL ) {
You can’t perform that action at this time.
0 commit comments