@@ -83,6 +83,68 @@ int fossil_io_validate_input_buffer(const char *buf, size_t size);
8383 */
8484char *fossil_io_gets_utf8 (char *buf, size_t size, FILE *input_stream);
8585
86+ /* *
87+ * @brief Validates if the input string is a valid integer.
88+ *
89+ * @param input The input string to validate.
90+ * @param output Pointer to an integer where the parsed value will be stored if valid.
91+ * @return true if the input is a valid integer, false otherwise.
92+ */
93+ int fossil_io_validate_is_int (const char *input, int *output);
94+
95+ /* *
96+ * @brief Validates if the input string is a valid float.
97+ *
98+ * @param input The input string to validate.
99+ * @param output Pointer to a float where the parsed value will be stored if valid.
100+ * @return true if the input is a valid float, false otherwise.
101+ */
102+ int fossil_io_validate_is_float (const char *input, float *output);
103+
104+ /* *
105+ * @brief Validates if the input string contains only alphanumeric characters.
106+ *
107+ * @param input The input string to validate.
108+ * @return true if the input is alphanumeric, false otherwise.
109+ */
110+ int fossil_io_validate_is_alnum (const char *input);
111+
112+ /* *
113+ * @brief Validates if the input string is a valid email address.
114+ *
115+ * @param input The input string to validate.
116+ * @return true if the input is a valid email address, false otherwise.
117+ */
118+ int fossil_io_validate_is_email (const char *input);
119+
120+ /* *
121+ * @brief Validates if the input string does not exceed the specified maximum length.
122+ *
123+ * @param input The input string to validate.
124+ * @param max_length The maximum allowed length of the input string.
125+ * @return true if the input length is within the specified limit, false otherwise.
126+ */
127+ int fossil_io_validate_is_length (const char *input, size_t max_length);
128+
129+ /* *
130+ * @brief Sanitizes the input string and stores the sanitized result in the output buffer.
131+ *
132+ * @param input The input string to sanitize.
133+ * @param output The buffer where the sanitized string will be stored.
134+ * @param output_size The size of the output buffer.
135+ * @return A fossil_io_validate_error_t indicating the result of the sanitization process.
136+ */
137+ int fossil_io_validate_sanitize_string (const char *input, char *output, size_t output_size);
138+
139+ /* *
140+ * @brief Reads a secure line of input into the provided buffer.
141+ *
142+ * @param buffer The buffer where the input will be stored.
143+ * @param buffer_size The size of the buffer.
144+ * @return A fossil_io_validate_error_t indicating the result of the input reading process.
145+ */
146+ int fossil_io_validate_read_secure_line (char *buffer, size_t buffer_size);
147+
86148#ifdef __cplusplus
87149}
88150
@@ -149,6 +211,115 @@ namespace fossil {
149211 return fossil_io_gets_utf8 (buf, size, input_stream);
150212 }
151213
214+ /* *
215+ * Reads formatted input from the standard input stream.
216+ *
217+ * @param format The format string specifying how the input should be interpreted.
218+ * @param ... Additional arguments for storing the input values.
219+ * @return On success, the number of input items successfully matched and assigned is returned.
220+ * On failure, EOF is returned.
221+ */
222+ static int scanf (const char *format, ...) {
223+ va_list args;
224+ va_start (args, format);
225+ int result = fossil_io_scanf (format, args);
226+ va_end (args);
227+ return result;
228+ }
229+
230+ /* *
231+ * Reads formatted input from the specified input stream.
232+ *
233+ * @param input_stream Pointer to the input stream to read from.
234+ * @param format The format string specifying how the input should be interpreted.
235+ * @param ... Additional arguments for storing the input values.
236+ * @return On success, the number of input items successfully matched and assigned is returned.
237+ * On failure, EOF is returned.
238+ */
239+ static int fscanf (FILE *input_stream, const char *format, ...) {
240+ va_list args;
241+ va_start (args, format);
242+ int result = fossil_io_fscanf (input_stream, format, args);
243+ va_end (args);
244+ return result;
245+ }
246+
247+ /* *
248+ * @brief Validates if the input string is a valid integer.
249+ *
250+ * @param input The input string to validate.
251+ * @param output Pointer to an integer where the parsed value will be stored if valid.
252+ * @return true if the input is a valid integer, false otherwise.
253+ */
254+ static int validate_is_int (const char *input, int *output) {
255+ return fossil_io_validate_is_int (input, output);
256+ }
257+
258+ /* *
259+ * @brief Validates if the input string is a valid float.
260+ *
261+ * @param input The input string to validate.
262+ * @param output Pointer to a float where the parsed value will be stored if valid.
263+ * @return true if the input is a valid float, false otherwise.
264+ */
265+ static int validate_is_float (const char *input, float *output) {
266+ return fossil_io_validate_is_float (input, output);
267+ }
268+
269+ /* *
270+ * @brief Validates if the input string contains only alphanumeric characters.
271+ *
272+ * @param input The input string to validate.
273+ * @return true if the input is alphanumeric, false otherwise.
274+ */
275+ static int validate_is_alnum (const char *input) {
276+ return fossil_io_validate_is_alnum (input);
277+ }
278+
279+ /* *
280+ * @brief Validates if the input string is a valid email address.
281+ *
282+ * @param input The input string to validate.
283+ * @return true if the input is a valid email address, false otherwise.
284+ */
285+ static int validate_is_email (const char *input) {
286+ return fossil_io_validate_is_email (input);
287+ }
288+
289+ /* *
290+ * @brief Validates if the input string does not exceed the specified maximum length.
291+ *
292+ * @param input The input string to validate.
293+ * @param max_length The maximum allowed length of the input string.
294+ * @return true if the input length is within the specified limit, false otherwise.
295+ */
296+ static int validate_is_length (const char *input, size_t max_length) {
297+ return fossil_io_validate_is_length (input, max_length);
298+ }
299+
300+ /* *
301+ * @brief Sanitizes the input string and stores the sanitized result in the output buffer.
302+ *
303+ * @param input The input string to sanitize.
304+ * @param output The buffer where the sanitized string will be stored.
305+ * @param output_size The size of the output buffer.
306+ * @return A fossil_io_validate_error_t indicating the result of the sanitization process.
307+ */
308+ static int validate_sanitize_string (const char *input, char *output, size_t output_size) {
309+ return fossil_io_validate_sanitize_string (input, output, output_size);
310+ }
311+
312+ /* *
313+ * @brief Reads a secure line of input into the provided buffer.
314+ *
315+ * @param buffer The buffer where the input will be stored.
316+ * @param buffer_size The size of the buffer.
317+ * @return A fossil_io_validate_error_t indicating the result of the input reading process.
318+ */
319+ static int validate_read_secure_line (char *buffer, size_t buffer_size) {
320+ return fossil_io_validate_read_secure_line (buffer, buffer_size);
321+ }
322+
152323 };
153324
154325 }
0 commit comments