[PATCH] os: Allow file streams to be open in binary mode.
Michal Krol
michal at vmware.com
Thu Nov 4 09:29:01 PDT 2010
Explicitly request binary file mode by adding
OS_STREAM_CREATE_BINARY flag to os_file_stream_create().
Without that files created on windows will be garbled.
---
src/gallium/auxiliary/os/os_stream.h | 10 ++++++++--
src/gallium/auxiliary/os/os_stream_stdc.c | 6 ++++--
src/gallium/auxiliary/util/u_debug.c | 2 +-
src/gallium/auxiliary/util/u_debug_refcnt.c | 2 +-
src/gallium/drivers/trace/tr_dump.c | 2 +-
5 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/src/gallium/auxiliary/os/os_stream.h b/src/gallium/auxiliary/os/os_stream.h
index 6c6050b..0e9acfa 100644
--- a/src/gallium/auxiliary/os/os_stream.h
+++ b/src/gallium/auxiliary/os/os_stream.h
@@ -55,6 +55,11 @@ struct os_stream
(*vprintf)(struct os_stream *stream, const char* format, va_list ap);
};
+/**
+ * OS stream creation flags.
+ */
+#define OS_STREAM_CREATE_BINARY 0x1
+
static INLINE void
os_stream_close(struct os_stream *stream)
@@ -116,7 +121,8 @@ os_stream_printf (struct os_stream* stream, const char *format, ...)
}
struct os_stream *
-os_file_stream_create(const char *filename);
+os_file_stream_create(const char *filename,
+ uint creation_flags);
struct os_stream *
@@ -139,7 +145,7 @@ os_str_stream_get_and_close(struct os_stream *stream);
#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
-#define os_file_stream_create(_filename) os_null_stream_create()
+#define os_file_stream_create(_filename, _creation_flags) os_null_stream_create()
#endif
#endif /* _OS_STREAM_H_ */
diff --git a/src/gallium/auxiliary/os/os_stream_stdc.c b/src/gallium/auxiliary/os/os_stream_stdc.c
index 37e7d06..adc2be4 100644
--- a/src/gallium/auxiliary/os/os_stream_stdc.c
+++ b/src/gallium/auxiliary/os/os_stream_stdc.c
@@ -93,7 +93,8 @@ os_stdc_stream_vprintf (struct os_stream* _stream, const char *format, va_list a
struct os_stream *
-os_file_stream_create(const char *filename)
+os_file_stream_create(const char *filename,
+ uint creation_flags)
{
struct os_stdc_stream *stream;
@@ -106,7 +107,8 @@ os_file_stream_create(const char *filename)
stream->base.flush = &os_stdc_stream_flush;
stream->base.vprintf = &os_stdc_stream_vprintf;
- stream->file = fopen(filename, "w");
+ stream->file = fopen(filename,
+ (creation_flags & OS_STREAM_CREATE_BINARY) ? "wb" : "w");
if(!stream->file)
goto no_file;
diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c
index 504e6d2..bb1680a 100644
--- a/src/gallium/auxiliary/util/u_debug.c
+++ b/src/gallium/auxiliary/util/u_debug.c
@@ -632,7 +632,7 @@ debug_dump_float_rgba_bmp(const char *filename,
bmih.biClrUsed = 0;
bmih.biClrImportant = 0;
- stream = os_file_stream_create(filename);
+ stream = os_file_stream_create(filename, OS_STREAM_CREATE_BINARY);
if(!stream)
goto error1;
diff --git a/src/gallium/auxiliary/util/u_debug_refcnt.c b/src/gallium/auxiliary/util/u_debug_refcnt.c
index 40a26c9..cee1615 100644
--- a/src/gallium/auxiliary/util/u_debug_refcnt.c
+++ b/src/gallium/auxiliary/util/u_debug_refcnt.c
@@ -119,7 +119,7 @@ void debug_reference_slowpath(const struct pipe_reference* p, debug_reference_de
{
const char* filename = debug_get_option("GALLIUM_REFCNT_LOG", NULL);
if(filename && filename[0])
- stream = os_file_stream_create(filename);
+ stream = os_file_stream_create(filename, 0);
if(stream)
debug_refcnt_state = 1;
diff --git a/src/gallium/drivers/trace/tr_dump.c b/src/gallium/drivers/trace/tr_dump.c
index 51a4ea9..dcc1a47 100644
--- a/src/gallium/drivers/trace/tr_dump.c
+++ b/src/gallium/drivers/trace/tr_dump.c
@@ -251,7 +251,7 @@ boolean trace_dump_trace_begin()
if(!stream) {
- stream = os_file_stream_create(filename);
+ stream = os_file_stream_create(filename, 0);
if(!stream)
return FALSE;
--
1.7.0.2.msysgit.0
More information about the mesa-dev
mailing list