From abe324a14284bc441ec9f4eef704a8d668dcfcb0 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Thu, 4 Jan 2007 13:51:32 +0000 Subject: [1626673] When croaking in files.cc, make sure the user can see the error message. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@784 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/stuff.cc | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'crawl-ref/source/stuff.cc') diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc index 521edb0699..cdbc70b862 100644 --- a/crawl-ref/source/stuff.cc +++ b/crawl-ref/source/stuff.cc @@ -479,10 +479,34 @@ void io_cleanup() #endif } -void end(int end_arg) +void end(int exit_code, bool print_error, const char *format, ...) { + std::string error = print_error? strerror(errno) : ""; + io_cleanup(); - exit(end_arg); + + if (format) + { + va_list arg; + va_start(arg, format); + char buffer[500]; + vsnprintf(buffer, sizeof buffer, format, arg); + va_end(arg); + + if (error.empty()) + error = std::string(buffer); + else + error = std::string(buffer) + ": " + error; + } + + if (error.length()) + { + if (error[error.length() - 1] != '\n') + error += "\n"; + fprintf(stderr, "%s", error.c_str()); + } + + exit(exit_code); } void redraw_screen(void) -- cgit v1.2.3-54-g00ecf