diff options
author | zelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573> | 2009-02-01 18:09:50 +0000 |
---|---|---|
committer | zelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573> | 2009-02-01 18:09:50 +0000 |
commit | 25666681f2cb8bfd3d5dfeb4894f0e45bf54e354 (patch) | |
tree | 4e5333f3e08ad545bf52d1435c7ecda81eff483c /crawl-ref | |
parent | 4509d7ddb91687e36b29358d924ef3d5ec22785d (diff) | |
download | crawl-ref-25666681f2cb8bfd3d5dfeb4894f0e45bf54e354.tar.gz crawl-ref-25666681f2cb8bfd3d5dfeb4894f0e45bf54e354.zip |
Get the crash dumping code to compile on MGW.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8876 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r-- | crawl-ref/source/debug.cc | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc index e354a56700..10fc310b18 100644 --- a/crawl-ref/source/debug.cc +++ b/crawl-ref/source/debug.cc @@ -6540,26 +6540,20 @@ void do_crash_dump() sprintf(name, "%scrash-%s-%d.txt", dir.c_str(), you.your_name, (int) time(NULL)); - FILE* file = fopen(name, "w"); + fprintf(stderr, EOL "Writing crash info to %s" EOL, name); + errno = 0; + FILE* file = freopen(name, "w+", stderr); - if (file == NULL) + if (file == NULL || errno != 0) { - fprintf(stderr, EOL "Unable to open file '%s' for writing: %s" EOL, + fprintf(stdout, EOL "Unable to open file '%s' for writing: %s" EOL, name, strerror(errno)); - file = stderr; + file = stdout; } - else - { - fprintf(stderr, EOL "Writing crash info to %s" EOL, name); - // Merge stderr into file, so that the lua stack dumping functions - // (and anything else that uses stderr) will send everything to - // the output file. - dup2(fileno(file), fileno(stderr)); - - // Unbuffer the output file stream, to match with stderr. - setvbuf(file, NULL, _IONBF, 0); - } + // Unbuffer the file, since if we recursively crash buffered lines + // won't make it to the file. + setvbuf(file, NULL, _IONBF, 0); set_msg_dump_file(file); |