[Mesa-dev] [PATCH] os: Allow file streams to be open in binary mode.

Michal Krol michal at vmware.com
Thu Nov 4 09:58:49 PDT 2010


W dniu 2010-11-04 17:56, José Fonseca pisze:
> Michal,
>
> I think we can just use binary all the time.
>

Really? There are some consumers of this function that produce text 
files, like XML output of trace. Though I think we should be fine with
those having linux newlines...


>
> On Thu, 2010-11-04 at 09:29 -0700, Michal Krol wrote:
>>  From efd52ac32547c80d1d8317fe2934a6742968a394 Mon Sep 17 00:00:00 2001
>> From: Michal Krol<michal at vmware.com>
>> Date: Thu, 4 Nov 2010 17:29:01 +0100
>> Subject: [PATCH] os: Allow file streams to be open in binary mode.
>>
>> 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;
>>
>
>



More information about the mesa-dev mailing list