1 /* Abstract output stream data type.
2    Copyright (C) 2006, 2019 Free Software Foundation, Inc.
3    Written by Bruno Haible <bruno@clisp.org>, 2006.
4 
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
17 
18 #include <config.h>
19 
20 /* Specification.  */
21 #include "ostream.h"
22 
23 #include <stdio.h>
24 
25 struct ostream
26 {
27 fields:
28 };
29 
30 #if !HAVE_INLINE
31 
32 void
ostream_write_str(ostream_t stream,const char * string)33 ostream_write_str (ostream_t stream, const char *string)
34 {
35   ostream_write_mem (stream, string, strlen (string));
36 }
37 
38 #endif
39 
40 ptrdiff_t
ostream_printf(ostream_t stream,const char * format,...)41 ostream_printf (ostream_t stream, const char *format, ...)
42 {
43   va_list args;
44   char *temp_string;
45   ptrdiff_t ret;
46 
47   va_start (args, format);
48   ret = vasprintf (&temp_string, format, args);
49   va_end (args);
50   if (ret >= 0)
51     {
52       if (ret > 0)
53         ostream_write_str (stream, temp_string);
54       free (temp_string);
55     }
56   return ret;
57 }
58 
59 ptrdiff_t
ostream_vprintf(ostream_t stream,const char * format,va_list args)60 ostream_vprintf (ostream_t stream, const char *format, va_list args)
61 {
62   char *temp_string;
63   ptrdiff_t ret = vasprintf (&temp_string, format, args);
64   if (ret >= 0)
65     {
66       if (ret > 0)
67         ostream_write_str (stream, temp_string);
68       free (temp_string);
69     }
70   return ret;
71 }
72