From: Michael Göhler Date: Sun, 21 Sep 2014 12:12:29 +0000 (+0200) Subject: error handling for freopen() X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=0435bbf91540e1ef2ec232fc7aa891b79e366c99;p=smdp.git error handling for freopen() --- 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);