From 03665868ac15ad4b002531ac30df0faf149a5854 Mon Sep 17 00:00:00 2001 From: Jasha Droppo Date: Fri, 31 Oct 2014 17:27:09 -0700 Subject: [PATCH] Make setmode optional on unix platforms. --- Common/Include/fileutil.h | 2 ++ Common/fileutil.cpp | 3 ++- DataReader/HTKMLFReader/fileutil.cpp | 10 ++++++++-- DataReader/HTKMLFReader/fileutil.h | 2 ++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Common/Include/fileutil.h b/Common/Include/fileutil.h index 205b97fdd..40d27fd24 100644 --- a/Common/Include/fileutil.h +++ b/Common/Include/fileutil.h @@ -40,11 +40,13 @@ using namespace std; FILE * fopenOrDie (const string & pathname, const char * mode); FILE * fopenOrDie (const wstring & pathname, const wchar_t * mode); +#ifndef __unix__ // ---------------------------------------------------------------------------- // fsetmode(): set mode to binary or text // ---------------------------------------------------------------------------- void fsetmode (FILE * f, char type); +#endif // ---------------------------------------------------------------------------- // freadOrDie(): like fread() but terminate with err msg in case of error diff --git a/Common/fileutil.cpp b/Common/fileutil.cpp index b1fc3d150..53152fea5 100644 --- a/Common/fileutil.cpp +++ b/Common/fileutil.cpp @@ -1,3 +1,4 @@ +<<<<<<< HEAD // // // Copyright (c) Microsoft Corporation. All rights reserved. @@ -1602,4 +1603,4 @@ vector sep_string(const string & istr, const string & sep) vstr.push_back(trim(csub)); return vstr; -} +} \ No newline at end of file diff --git a/DataReader/HTKMLFReader/fileutil.cpp b/DataReader/HTKMLFReader/fileutil.cpp index e4f687768..564c448ec 100644 --- a/DataReader/HTKMLFReader/fileutil.cpp +++ b/DataReader/HTKMLFReader/fileutil.cpp @@ -24,8 +24,10 @@ #ifndef UNDER_CE // some headers don't exist under winCE - the appropriate definitions seem to be in stdlib.h #include // for _O_BINARY/TEXT - not needed for wince +#ifndef __unix__ #include // for _setmode() #endif +#endif #include @@ -44,13 +46,15 @@ static const wchar_t * strchr (const wchar_t * s, wchar_t v) { return wcschr (s, template FILE * fopenStdHandle (const _T * mode) { FILE * f = strchr (mode, 'r') ? stdin : stdout; - if (strchr (mode, 'b') || strchr (mode, 't')) // change binary mode +#ifndef __unix__ // don't need binary/text distinction on unix + if (strchr(mode, 'b') || strchr(mode, 't')) // change binary mode { // switch to binary mode if not yet (in case it is stdin) int rc = _setmode (_fileno (f), strchr (mode, 'b') ? _O_BINARY : _O_TEXT); if (rc == -1) RuntimeError ("error switching stream to binary mode: %s", strerror (errno)); } +#endif return f; } @@ -88,7 +92,8 @@ FILE * fopenOrDie (const WSTRING & pathname, const wchar_t * mode) // set mode to binary or text (pass 'b' or 't') // ---------------------------------------------------------------------------- -void fsetmode (FILE * f, char type) +#ifndef __unix__ // don't need binary/text distinction on unix +void fsetmode(FILE * f, char type) { if (type != 'b' && type != 't') { @@ -106,6 +111,7 @@ void fsetmode (FILE * f, char type) RuntimeError ("error changing file mode: %s", strerror (errno)); } } +#endif // ---------------------------------------------------------------------------- // freadOrDie(): like fread() but terminate with err msg in case of error diff --git a/DataReader/HTKMLFReader/fileutil.h b/DataReader/HTKMLFReader/fileutil.h index 390a175e8..1e7aae9b3 100644 --- a/DataReader/HTKMLFReader/fileutil.h +++ b/DataReader/HTKMLFReader/fileutil.h @@ -29,11 +29,13 @@ using namespace std; FILE * fopenOrDie (const STRING & pathname, const char * mode); FILE * fopenOrDie (const WSTRING & pathname, const wchar_t * mode); +#ifndef __unix__ // don't need binary/text distinction on unix // ---------------------------------------------------------------------------- // fsetmode(): set mode to binary or text // ---------------------------------------------------------------------------- void fsetmode (FILE * f, char type); +#endif // ---------------------------------------------------------------------------- // freadOrDie(): like fread() but terminate with err msg in case of error