summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/stuff.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-01-04 13:51:32 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-01-04 13:51:32 +0000
commitabe324a14284bc441ec9f4eef704a8d668dcfcb0 (patch)
tree18618cb4ead26314c9673fe0d4592fb896bb8874 /crawl-ref/source/stuff.cc
parent5e88f223672ce4d126cfeb08544959eec9abb8a1 (diff)
downloadcrawl-ref-abe324a14284bc441ec9f4eef704a8d668dcfcb0.tar.gz
crawl-ref-abe324a14284bc441ec9f4eef704a8d668dcfcb0.zip
[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
Diffstat (limited to 'crawl-ref/source/stuff.cc')
-rw-r--r--crawl-ref/source/stuff.cc28
1 files changed, 26 insertions, 2 deletions
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)