From 0435bbf91540e1ef2ec232fc7aa891b79e366c99 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michael=20G=C3=B6hler?= Date: Sun, 21 Sep 2014 14:12:29 +0200 Subject: [PATCH] error handling for freopen() --- mdp.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mdp.c b/mdp.c index 3bf1bd2..3d38e3f 100644 --- a/mdp.c +++ b/mdp.c @@ -109,8 +109,13 @@ int main(int argc, char *argv[]) { fclose(input); // replace stdin with current tty if input was a pipe - if(input == stdin) - freopen("/dev/tty", "rw", stdin); + if(input == stdin) { + input = freopen("/dev/tty", "rw", stdin); + if(!input) { + fprintf(stderr, "%s: %s: %s\n", argv[0], "/dev/tty", strerror(errno)); + exit(EXIT_FAILURE); + } + } if(debug > 0) { markdown_debug(deck, debug); -- 2.20.1