summaryrefslogtreecommitdiff
path: root/ACE/ace/OS_NS_stdio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ACE/ace/OS_NS_stdio.cpp')
-rw-r--r--ACE/ace/OS_NS_stdio.cpp48
1 files changed, 40 insertions, 8 deletions
diff --git a/ACE/ace/OS_NS_stdio.cpp b/ACE/ace/OS_NS_stdio.cpp
index c4b23cb1904..c428ab2f762 100644
--- a/ACE/ace/OS_NS_stdio.cpp
+++ b/ACE/ace/OS_NS_stdio.cpp
@@ -299,7 +299,7 @@ ACE_OS::fprintf (FILE *fp, const wchar_t *format, ...)
int
ACE_OS::printf (const char *format, ...)
{
- // ACE_OS_TRACE ("ACE_OS::printf");
+ ACE_OS_TRACE ("ACE_OS::printf");
int result;
va_list ap;
va_start (ap, format);
@@ -312,12 +312,41 @@ int
ACE_OS::snprintf (char *buf, size_t maxlen, const char *format, ...)
{
// ACE_OS_TRACE ("ACE_OS::snprintf");
+#if defined (ACE_HAS_SNPRINTF)
int result;
va_list ap;
va_start (ap, format);
- result = ACE_OS::vsnprintf (buf, maxlen, format, ap);
+# if !defined (ACE_WIN32) || (defined (__BORLANDC__) && (__BORLANDC__ >= 0x600))
+ ACE_OSCALL (ACE_SPRINTF_ADAPTER (::vsnprintf (buf, maxlen, format, ap)),
+ int, -1, result);
+# else
+ ACE_OSCALL (ACE_SPRINTF_ADAPTER (::_vsnprintf (buf, maxlen, format, ap)),
+ int, -1, result);
+ // Win32 doesn't regard a full buffer with no 0-terminate as an
+ // overrun.
+ if (result == static_cast <int> (maxlen))
+ result = -1;
+
+ // Win32 doesn't 0-terminate the string if it overruns maxlen.
+ if (result == -1)
+ buf[maxlen-1] = '\0';
+# endif /* !ACE_WIN32 || __BORLANDC__ >= 0x600 */
va_end (ap);
+ // In out-of-range conditions, C99 defines vsnprintf to return the number
+ // of characters that would have been written if enough space was available.
+ // Earlier variants of the vsnprintf() (e.g. UNIX98) defined it to return
+ // -1. This method follows the C99 standard, but needs to guess at the
+ // value; uses maxlen + 1.
+ if (result == -1)
+ result = static_cast <int> (maxlen + 1);
return result;
+
+#else
+ ACE_UNUSED_ARG (buf);
+ ACE_UNUSED_ARG (maxlen);
+ ACE_UNUSED_ARG (format);
+ ACE_NOTSUP_RETURN (-1);
+#endif /* ACE_HAS_SNPRINTF */
}
#if defined (ACE_HAS_WCHAR)
@@ -336,8 +365,10 @@ ACE_OS::snprintf (wchar_t *buf, size_t maxlen, const wchar_t *format, ...)
// Microsoft's vswprintf() doesn't have the maxlen argument that
// XPG4/UNIX98 define. They do, however, recommend use of _vsnwprintf()
// as a substitute, which does have the same signature as the UNIX98 one.
- ACE_OSCALL (::_vsnwprintf (buf, maxlen, format, ap), int, -1, result);
- // Win32 doesn't regard a full buffer with no 0-terminate as an overrun.
+ ACE_OSCALL (ACE_SPRINTF_ADAPTER (::_vsnwprintf (buf, maxlen, format, ap)),
+ int, -1, result);
+ // Win32 doesn't regard a full buffer with no 0-terminate as an
+ // overrun.
if (result == static_cast <int> (maxlen))
result = -1;
@@ -345,7 +376,8 @@ ACE_OS::snprintf (wchar_t *buf, size_t maxlen, const wchar_t *format, ...)
if (result == -1)
buf[maxlen-1] = '\0';
# else
- ACE_OSCALL (::vswprintf (buf, maxlen, format, ap), int, -1, result);
+ ACE_OSCALL (ACE_SPRINTF_ADAPTER (::vswprintf (buf, maxlen, format, ap)),
+ int, -1, result);
# endif /* ACE_WIN32 */
va_end (ap);
// In out-of-range conditions, C99 defines vsnprintf to return the number
@@ -357,12 +389,12 @@ ACE_OS::snprintf (wchar_t *buf, size_t maxlen, const wchar_t *format, ...)
result = static_cast <int> (maxlen + 1);
return result;
-# else
+#else
ACE_UNUSED_ARG (buf);
ACE_UNUSED_ARG (maxlen);
ACE_UNUSED_ARG (format);
ACE_NOTSUP_RETURN (-1);
-# endif /* _XOPEN_SOURCE ... */
+#endif /* ACE_HAS_SNPRINTF */
}
#endif /* ACE_HAS_WCHAR */
@@ -374,7 +406,7 @@ ACE_OS::sprintf (char *buf, const char *format, ...)
int result;
va_list ap;
va_start (ap, format);
- ACE_OSCALL (::vsprintf (buf, format, ap), int, -1, result);
+ ACE_OSCALL (ACE_SPRINTF_ADAPTER (::vsprintf (buf, format, ap)), int, -1, result);
va_end (ap);
return result;
}