42sh/src/io_backend/io_backend.h

44 lines
1,021 B
C
Raw Normal View History

2026-01-08 14:40:37 +01:00
#ifndef IO_BACKEND_H
#define IO_BACKEND_H
#include <sys/types.h>
enum iob_mode {
IOB_MODE_NULL = 0,
IOB_MODE_STDIN,
IOB_MODE_SCRIPT,
IOB_MODE_CMD
};
/* @struct iob_context
* @var mode
* @var args contains
* the script name when mode is set to IOB_SCRIPT,
* the command to execute when mode is set to IOB_CMD,
*/
struct iob_context {
enum iob_mode mode;
char* args;
};
/*
* @brief Initializes the IO Backend module
*
* @param context contains the input mode and the args
* @return 0 on success, the corresponding error code otherwise
*/
int iob_init(struct iob_context *context);
2026-01-08 15:02:33 +01:00
/* @brief Closes the opened buffers and exits the modules gracefully
2026-01-08 14:40:37 +01:00
*/
2026-01-08 15:02:33 +01:00
void iob_close(void);
2026-01-08 14:40:37 +01:00
2026-01-08 15:02:33 +01:00
/* @brief reads at most one line of the input and stores it into *stream
2026-01-08 14:40:37 +01:00
*
2026-01-08 15:02:33 +01:00
* @param stream is a pointer that will be set to a string to parse
* @return the number of read characters if positive, the error code otherwise
2026-01-08 14:40:37 +01:00
*/
ssize_t stream_read(char** stream);
#endif /* ! IO_BACKEND_H */