From d34a1c8598ac7f521ccc77f3c45cc7fc19e8a56e Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Mon, 19 Nov 2007 18:15:36 -0500 Subject: [PATCH] Make sure the file specified file descriptor to pwmc doesn't fail when calling fdopen(). --- pwmc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pwmc.c b/pwmc.c index 535a17ef..6c3b18c2 100644 --- a/pwmc.c +++ b/pwmc.c @@ -132,7 +132,7 @@ int main(int argc, char *argv[]) char *pinentry_path = NULL; char *display = NULL, *tty = NULL, *ttytype = NULL; struct termios term; - int outfd = -1; + int outfd = STDOUT_FILENO; FILE *outfp = stdout; setlocale(LC_ALL, ""); @@ -152,6 +152,10 @@ int main(int argc, char *argv[]) break; case 'd': outfd = atoi(optarg); + outfp = fdopen(outfd, "w"); + + if (!outfp) + err(EXIT_FAILURE, "%i", outfd); break; case 'E': do_exit = 1; @@ -266,9 +270,6 @@ int main(int argc, char *argv[]) signal(SIGALRM, SIG_IGN); elapsed = 0; - if (outfd != -1) - outfp = fdopen(outfd, "w"); - while ((p = fgets(command, sizeof(command), stdin)) != NULL) { int len = strlen(p); char *t; -- 2.11.4.GIT