From: Chris Lattner Date: Fri, 11 Apr 2008 06:14:11 +0000 (+0000) Subject: Fix rdar://5843510 don't assert and die when an invalid output X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8808f0020fd0e36dc5d537275c6dfa7654a69f3b;p=clang Fix rdar://5843510 don't assert and die when an invalid output file is specified, print a happy little error message. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49518 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/PrintPreprocessedOutput.cpp b/Driver/PrintPreprocessedOutput.cpp index 68a2f954ed..105e99e9c4 100644 --- a/Driver/PrintPreprocessedOutput.cpp +++ b/Driver/PrintPreprocessedOutput.cpp @@ -60,8 +60,14 @@ static void InitOutputBuffer(const std::string& Output) { if (!Output.size() || Output == "-") OutputFILE = stdout; else { - OutputFILE = fopen(Output.c_str(), "w+"); OutputFilename = Output; + OutputFILE = fopen(Output.c_str(), "w+"); + + if (OutputFILE == 0) { + fprintf(stderr, "Error opening output file '%s'.\n", Output.c_str()); + exit(1); + } + } assert(OutputFILE && "failed to open output file"); @@ -73,11 +79,13 @@ static void InitOutputBuffer(const std::string& Output) { if (!Output.size() || Output == "-") OutputFD = STDOUT_FILENO; else { - OutputFD = open(Output.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0644); OutputFilename = Output; + OutputFD = open(Output.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0644); + if (OutputFD < 0) { + fprintf(stderr, "Error opening output file '%s'.\n", Output.c_str()); + exit(1); + } } - - assert(OutputFD >= 0 && "failed to open output file"); #endif }