diff options
| author | Tristan Riehs <tristan.riehs@inria.fr> | 2026-08-02 20:01:28 +0200 |
|---|---|---|
| committer | Tristan Riehs <tristan.riehs@inria.fr> | 2026-08-02 20:01:28 +0200 |
| commit | 0c317a065282c8f00c5277799e155aa58a55b7ca (patch) | |
| tree | 117eaf6153afc2d354d5943ea4edae5c8950d2da /src | |
| parent | e61e95d1699ffe04cab3a7caa952c3425fd1e5bb (diff) | |
Add readline_with_check readline wrapper
Diffstat (limited to 'src')
| -rw-r--r-- | src/input.c | 10 | ||||
| -rw-r--r-- | src/input.h | 3 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/input.c b/src/input.c index 94777bb..ec3a766 100644 --- a/src/input.c +++ b/src/input.c @@ -37,3 +37,13 @@ void remove_ending_newline(char *str) assert(str[idx] == '\n'); str[idx] = '\0'; } + +char *readline_with_check(const char *prompt) +{ + char *input = readline(prompt); + if (input == NULL) { + perror("readline"); + exit(EXIT_FAILURE); + } + return input; +} diff --git a/src/input.h b/src/input.h index 7085bac..13a53d5 100644 --- a/src/input.h +++ b/src/input.h @@ -9,4 +9,7 @@ int prompt_yes_no(void); void remove_ending_newline(char *str); +/* Readline wrapper that aborts if readline returns NULL. */ +char *readline_with_check(const char *prompt); + #endif |
