sl@0: /************************************************************************
sl@0:  *
sl@0:  * printf.h - declarations of the rw_printf family of functions
sl@0:  *
sl@0:  * $Id: printf.h 278837 2005-09-05 20:57:44Z sebor $
sl@0:  *
sl@0:  ************************************************************************
sl@0:  *
sl@0:  * Copyright (c) 1994-2005 Quovadx,  Inc., acting through its  Rogue Wave
sl@0:  * Software division. Licensed under the Apache License, Version 2.0 (the
sl@0:  * "License");  you may  not use this file except  in compliance with the
sl@0:  * License.    You    may   obtain   a   copy   of    the   License    at
sl@0:  * http://www.apache.org/licenses/LICENSE-2.0.    Unless   required    by
sl@0:  * applicable law  or agreed to  in writing,  software  distributed under
sl@0:  * the License is distributed on an "AS IS" BASIS,  WITHOUT WARRANTIES OR
sl@0:  * CONDITIONS OF  ANY KIND, either  express or implied.  See  the License
sl@0:  * for the specific language governing permissions  and limitations under
sl@0:  * the License.
sl@0:  * 
sl@0:  **************************************************************************/
sl@0: 
sl@0: #ifndef RW_PRINTF_H_INCLUDED
sl@0: #define RW_PRINTF_H_INCLUDED
sl@0: 
sl@0: #include <testdefs.h>
sl@0: 
sl@0: struct rw_file;
sl@0: 
sl@0: // the equivalent of stdout and stderr
sl@0: extern _TEST_EXPORT rw_file* const rw_stdout;
sl@0: extern _TEST_EXPORT rw_file* const rw_stderr;
sl@0: 
sl@0: 
sl@0: /************************************************************************
sl@0:  * Formatted file output.
sl@0:  ************************************************************************/
sl@0: 
sl@0: /**
sl@0:  *  Prints to rw_stdout.
sl@0:  */
sl@0: _TEST_EXPORT int
sl@0: rw_printf (const char*, ...);
sl@0: 
sl@0: /**
sl@0:  * Prints to a file.
sl@0:  */
sl@0: _TEST_EXPORT int
sl@0: rw_fprintf (rw_file*, const char*, ...);
sl@0: 
sl@0: 
sl@0: /************************************************************************
sl@0:  * Formatted string output.
sl@0:  ************************************************************************/
sl@0: 
sl@0: /**
sl@0:  * Prints to a character buffer.
sl@0:  */
sl@0: _TEST_EXPORT int
sl@0: rw_sprintf (char*, const char*, ...);
sl@0: 
sl@0: /**
sl@0:  * Prints to a character buffer of given size.
sl@0:  */
sl@0: _TEST_EXPORT int
sl@0: rw_snprintf (char*, _RWSTD_SIZE_T, const char*, ...);
sl@0: 
sl@0: 
sl@0: /************************************************************************
sl@0:  * Formatted string output into a dynamically allocated buffer.
sl@0:  ************************************************************************/
sl@0: 
sl@0: /**
sl@0:  * Prints to a dynamically allocated character buffer.
sl@0:  *
sl@0:  * @param fmt  Format specifier.
sl@0:  *
sl@0:  * @return  On success, returns a pointer to the dynamically allocated
sl@0:  *          character buffer. Otherwise, returns 0.
sl@0:  */
sl@0: _TEST_EXPORT char*
sl@0: rw_sprintfa (const char* fmt, ...);
sl@0: 
sl@0: 
sl@0: /**
sl@0:  * Prints to a dynamically allocated character buffer.
sl@0:  *
sl@0:  * @param buf  A pointer to character buffer where the function should
sl@0:  *        store its output.
sl@0:  * @param bufise  The size of the character buffer in bytes.
sl@0:  *
sl@0:  * @return  On success, if the size of the supplied buffer was sufficient
sl@0:  *          to format all characters including the terminating NUL, returns
sl@0:  *          buf. Otherwise, if the size of the supplied buffer was not
sl@0:  *          sufficient, returns a pointer to the newly allocated character
sl@0:  *          buffer of sufficient size. Returns 0 on failure.
sl@0:  */
sl@0: _TEST_EXPORT char*
sl@0: rw_snprintfa (char *buf, _RWSTD_SIZE_T bufsize, const char* fmt, ...);
sl@0: 
sl@0: 
sl@0: /**
sl@0:  * Prints to a dynamically allocated character buffer of sufficient size.
sl@0:  * Provided for portability with the BSD and GNU C libraries:
sl@0:  *
sl@0:  * http://www.freebsd.org/cgi/man.cgi?query=asprintf
sl@0:  * http://www.openbsd.org/cgi-bin/man.cgi?query=asprintf
sl@0:  * http://netbsd.gw.com/cgi-bin/man-cgi?asprintf++NetBSD-current
sl@0:  * http://www.gnu.org/software/libc/manual/html_node/Dynamic-Output.html
sl@0:  *
sl@0:  * @param pbuf  Pointer to a pointer to character set by the caller to
sl@0:  *        to address of the inital character buffer, or 0 of no such
sl@0:  *        buffer exists. The function sets the pointer to a the address
sl@0:  *        of the dynamically allocated character buffer, or leaves it
sl@0:  *        unchanged if it doesn't allocate any buffer.
sl@0:  * @param pbufsize  Pointer to a size_t set by the caller to the size of
sl@0:  *        the inital character buffer. The function sets the value pointed
sl@0:  *        to by this argument to the size of the dynamically allocated
sl@0:  *        character buffer, or leaves it unchanged if it doesn't allocate
sl@0:  *        any buffer.
sl@0:  * @param fmt  Format specifier.
sl@0:  *        The format specifier string has the same syntax as C99 sprintf
sl@0:  *        (see 7.19.6.1 of ISO/IEC 9899:1999) with the following extensions:
sl@0:  *
sl@0:  *        %n$          where n is a integer (see IEEE Std 1003.1)
sl@0:  *        %m           the value of strerror(errno)
sl@0:  *
sl@0:  *        %{?}         if clause (extracts an int)
sl@0:  *        %{:}         else clause
sl@0:  *        %{;}         end of if/else clause
sl@0:  *        %{#s}        quoted narrow character string
sl@0:  *        %{#ls}       quoted wide character string
sl@0:  *        %{$envvar}   value of an environment variable envvar
sl@0:  *        %{f}         function pointer
sl@0:  *        %{M}         member pointer
sl@0:  *        %{#m}        name of the errno constant (such as EINVAL)
sl@0:  *        %{n}         buffer size
sl@0:  *        %{S}         pointer to std::string
sl@0:  *        %{lS}        pointer to std::wstring
sl@0:  *        %{tm}        pointer to struct tm
sl@0:  *        %{InJ}       where n is one of { 8, 16, 32, 64 } and J { d, o, x, X }
sl@0:  *
sl@0:  * @return  On success, returns the number of characters formatted into
sl@0:  *          the buffer, otherwise -1.
sl@0:  */
sl@0: _TEST_EXPORT int
sl@0: rw_asnprintf (char** pbuf, _RWSTD_SIZE_T *pbufsize, const char *fmt, ...);
sl@0: 
sl@0: #endif   // RW_PRINTF_H_INCLUDED