1 /**************************************************************************
3 * Copyright 2008-2010 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * Stream implementation based on the Standard C Library.
33 #include "pipe/p_config.h"
35 #if defined(PIPE_OS_UNIX) || defined(PIPE_SUBSYSTEM_WINDOWS_USER)
40 #include "os_stream.h"
45 struct os_stream base
;
51 static INLINE
struct os_stdc_stream
*
52 os_stdc_stream(struct os_stream
*stream
)
54 return (struct os_stdc_stream
*)stream
;
59 os_stdc_stream_close(struct os_stream
*_stream
)
61 struct os_stdc_stream
*stream
= os_stdc_stream(_stream
);
70 os_stdc_stream_write(struct os_stream
*_stream
, const void *data
, size_t size
)
72 struct os_stdc_stream
*stream
= os_stdc_stream(_stream
);
74 return fwrite(data
, size
, 1, stream
->file
) == size
? TRUE
: FALSE
;
79 os_stdc_stream_flush(struct os_stream
*_stream
)
81 struct os_stdc_stream
*stream
= os_stdc_stream(_stream
);
87 os_stdc_stream_vprintf (struct os_stream
* _stream
, const char *format
, va_list ap
)
89 struct os_stdc_stream
*stream
= os_stdc_stream(_stream
);
91 return vfprintf(stream
->file
, format
, ap
);
96 os_file_stream_create(const char *filename
)
98 struct os_stdc_stream
*stream
;
100 stream
= (struct os_stdc_stream
*)calloc(1, sizeof(*stream
));
104 stream
->base
.close
= &os_stdc_stream_close
;
105 stream
->base
.write
= &os_stdc_stream_write
;
106 stream
->base
.flush
= &os_stdc_stream_flush
;
107 stream
->base
.vprintf
= &os_stdc_stream_vprintf
;
109 stream
->file
= fopen(filename
, "wb");
113 return &stream
->base
;