stdcpp/src/iostream.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2  * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
       
     3  *
       
     4  * Copyright (c) 1999
       
     5  * Silicon Graphics Computer Systems, Inc.
       
     6  *
       
     7  * Copyright (c) 1999 
       
     8  * Boris Fomitchev
       
     9  *
       
    10  * This material is provided "as is", with absolutely no warranty expressed
       
    11  * or implied. Any use is at your own risk.
       
    12  *
       
    13  * Permission to use or copy this software for any purpose is hereby granted 
       
    14  * without fee, provided the above notices are retained on all copies.
       
    15  * Permission to modify the code and to distribute modified code is granted,
       
    16  * provided the above notices are retained, and a notice that the code was
       
    17  * modified is included with the above copyright notice.
       
    18  *
       
    19  */ 
       
    20 # include "stlport_prefix.h"
       
    21 
       
    22 #include <istream>
       
    23 // #include <stl/_istream.h>
       
    24 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
    25 # include "libstdcppwsd.h"
       
    26 # endif
       
    27 
       
    28 #include <stl/_fstream.h>
       
    29 #include <stdio_streambuf>
       
    30 #include "aligned_buffer.h"
       
    31 
       
    32 // boris : note this is repeated in <iostream>
       
    33 #ifndef _STLP_USE_NAMESPACES
       
    34 // in case of SGI iostreams, we have to rename our streams not to clash with those
       
    35 // provided in native lib
       
    36 # define cin _STLP_cin
       
    37 # define cout _STLP_cout
       
    38 # define cerr _STLP_cerr
       
    39 # define clog _STLP_clog
       
    40 #endif
       
    41 
       
    42 _STLP_BEGIN_NAMESPACE
       
    43 
       
    44 #if defined (__BORLANDC__) && ! defined (_STLP_USE_GLIBC)
       
    45 using _STLP_VENDOR_CSTD::_streams;
       
    46 #endif
       
    47 
       
    48 // This file handles iostream initialization.  It is inherently
       
    49 // nonportable, since the C++ language definition provides no mechanism
       
    50 // for controlling order of initialization of nonlocal objects.  
       
    51 // Initialization has three parts, which must be performed in the following
       
    52 // order:
       
    53 //  (1) Initialize the locale system
       
    54 //  (2) Call the constructors for the eight global stream objects.
       
    55 //  (3) Create streambufs for the global stream objects, and initialize
       
    56 //      the stream objects by calling the init() member function.
       
    57 
       
    58 
       
    59 #if defined (_STLP_MSVC) || defined(__MWERKS__) || defined (__ICL) || defined (__ISCPP__) || defined (__SYMBIAN32__)
       
    60 // Definitions of the eight global I/O objects that are declared in 
       
    61 // <iostream>. For VC++ we use the init_seg pragma to put the global I/O
       
    62 // objects into an intitialization segement that will not
       
    63 // be executed. We then explicitly invoke the constructors
       
    64 // with placement new in ios_base::_S_initialize() 
       
    65 
       
    66 #if defined(__MWERKS__)
       
    67 # pragma suppress_init_code on
       
    68 #else
       
    69 # pragma init_seg("STLPORT_NO_INIT")
       
    70 #endif
       
    71 
       
    72 # if !defined(__LIBSTD_CPP_SYMBIAN32_WSD__) && !defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
    73 _STLP_EXP_DECLSPEC istream cin(0);
       
    74 _STLP_EXP_DECLSPEC ostream cout(0);
       
    75 _STLP_EXP_DECLSPEC ostream cerr(0);
       
    76 _STLP_EXP_DECLSPEC ostream clog(0);
       
    77 
       
    78 #ifndef _STLP_NO_WCHAR_T
       
    79 _STLP_EXP_DECLSPEC wistream wcin(0);
       
    80 _STLP_EXP_DECLSPEC wostream wcout(0);
       
    81 _STLP_EXP_DECLSPEC wostream wcerr(0);
       
    82 _STLP_EXP_DECLSPEC wostream wclog(0);
       
    83 #endif
       
    84 # endif
       
    85 
       
    86 _STLP_EXP_DECLSPEC ostream& GetCErrStream()
       
    87     {
       
    88     return *getCErrStream();
       
    89     }
       
    90 
       
    91 _STLP_EXP_DECLSPEC ostream& GetCoutStream()
       
    92     {
       
    93     return *getCoutStream();
       
    94     }
       
    95 
       
    96 _STLP_EXP_DECLSPEC ostream& GetClogStream()
       
    97     {
       
    98     return *getClogStream();
       
    99     }
       
   100 
       
   101 _STLP_EXP_DECLSPEC istream& GetCinStream()
       
   102     {
       
   103     return *getCinStream();
       
   104     }
       
   105 
       
   106 #ifndef _STLP_NO_WCHAR_T    
       
   107 _STLP_EXP_DECLSPEC wostream& GetWCErrStream()
       
   108     {
       
   109     return *getWCErrStream();
       
   110     }
       
   111 
       
   112 _STLP_EXP_DECLSPEC wostream& GetWCoutStream()
       
   113     {
       
   114     return *getWCoutStream();
       
   115     }
       
   116 
       
   117 _STLP_EXP_DECLSPEC wostream& GetWClogStream()
       
   118     {
       
   119     return *getWClogStream();
       
   120     }
       
   121 
       
   122 _STLP_EXP_DECLSPEC wistream& GetWCinStream()
       
   123     {
       
   124     return *getWCinStream();
       
   125     }   
       
   126 #endif //_STLP_NO_WCHAR_T    
       
   127 
       
   128 #if defined(__MWERKS__)
       
   129 # pragma suppress_init_code off
       
   130 #endif
       
   131 
       
   132 #else
       
   133 
       
   134 
       
   135 // Definitions of the eight global I/O objects that are declared in 
       
   136 // <iostream>.  Disgusting hack: we deliberately define them with the
       
   137 // wrong types so that the constructors don't get run automatically.
       
   138 // We need special tricks to make sure that these objects are struct-
       
   139 // aligned rather than byte-aligned.
       
   140 
       
   141 // This is not portable.  Declaring a variable with different types in
       
   142 // two translations units is "undefined", according to the C++ standard.
       
   143 // Most compilers, however, silently accept this instead of diagnosing
       
   144 // it as an error.
       
   145 
       
   146 #ifndef __DMC__
       
   147 _Stl_aligned_buffer<istream> cin;
       
   148 _Stl_aligned_buffer<ostream> cout;
       
   149 _Stl_aligned_buffer<ostream> cerr;
       
   150 _Stl_aligned_buffer<ostream> clog;
       
   151 #else
       
   152 _Stl_aligned_buffer<istream> cin;
       
   153 _Stl_aligned_buffer<ostream> cout;
       
   154 _Stl_aligned_buffer<ostream> cerr;
       
   155 _Stl_aligned_buffer<ostream> clog;
       
   156 
       
   157 #pragma alias("?cin@std@@3V?$basic_istream@std@DV?$char_traits@std@D@1@@1@A", "?cin@std@@3T?$_Stl_aligned_buffer@std@V?$basic_istream@std@DV?$char_traits@std@D@1@@1@@1@A")
       
   158 #pragma alias("?cout@std@@3V?$basic_ostream@std@DV?$char_traits@std@D@1@@1@A", "?cout@std@@3T?$_Stl_aligned_buffer@std@V?$basic_ostream@std@DV?$char_traits@std@D@1@@1@@1@A")
       
   159 #pragma alias("?cerr@std@@3V?$basic_ostream@std@DV?$char_traits@std@D@1@@1@A", "?cerr@std@@3T?$_Stl_aligned_buffer@std@V?$basic_ostream@std@DV?$char_traits@std@D@1@@1@@1@A")
       
   160 #pragma alias("?clog@std@@3V?$basic_ostream@std@DV?$char_traits@std@D@1@@1@A", "?clog@std@@3T?$_Stl_aligned_buffer@std@V?$basic_ostream@std@DV?$char_traits@std@D@1@@1@@1@A")
       
   161 #endif
       
   162 
       
   163 # ifndef _STLP_NO_WCHAR_T
       
   164 
       
   165 #ifndef __DMC__
       
   166 _Stl_aligned_buffer<wistream> wcin;
       
   167 _Stl_aligned_buffer<wostream> wcout;
       
   168 _Stl_aligned_buffer<wostream> wcerr;
       
   169 _Stl_aligned_buffer<wostream> wclog;
       
   170 #else
       
   171 _Stl_aligned_buffer<wistream> wcin;
       
   172 _Stl_aligned_buffer<wostream> wcout;
       
   173 _Stl_aligned_buffer<wostream> wcerr;
       
   174 _Stl_aligned_buffer<wostream> wclog;
       
   175 
       
   176 #pragma alias("?wcin@std@@3V?$basic_istream@std@_YV?$char_traits@std@_Y@1@@1@A", "?wcin@std@@3T?$_Stl_aligned_buffer@std@V?$basic_istream@std@_YV?$char_traits@std@_Y@1@@1@@1@A")
       
   177 #pragma alias("?wcout@std@@3V?$basic_ostream@std@_YV?$char_traits@std@_Y@1@@1@A", "?wcout@std@@3T?$_Stl_aligned_buffer@std@V?$basic_ostream@std@_YV?$char_traits@std@_Y@1@@1@@1@A")
       
   178 #pragma alias("?wcerr@std@@3V?$basic_ostream@std@_YV?$char_traits@std@_Y@1@@1@A", "?wcerr@std@@3T?$_Stl_aligned_buffer@std@V?$basic_ostream@std@_YV?$char_traits@std@_Y@1@@1@@1@A")
       
   179 #pragma alias("?wclog@std@@3V?$basic_ostream@std@_YV?$char_traits@std@_Y@1@@1@A", "?wclog@std@@3T?$_Stl_aligned_buffer@std@V?$basic_ostream@std@_YV?$char_traits@std@_Y@1@@1@@1@A")
       
   180 #endif
       
   181 # endif
       
   182 
       
   183 #endif /* STL_MSVC || __MWERKS__ */
       
   184 
       
   185 // Member functions from class ios_base and ios_base::Init
       
   186 
       
   187 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
   188 void ios_base_Init_S_count_init()
       
   189 {
       
   190 	get_ios_base_Init_S_count() = 0;	
       
   191 }
       
   192 void ios_base_S_was_synced_init()
       
   193 {
       
   194 	get_ios_base_S_was_synced() = true;	
       
   195 }
       
   196 # else
       
   197 long ios_base::Init::_S_count = 0;
       
   198 // by default, those are synced
       
   199 bool ios_base::_S_was_synced = true;
       
   200 # endif //__LIBSTD_CPP_SYMBIAN32_WSD__
       
   201 
       
   202 
       
   203 _STLP_DECLSPEC extern void LibStdCppInit();
       
   204 
       
   205 
       
   206 void CallIosInit()
       
   207     {
       
   208     ios_base::_S_initialize();
       
   209     }
       
   210 
       
   211 
       
   212 _STLP_EXP_DECLSPEC ios_base::Init::Init() {
       
   213   //    if (_S_count == 0)
       
   214       //ios_base::_S_initialize();
       
   215       LibStdCppInit();
       
   216 }
       
   217 
       
   218 _STLP_EXP_DECLSPEC ios_base::Init::~Init() {
       
   219   //    if (_S_count > 0)
       
   220       ios_base::_S_uninitialize();
       
   221 }
       
   222 
       
   223 
       
   224 filebuf*
       
   225 _Stl_create_filebuf(FILE* f, ios_base::openmode mode )
       
   226 {
       
   227   basic_filebuf<char, char_traits<char> >* result;
       
   228   
       
   229   result = new basic_filebuf<char, char_traits<char> >();
       
   230 
       
   231   _STLP_TRY {
       
   232     result->_M_open(_FILE_fd(f), mode);
       
   233   }
       
   234   _STLP_CATCH_ALL {}
       
   235 
       
   236   if (!result->is_open()) {
       
   237     delete result;
       
   238     result = 0;
       
   239   }
       
   240   return result;
       
   241 }
       
   242 
       
   243 # ifndef _STLP_NO_WCHAR_T
       
   244 
       
   245 wfilebuf*
       
   246 _Stl_create_wfilebuf(FILE* f, ios_base::openmode mode )
       
   247 {
       
   248   basic_filebuf<wchar_t, char_traits<wchar_t> >* result;
       
   249   
       
   250   result = new basic_filebuf<wchar_t, char_traits<wchar_t> >();
       
   251 
       
   252   _STLP_TRY {
       
   253     result->_M_open(_FILE_fd(f), mode);
       
   254   }
       
   255   _STLP_CATCH_ALL {}
       
   256 
       
   257   if (!result->is_open()) {
       
   258     delete result;
       
   259     result = 0;
       
   260   }
       
   261   return result;
       
   262 }
       
   263 
       
   264 # endif
       
   265 
       
   266 void  _STLP_CALL ios_base::_S_initialize()
       
   267 {
       
   268 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
   269 	if (get_ios_base_Init_S_count()++ > 0) 
       
   270     	return ;
       
   271 # else
       
   272 	if (ios_base::Init::_S_count++ > 0) 
       
   273     	return ;
       
   274 # endif //__LIBSTD_CPP_SYMBIAN32_WSD__
       
   275   
       
   276 # if !defined(_STLP_HAS_NO_NAMESPACES) && !defined(_STLP_WINCE)
       
   277   using _SgI::stdio_istreambuf;
       
   278   using _SgI::stdio_ostreambuf;
       
   279 # endif
       
   280   _STLP_TRY {
       
   281     // Run constructors for the four narrow stream objects.
       
   282     // check with locale system
       
   283     //    if (_Loc_init::_S_count == 0) {
       
   284       locale::_S_initialize();
       
   285       //    }
       
   286 #if !defined(_STLP_WINCE)
       
   287 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
   288     istream* ptr_cin  = new((void*)&GetCinStream())  istream(0);
       
   289     ostream* ptr_cout = new((void*)&GetCoutStream()) ostream(0);
       
   290     ostream* ptr_cerr = new((void*)&GetCErrStream()) ostream(0);
       
   291     ostream* ptr_clog = new((void*)&GetClogStream()) ostream(0);
       
   292 # else
       
   293 	istream* ptr_cin  = new((void*)&cin)  istream(0);
       
   294     ostream* ptr_cout = new((void*)&cout) ostream(0);
       
   295     ostream* ptr_cerr = new((void*)&cerr) ostream(0);
       
   296     ostream* ptr_clog = new((void*)&clog) ostream(0);
       
   297 # endif //__LIBSTD_CPP_SYMBIAN32_WSD__
       
   298     // Initialize the four narrow stream objects.
       
   299 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
   300 	if (get_ios_base_S_was_synced()) {
       
   301 # else
       
   302 	if (_S_was_synced) {
       
   303 # endif        
       
   304       ptr_cin->init(new stdio_istreambuf(stdin));
       
   305       ptr_cout->init(new stdio_ostreambuf(stdout));
       
   306       ptr_cerr->init(new stdio_ostreambuf(stderr));
       
   307       ptr_clog->init(new stdio_ostreambuf(stderr));
       
   308     } else {
       
   309       ptr_cin->init(_Stl_create_filebuf(stdin, ios_base::in));
       
   310       ptr_cin->init(_Stl_create_filebuf(stdout, ios_base::out));
       
   311       ptr_cin->init(_Stl_create_filebuf(stderr, ios_base::out));
       
   312       ptr_cin->init(_Stl_create_filebuf(stderr, ios_base::out)); 
       
   313     }
       
   314     ptr_cin->tie(ptr_cout);
       
   315     ptr_cerr->setf(ios_base::unitbuf);
       
   316 
       
   317 # ifndef _STLP_NO_WCHAR_T
       
   318 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
   319     // Run constructors for the four wide stream objects.
       
   320     wistream* ptr_wcin  = new(&GetWCinStream())  wistream(0);
       
   321     wostream* ptr_wcout = new(&GetWCoutStream()) wostream(0);
       
   322     wostream* ptr_wcerr = new(&GetWCErrStream()) wostream(0);
       
   323     wostream* ptr_wclog = new(&GetWClogStream()) wostream(0);
       
   324 # else
       
   325 	// Run constructors for the four wide stream objects.
       
   326     wistream* ptr_wcin  = new(&wcin)  wistream(0);
       
   327     wostream* ptr_wcout = new(&wcout) wostream(0);
       
   328     wostream* ptr_wcerr = new(&wcerr) wostream(0);
       
   329     wostream* ptr_wclog = new(&wclog) wostream(0);
       
   330 # endif //__LIBSTD_CPP_SYMBIAN32_WSD__
       
   331 
       
   332     wfilebuf* win  = _Stl_create_wfilebuf(stdin, ios_base::in);
       
   333     wfilebuf* wout = _Stl_create_wfilebuf(stdout, ios_base::out);;
       
   334     wfilebuf* werr = _Stl_create_wfilebuf(stderr, ios_base::out);
       
   335     wfilebuf* wlog = _Stl_create_wfilebuf(stderr, ios_base::out);
       
   336 
       
   337     ptr_wcin->init(win);
       
   338     ptr_wcout->init(wout);
       
   339     ptr_wcerr->init(werr);
       
   340     ptr_wclog->init(wlog);
       
   341 
       
   342     ptr_wcin->tie(ptr_wcout);
       
   343     ptr_wcerr->setf(ios_base::unitbuf);
       
   344     
       
   345 # endif /*  _STLP_NO_WCHAR_T */
       
   346 #endif /* _STLP_WINCE */
       
   347 
       
   348     //    ++ios_base::Init::_S_count;
       
   349   }
       
   350 
       
   351   _STLP_CATCH_ALL {}
       
   352 }
       
   353 
       
   354 void _STLP_CALL ios_base::_S_uninitialize()
       
   355 {
       
   356 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
   357   if (--get_ios_base_Init_S_count() != 0) 
       
   358     return ;
       
   359 # else
       
   360 	  if (--ios_base::Init::_S_count != 0) 
       
   361     return ;
       
   362 # endif //__LIBSTD_CPP_SYMBIAN32_WSD__
       
   363 
       
   364 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
   365   // Note that destroying output streambufs flushes the buffers.
       
   366   istream* ptr_cin  = __REINTERPRET_CAST(istream*,&GetCinStream());
       
   367   ostream* ptr_cout = __REINTERPRET_CAST(ostream*,&GetCoutStream());
       
   368   ostream* ptr_cerr = __REINTERPRET_CAST(ostream*,&GetCErrStream());
       
   369   ostream* ptr_clog = __REINTERPRET_CAST(ostream*,&GetClogStream());
       
   370 
       
   371 # ifndef _STLP_NO_WCHAR_T
       
   372   wistream* ptr_wcin  = __REINTERPRET_CAST(wistream*,&GetWCinStream());
       
   373   wostream* ptr_wcout = __REINTERPRET_CAST(wostream*,&GetWCoutStream());
       
   374   wostream* ptr_wcerr = __REINTERPRET_CAST(wostream*,&GetWCErrStream());
       
   375   wostream* ptr_wclog = __REINTERPRET_CAST(wostream*,&GetWClogStream());
       
   376 # endif //_STLP_NO_WCHAR_T
       
   377 # else
       
   378   // Note that destroying output streambufs flushes the buffers.
       
   379   istream* ptr_cin  = __REINTERPRET_CAST(istream*,&cin);
       
   380   ostream* ptr_cout = __REINTERPRET_CAST(ostream*,&cout);
       
   381   ostream* ptr_cerr = __REINTERPRET_CAST(ostream*,&cerr);
       
   382   ostream* ptr_clog = __REINTERPRET_CAST(ostream*,&clog);
       
   383 
       
   384 # ifndef _STLP_NO_WCHAR_T
       
   385   wistream* ptr_wcin  = __REINTERPRET_CAST(wistream*,&wcin);
       
   386   wostream* ptr_wcout = __REINTERPRET_CAST(wostream*,&wcout);
       
   387   wostream* ptr_wcerr = __REINTERPRET_CAST(wostream*,&wcerr);
       
   388   wostream* ptr_wclog = __REINTERPRET_CAST(wostream*,&wclog);
       
   389 # endif
       
   390 # endif //__LIBSTD_CPP_SYMBIAN32_WSD__
       
   391 
       
   392 
       
   393   // we don't want any exceptions being thrown here
       
   394   ptr_cin->exceptions(0);
       
   395   ptr_cout->exceptions(0);
       
   396   ptr_cerr->exceptions(0);
       
   397   ptr_clog->exceptions(0);
       
   398 
       
   399   delete ptr_cin->rdbuf(0);
       
   400   delete ptr_cout->rdbuf(0);
       
   401   delete ptr_cerr->rdbuf(0);
       
   402   delete ptr_clog->rdbuf(0);
       
   403 
       
   404   _Destroy(ptr_cin);
       
   405   _Destroy(ptr_cout);
       
   406   _Destroy(ptr_cerr);
       
   407   _Destroy(ptr_clog);
       
   408 
       
   409 # ifndef _STLP_NO_WCHAR_T
       
   410   // we don't want any exceptions being thrown here
       
   411   ptr_wcin->exceptions(0);
       
   412   ptr_wcout->exceptions(0);
       
   413   ptr_wcerr->exceptions(0);
       
   414   ptr_wclog->exceptions(0);
       
   415 
       
   416   delete ptr_wcin->rdbuf(0);
       
   417   delete ptr_wcout->rdbuf(0);
       
   418   delete ptr_wcerr->rdbuf(0);
       
   419   delete ptr_wclog->rdbuf(0);
       
   420 
       
   421   _Destroy(ptr_wcin);
       
   422   _Destroy(ptr_wcout);
       
   423   _Destroy(ptr_wcerr);
       
   424   _Destroy(ptr_wclog);
       
   425 
       
   426 # endif
       
   427 
       
   428 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
   429 	if (get_ios_base_Loc_init_S_count() > 0) {
       
   430 # else
       
   431     if (_Loc_init::_S_count > 0) {
       
   432 # endif // __LIBSTD_CPP_SYMBIAN32_WSD__  
       
   433       locale::_S_uninitialize();
       
   434     }
       
   435 
       
   436 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
   437 	--get_ios_base_Init_S_count();
       
   438 # else
       
   439 	--ios_base::Init::_S_count;
       
   440 # endif //__LIBSTD_CPP_SYMBIAN32_WSD__
       
   441     
       
   442 }
       
   443 
       
   444 
       
   445 _STLP_EXP_DECLSPEC bool _STLP_CALL ios_base::sync_with_stdio(bool sync) {
       
   446 #if !defined(STLP_WINCE)
       
   447 # ifndef _STLP_HAS_NO_NAMESPACES
       
   448   using _SgI::stdio_istreambuf;
       
   449   using _SgI::stdio_ostreambuf;
       
   450 # endif
       
   451 
       
   452 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
   453 	bool was_synced =  get_ios_base_S_was_synced();
       
   454 # else
       
   455 	bool was_synced =  _S_was_synced;
       
   456 # endif  //__LIBSTD_CPP_SYMBIAN32_WSD__
       
   457 
       
   458   // if by any chance we got there before std streams initialization,
       
   459   // just set the sync flag and exit
       
   460 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
   461 	if (get_ios_base_Init_S_count() == 0) {
       
   462     get_ios_base_S_was_synced() = sync;
       
   463 # else
       
   464 	if (Init::_S_count == 0) {
       
   465     _S_was_synced = sync;
       
   466 # endif //__LIBSTD_CPP_SYMBIAN32_WSD__ 
       
   467     return was_synced;
       
   468   }
       
   469 
       
   470 #if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
       
   471   istream* ptr_cin  = __REINTERPRET_CAST(istream*,&GetCinStream());
       
   472   ostream* ptr_cout = __REINTERPRET_CAST(ostream*,&GetCoutStream());
       
   473   ostream* ptr_cerr = __REINTERPRET_CAST(ostream*,&GetCErrStream());
       
   474   ostream* ptr_clog = __REINTERPRET_CAST(ostream*,&GetClogStream());
       
   475 # else
       
   476   istream* ptr_cin  = __REINTERPRET_CAST(istream*,&cin);
       
   477   ostream* ptr_cout = __REINTERPRET_CAST(ostream*,&cout);
       
   478   ostream* ptr_cerr = __REINTERPRET_CAST(ostream*,&cerr);
       
   479   ostream* ptr_clog = __REINTERPRET_CAST(ostream*,&clog);	
       
   480 # endif //__LIBSTD_CPP_SYMBIAN32_WSD__
       
   481 
       
   482   streambuf* old_cin  = ptr_cin->rdbuf();
       
   483   streambuf* old_cout = ptr_cout->rdbuf();
       
   484   streambuf* old_cerr = ptr_cerr->rdbuf();
       
   485   streambuf* old_clog = ptr_clog->rdbuf();
       
   486 
       
   487   streambuf* new_cin  = 0;
       
   488   streambuf* new_cout = 0;
       
   489   streambuf* new_cerr = 0;
       
   490   streambuf* new_clog = 0;
       
   491 
       
   492   _STLP_TRY {
       
   493     if (sync && !was_synced) {
       
   494       new_cin  = new stdio_istreambuf(stdin);
       
   495       new_cout = new stdio_ostreambuf(stdout);
       
   496       new_cerr = new stdio_ostreambuf(stderr);
       
   497       new_clog = new stdio_ostreambuf(stderr);
       
   498     }
       
   499     else if (!sync && was_synced) {
       
   500       new_cin  = _Stl_create_filebuf(stdin, ios_base::in);
       
   501       new_cout = _Stl_create_filebuf(stdout, ios_base::out);
       
   502       new_cerr = _Stl_create_filebuf(stderr, ios_base::out);
       
   503       new_clog = _Stl_create_filebuf(stderr, ios_base::out);
       
   504     }
       
   505   }
       
   506   _STLP_CATCH_ALL {}
       
   507 
       
   508   if (new_cin && new_cout && new_cerr && new_clog) {
       
   509     ptr_cin->rdbuf(new_cin);
       
   510     ptr_cout->rdbuf(new_cout);
       
   511     ptr_cerr->rdbuf(new_cerr);
       
   512     ptr_clog->rdbuf(new_clog);
       
   513 
       
   514     delete old_cin;
       
   515     delete old_cout;
       
   516     delete old_cerr;
       
   517     delete old_clog;
       
   518   }
       
   519   else {
       
   520     delete new_cin;
       
   521     delete new_cout;
       
   522     delete new_cerr;
       
   523     delete new_clog;
       
   524   }
       
   525 
       
   526   return was_synced;
       
   527 #else
       
   528   return false;
       
   529 #endif /* _STLP_WINCE */
       
   530 }
       
   531 
       
   532 _STLP_END_NAMESPACE
       
   533 
       
   534 // Local Variables:
       
   535 // mode:C++
       
   536 // End: