stdcpp/tsrc/Stdcpp_test/stdcxx/include/printf.h
changeset 31 ce057bb09d0b
parent 0 e4d67989cc36
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     1 /************************************************************************
       
     2  *
       
     3  * printf.h - declarations of the rw_printf family of functions
       
     4  *
       
     5  * $Id: printf.h 278837 2005-09-05 20:57:44Z sebor $
       
     6  *
       
     7  ************************************************************************
       
     8  *
       
     9  * Copyright (c) 1994-2005 Quovadx,  Inc., acting through its  Rogue Wave
       
    10  * Software division. Licensed under the Apache License, Version 2.0 (the
       
    11  * "License");  you may  not use this file except  in compliance with the
       
    12  * License.    You    may   obtain   a   copy   of    the   License    at
       
    13  * http://www.apache.org/licenses/LICENSE-2.0.    Unless   required    by
       
    14  * applicable law  or agreed to  in writing,  software  distributed under
       
    15  * the License is distributed on an "AS IS" BASIS,  WITHOUT WARRANTIES OR
       
    16  * CONDITIONS OF  ANY KIND, either  express or implied.  See  the License
       
    17  * for the specific language governing permissions  and limitations under
       
    18  * the License.
       
    19  * 
       
    20  **************************************************************************/
       
    21 
       
    22 #ifndef RW_PRINTF_H_INCLUDED
       
    23 #define RW_PRINTF_H_INCLUDED
       
    24 
       
    25 #include <testdefs.h>
       
    26 
       
    27 struct rw_file;
       
    28 
       
    29 // the equivalent of stdout and stderr
       
    30 extern _TEST_EXPORT rw_file* const rw_stdout;
       
    31 extern _TEST_EXPORT rw_file* const rw_stderr;
       
    32 
       
    33 
       
    34 /************************************************************************
       
    35  * Formatted file output.
       
    36  ************************************************************************/
       
    37 
       
    38 /**
       
    39  *  Prints to rw_stdout.
       
    40  */
       
    41 _TEST_EXPORT int
       
    42 rw_printf (const char*, ...);
       
    43 
       
    44 /**
       
    45  * Prints to a file.
       
    46  */
       
    47 _TEST_EXPORT int
       
    48 rw_fprintf (rw_file*, const char*, ...);
       
    49 
       
    50 
       
    51 /************************************************************************
       
    52  * Formatted string output.
       
    53  ************************************************************************/
       
    54 
       
    55 /**
       
    56  * Prints to a character buffer.
       
    57  */
       
    58 _TEST_EXPORT int
       
    59 rw_sprintf (char*, const char*, ...);
       
    60 
       
    61 /**
       
    62  * Prints to a character buffer of given size.
       
    63  */
       
    64 _TEST_EXPORT int
       
    65 rw_snprintf (char*, _RWSTD_SIZE_T, const char*, ...);
       
    66 
       
    67 
       
    68 /************************************************************************
       
    69  * Formatted string output into a dynamically allocated buffer.
       
    70  ************************************************************************/
       
    71 
       
    72 /**
       
    73  * Prints to a dynamically allocated character buffer.
       
    74  *
       
    75  * @param fmt  Format specifier.
       
    76  *
       
    77  * @return  On success, returns a pointer to the dynamically allocated
       
    78  *          character buffer. Otherwise, returns 0.
       
    79  */
       
    80 _TEST_EXPORT char*
       
    81 rw_sprintfa (const char* fmt, ...);
       
    82 
       
    83 
       
    84 /**
       
    85  * Prints to a dynamically allocated character buffer.
       
    86  *
       
    87  * @param buf  A pointer to character buffer where the function should
       
    88  *        store its output.
       
    89  * @param bufise  The size of the character buffer in bytes.
       
    90  *
       
    91  * @return  On success, if the size of the supplied buffer was sufficient
       
    92  *          to format all characters including the terminating NUL, returns
       
    93  *          buf. Otherwise, if the size of the supplied buffer was not
       
    94  *          sufficient, returns a pointer to the newly allocated character
       
    95  *          buffer of sufficient size. Returns 0 on failure.
       
    96  */
       
    97 _TEST_EXPORT char*
       
    98 rw_snprintfa (char *buf, _RWSTD_SIZE_T bufsize, const char* fmt, ...);
       
    99 
       
   100 
       
   101 /**
       
   102  * Prints to a dynamically allocated character buffer of sufficient size.
       
   103  * Provided for portability with the BSD and GNU C libraries:
       
   104  *
       
   105  * http://www.freebsd.org/cgi/man.cgi?query=asprintf
       
   106  * http://www.openbsd.org/cgi-bin/man.cgi?query=asprintf
       
   107  * http://netbsd.gw.com/cgi-bin/man-cgi?asprintf++NetBSD-current
       
   108  * http://www.gnu.org/software/libc/manual/html_node/Dynamic-Output.html
       
   109  *
       
   110  * @param pbuf  Pointer to a pointer to character set by the caller to
       
   111  *        to address of the inital character buffer, or 0 of no such
       
   112  *        buffer exists. The function sets the pointer to a the address
       
   113  *        of the dynamically allocated character buffer, or leaves it
       
   114  *        unchanged if it doesn't allocate any buffer.
       
   115  * @param pbufsize  Pointer to a size_t set by the caller to the size of
       
   116  *        the inital character buffer. The function sets the value pointed
       
   117  *        to by this argument to the size of the dynamically allocated
       
   118  *        character buffer, or leaves it unchanged if it doesn't allocate
       
   119  *        any buffer.
       
   120  * @param fmt  Format specifier.
       
   121  *        The format specifier string has the same syntax as C99 sprintf
       
   122  *        (see 7.19.6.1 of ISO/IEC 9899:1999) with the following extensions:
       
   123  *
       
   124  *        %n$          where n is a integer (see IEEE Std 1003.1)
       
   125  *        %m           the value of strerror(errno)
       
   126  *
       
   127  *        %{?}         if clause (extracts an int)
       
   128  *        %{:}         else clause
       
   129  *        %{;}         end of if/else clause
       
   130  *        %{#s}        quoted narrow character string
       
   131  *        %{#ls}       quoted wide character string
       
   132  *        %{$envvar}   value of an environment variable envvar
       
   133  *        %{f}         function pointer
       
   134  *        %{M}         member pointer
       
   135  *        %{#m}        name of the errno constant (such as EINVAL)
       
   136  *        %{n}         buffer size
       
   137  *        %{S}         pointer to std::string
       
   138  *        %{lS}        pointer to std::wstring
       
   139  *        %{tm}        pointer to struct tm
       
   140  *        %{InJ}       where n is one of { 8, 16, 32, 64 } and J { d, o, x, X }
       
   141  *
       
   142  * @return  On success, returns the number of characters formatted into
       
   143  *          the buffer, otherwise -1.
       
   144  */
       
   145 _TEST_EXPORT int
       
   146 rw_asnprintf (char** pbuf, _RWSTD_SIZE_T *pbufsize, const char *fmt, ...);
       
   147 
       
   148 #endif   // RW_PRINTF_H_INCLUDED