gallium: refactor/replace p_util.h with util/u_memory.h and util/u_math.h
[mesa.git] / src / gallium / drivers / trace / tr_stream_stdc.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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_LINUX)
36
37 #include <stdio.h>
38
39 #include "util/u_memory.h"
40
41 #include "tr_stream.h"
42
43
44 struct trace_stream
45 {
46 FILE *file;
47 };
48
49
50 struct trace_stream *
51 trace_stream_create(const char *filename)
52 {
53 struct trace_stream *stream;
54
55 stream = CALLOC_STRUCT(trace_stream);
56 if(!stream)
57 goto error1;
58
59 stream->file = fopen(filename, "w");
60 if(!stream->file)
61 goto error2;
62
63 return stream;
64
65 error2:
66 FREE(stream);
67 error1:
68 return NULL;
69 }
70
71
72 boolean
73 trace_stream_write(struct trace_stream *stream, const void *data, size_t size)
74 {
75 if(!stream)
76 return FALSE;
77
78 return fwrite(data, size, 1, stream->file) == size ? TRUE : FALSE;
79 }
80
81
82 void
83 trace_stream_flush(struct trace_stream *stream)
84 {
85 if(!stream)
86 return;
87
88 fflush(stream->file);
89 }
90
91
92 void
93 trace_stream_close(struct trace_stream *stream)
94 {
95 if(!stream)
96 return;
97
98 fclose(stream->file);
99
100 FREE(stream);
101 }
102
103
104 #endif