gallium: cast to silence waring
[mesa.git] / src / gallium / auxiliary / os / os_stream_stdc.c
1 /**************************************************************************
2 *
3 * Copyright 2008-2010 VMware, Inc.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 /**
29 * @file
30 * Stream implementation based on the Standard C Library.
31 */
32
33 #include "pipe/p_config.h"
34
35 #if defined(PIPE_OS_UNIX) || defined(PIPE_SUBSYSTEM_WINDOWS_USER)
36
37 #include <stdlib.h>
38 #include <stdio.h>
39
40 #include "os_stream.h"
41
42
43 struct os_stream
44 {
45 FILE *file;
46 };
47
48
49 struct os_stream *
50 os_stream_create(const char *filename, size_t max_size)
51 {
52 struct os_stream *stream;
53
54 (void)max_size;
55
56 stream = (struct os_stream *)calloc(1, sizeof(struct os_stream));
57 if(!stream)
58 goto no_stream;
59
60 stream->file = fopen(filename, "w");
61 if(!stream->file)
62 goto no_file;
63
64 return stream;
65
66 no_file:
67 free(stream);
68 no_stream:
69 return NULL;
70 }
71
72
73 boolean
74 os_stream_write(struct os_stream *stream, const void *data, size_t size)
75 {
76 if(!stream)
77 return FALSE;
78
79 return fwrite(data, size, 1, stream->file) == size ? TRUE : FALSE;
80 }
81
82
83 void
84 os_stream_flush(struct os_stream *stream)
85 {
86 if(!stream)
87 return;
88
89 fflush(stream->file);
90 }
91
92
93 void
94 os_stream_close(struct os_stream *stream)
95 {
96 if(!stream)
97 return;
98
99 fclose(stream->file);
100
101 free(stream);
102 }
103
104
105 #endif