Author: sebor
Date: Tue Jan 24 17:14:14 2006
New Revision: 372072
URL: http://svn.apache.org/viewcvs?rev=372072&view=rev
Log:
2006-01-24 Martin Sebor <[EMAIL PROTECTED]>
* printf.cpp (_rw_vfprintf): Allowed rw_file* argument to be null
to permit executing special directives that generate no characters,
and avoided attempting to produce output.
Modified:
incubator/stdcxx/trunk/tests/src/printf.cpp
Modified: incubator/stdcxx/trunk/tests/src/printf.cpp
URL:
http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/printf.cpp?rev=372072&r1=372071&r2=372072&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/printf.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/printf.cpp Tue Jan 24 17:14:14 2006
@@ -3878,36 +3878,45 @@
static int
_rw_vfprintf (rw_file *file, const char *fmt, va_list va)
{
- RW_ASSERT (0 != file);
-
char* buf = 0;
size_t bufsize = 0;
const int nchars = rw_vasnprintf (&buf, &bufsize, fmt, va);
- // FIXME: implement this in terms of POSIX write()
- // for async-signal safety
- FILE* const stdio_file = _RWSTD_REINTERPRET_CAST (FILE*, file);
-
- const int nwrote = 0 < nchars ?
- fwrite (buf, 1, nchars, stdio_file) : nchars;
-
- // flush in case stderr isn't line-buffered (e.g., when
- // it's determined not to refer to a terminal device,
- // for example after it has been redirected to a file)
- fflush (stdio_file);
+ int nwrote = nchars;
-#ifdef _MSC_VER
+ if (0 < nchars) {
- // IsDebuggerPresent() depends on the macros _WIN32_WINNT and WINVER
- // being appropriately #defined prior to the #inclusion of <windows.h>
- if (IsDebuggerPresent ()) {
+ // avoid formatting when there's nothing to output
- // write string to the attached debugger (if any)
- OutputDebugString (buf);
- }
+ if (file) {
+ // allow null file argument
+
+ // FIXME: implement this in terms of POSIX write()
+ // for async-signal safety
+ FILE* const stdio_file = _RWSTD_REINTERPRET_CAST (FILE*, file);
+
+ nwrote = fwrite (buf, 1, nchars, stdio_file);
+
+ // flush in case stderr isn't line-buffered (e.g., when
+ // it's determined not to refer to a terminal device,
+ // for example after it has been redirected to a file)
+ fflush (stdio_file);
+ }
+
+#ifdef _MSC_VER
+
+ // IsDebuggerPresent() depends on the macros _WIN32_WINNT and WINVER
+ // being appropriately #defined prior to the #inclusion of <windows.h>
+ if (IsDebuggerPresent ()) {
+
+ // write string to the attached debugger (if any)
+ OutputDebugString (buf);
+ }
#endif // _MSC_VER
+
+ }
free (buf);