[x264-devel] [PATCH 3/7] Set stdin/stdout to binary mode on OS/2 as well as Win32
KO Myung-Hun
komh at chollian.net
Sat Mar 19 15:17:25 CET 2011
---
common/osdep.h | 14 ++++++++++++++
x264.c | 6 ++----
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/common/osdep.h b/common/osdep.h
index f56f733..e6b15f6 100644
--- a/common/osdep.h
+++ b/common/osdep.h
@@ -48,6 +48,20 @@
#ifdef _WIN32
#include <io.h> // _setmode()
#include <fcntl.h> // _O_BINARY
+#include <stdio.h> // _fileno
+#define set_bin_mode(stream) _setmode(_fileno(stream), _O_BINARY)
+#elif defined(SYS_OS2)
+#include <io.h> // isatty(), setmode()
+#include <fcntl.h> // O_BINARY
+#include <stdio.h> // FILE, fileno()
+
+static inline void set_bin_mode(FILE *stream)
+{
+ if(!isatty(fileno(stream)))
+ setmode(fileno(stream), O_BINARY);
+}
+#else
+#define set_bin_mode(stream)
#endif
#if !defined(isfinite) && (SYS_OPENBSD || SYS_SunOS)
diff --git a/x264.c b/x264.c
index 92695ab..d04923a 100644
--- a/x264.c
+++ b/x264.c
@@ -257,10 +257,8 @@ int main( int argc, char **argv )
FAIL_IF_ERROR( x264_threading_init(), "unable to initialize threading\n" )
-#ifdef _WIN32
- _setmode(_fileno(stdin), _O_BINARY);
- _setmode(_fileno(stdout), _O_BINARY);
-#endif
+ set_bin_mode(stdin);
+ set_bin_mode(stdout);
/* Parse command line */
if( parse( argc, argv, ¶m, &opt ) < 0 )
--
1.7.3.2
More information about the x264-devel
mailing list