summaryrefslogtreecommitdiff
path: root/sql/log.cc
diff options
context:
space:
mode:
authorDavi Arnaut <davi.arnaut@oracle.com>2011-01-07 17:30:52 -0200
committerDavi Arnaut <davi.arnaut@oracle.com>2011-01-07 17:30:52 -0200
commitd4ffbd3ee0ed0b37bafa80dc5ec5e2a03ceb8695 (patch)
tree44fc4a56c4acc6d8be58b9aaf0eddb1f8e89eb29 /sql/log.cc
parentb342d3e763a54fe2d1cb02bc744890c61deeb3c7 (diff)
parent844d6ed4b26e676418eb3867682fc1a2949e4706 (diff)
downloadmariadb-git-d4ffbd3ee0ed0b37bafa80dc5ec5e2a03ceb8695.tar.gz
Merge of mysql-5.1 into mysql-5.5.
Diffstat (limited to 'sql/log.cc')
-rw-r--r--sql/log.cc74
1 files changed, 10 insertions, 64 deletions
diff --git a/sql/log.cc b/sql/log.cc
index b9be66f8ce7..7ab4b6b4a61 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -5686,80 +5686,26 @@ void sql_perror(const char *message)
}
-#ifdef __WIN__
+/*
+ Change the file associated with two output streams. Used to
+ redirect stdout and stderr to a file. The streams are reopened
+ only for appending (writing at end of file).
+*/
extern "C" my_bool reopen_fstreams(const char *filename,
FILE *outstream, FILE *errstream)
{
- int handle_fd;
- int err_fd, out_fd;
- HANDLE osfh;
-
- DBUG_ASSERT(filename && errstream);
-
- // Services don't have stdout/stderr on Windows, so _fileno returns -1.
- err_fd= _fileno(errstream);
- if (err_fd < 0)
- {
- if (!freopen(filename, "a+", errstream))
- return TRUE;
-
- setbuf(errstream, NULL);
- err_fd= _fileno(errstream);
- }
-
- if (outstream)
- {
- out_fd= _fileno(outstream);
- if (out_fd < 0)
- {
- if (!freopen(filename, "a+", outstream))
- return TRUE;
- out_fd= _fileno(outstream);
- }
- }
-
- if ((osfh= CreateFile(filename, GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE |
- FILE_SHARE_DELETE, NULL,
- OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL,
- NULL)) == INVALID_HANDLE_VALUE)
+ if (outstream && !my_freopen(filename, "a", outstream))
return TRUE;
- if ((handle_fd= _open_osfhandle((intptr_t)osfh,
- _O_APPEND | _O_TEXT)) == -1)
- {
- CloseHandle(osfh);
+ if (errstream && !my_freopen(filename, "a", errstream))
return TRUE;
- }
- if (_dup2(handle_fd, err_fd) < 0)
- {
- CloseHandle(osfh);
- return TRUE;
- }
-
- if (outstream && _dup2(handle_fd, out_fd) < 0)
- {
- CloseHandle(osfh);
- return TRUE;
- }
-
- _close(handle_fd);
- return FALSE;
-}
-#else
-extern "C" my_bool reopen_fstreams(const char *filename,
- FILE *outstream, FILE *errstream)
-{
- if (outstream && !freopen(filename, "a+", outstream))
- return TRUE;
-
- if (errstream && !freopen(filename, "a+", errstream))
- return TRUE;
+ /* The error stream must be unbuffered. */
+ if (errstream)
+ setbuf(errstream, NULL);
return FALSE;
}
-#endif
/*