summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/os/os_stream_stdc.c
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2010-02-14 16:55:04 +0000
committerJosé Fonseca <jfonseca@vmware.com>2010-02-14 23:25:33 +0000
commit2b4575f16d24a212b9a43cbd4a9966b3668e4b32 (patch)
tree6d6eb6a87e5641fb48c9e76181893a711e01d43b /src/gallium/auxiliary/os/os_stream_stdc.c
parente7660a54423c69fe352e21eedd2a082d9c7aeac0 (diff)
os: Make streams abstract.
Also replace windows kernel stream with null implementation. It was severely limited and no easy means to test it now.
Diffstat (limited to 'src/gallium/auxiliary/os/os_stream_stdc.c')
-rw-r--r--src/gallium/auxiliary/os/os_stream_stdc.c71
1 files changed, 44 insertions, 27 deletions
diff --git a/src/gallium/auxiliary/os/os_stream_stdc.c b/src/gallium/auxiliary/os/os_stream_stdc.c
index caa60c0b50..9a62799c0f 100644
--- a/src/gallium/auxiliary/os/os_stream_stdc.c
+++ b/src/gallium/auxiliary/os/os_stream_stdc.c
@@ -40,39 +40,40 @@
#include "os_stream.h"
-struct os_stream
+struct os_stdc_stream
{
+ struct os_stream base;
+
FILE *file;
};
-struct os_stream *
-os_stream_create(const char *filename, size_t max_size)
+static INLINE struct os_stdc_stream *
+os_stdc_stream(struct os_stream *stream)
{
- struct os_stream *stream;
-
- (void)max_size;
-
- stream = (struct os_stream *)calloc(1, sizeof(struct os_stream));
+ return (struct os_stdc_stream *)stream;
+}
+
+
+static void
+os_stdc_stream_close(struct os_stream *_stream)
+{
+ struct os_stdc_stream *stream = os_stdc_stream(_stream);
+
if(!stream)
- goto no_stream;
-
- stream->file = fopen(filename, "w");
- if(!stream->file)
- goto no_file;
-
- return stream;
+ return;
-no_file:
+ fclose(stream->file);
+
free(stream);
-no_stream:
- return NULL;
}
-boolean
-os_stream_write(struct os_stream *stream, const void *data, size_t size)
+static boolean
+os_stdc_stream_write(struct os_stream *_stream, const void *data, size_t size)
{
+ struct os_stdc_stream *stream = os_stdc_stream(_stream);
+
if(!stream)
return FALSE;
@@ -80,9 +81,11 @@ os_stream_write(struct os_stream *stream, const void *data, size_t size)
}
-void
-os_stream_flush(struct os_stream *stream)
+static void
+os_stdc_stream_flush(struct os_stream *_stream)
{
+ struct os_stdc_stream *stream = os_stdc_stream(_stream);
+
if(!stream)
return;
@@ -90,15 +93,29 @@ os_stream_flush(struct os_stream *stream)
}
-void
-os_stream_close(struct os_stream *stream)
+struct os_stream *
+os_file_stream_create(const char *filename)
{
+ struct os_stdc_stream *stream;
+
+ stream = (struct os_stdc_stream *)calloc(1, sizeof(struct os_stream));
if(!stream)
- return;
-
- fclose(stream->file);
+ goto no_stream;
+ stream->base.close = &os_stdc_stream_close;
+ stream->base.write = &os_stdc_stream_write;
+ stream->base.flush = &os_stdc_stream_flush;
+
+ stream->file = fopen(filename, "w");
+ if(!stream->file)
+ goto no_file;
+
+ return &stream->base;
+
+no_file:
free(stream);
+no_stream:
+ return NULL;
}