os/ossrv/genericopenlibs/cppstdlib/stl/src/iostream.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/src/iostream.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,524 @@
     1.4 +/*
     1.5 + * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     1.6 + *
     1.7 + * Copyright (c) 1999
     1.8 + * Silicon Graphics Computer Systems, Inc.
     1.9 + *
    1.10 + * Copyright (c) 1999
    1.11 + * Boris Fomitchev
    1.12 + *
    1.13 + * This material is provided "as is", with absolutely no warranty expressed
    1.14 + * or implied. Any use is at your own risk.
    1.15 + *
    1.16 + * Permission to use or copy this software for any purpose is hereby granted
    1.17 + * without fee, provided the above notices are retained on all copies.
    1.18 + * Permission to modify the code and to distribute modified code is granted,
    1.19 + * provided the above notices are retained, and a notice that the code was
    1.20 + * modified is included with the above copyright notice.
    1.21 + *
    1.22 + */
    1.23 +#include "stlport_prefix.h"
    1.24 +
    1.25 +#include <istream>
    1.26 +#include <fstream>
    1.27 +#if defined (_STLP_MSVC) || defined (__MWERKS__) || defined (__ICL) || defined (__ISCPP__) || defined(__SYMBIAN32__)
    1.28 +#  define _STLP_USE_NOT_INIT_SEGMENT
    1.29 +#  include <iostream>
    1.30 +#endif
    1.31 +
    1.32 +#if defined(__SYMBIAN32__WSD__)
    1.33 +# include "libstdcppwsd.h"
    1.34 +#endif
    1.35 +
    1.36 +#include "stdio_streambuf.h"
    1.37 +#include "aligned_buffer.h"
    1.38 +#include "_stdio_file.h"
    1.39 +#include "c_locale.h"
    1.40 +
    1.41 +// boris : note this is repeated in <iostream>
    1.42 +#ifndef _STLP_USE_NAMESPACES
    1.43 +// in case of SGI iostreams, we have to rename our streams not to clash with those
    1.44 +// provided in native lib
    1.45 +#  define cin _STLP_cin
    1.46 +#  define cout _STLP_cout
    1.47 +#  define cerr _STLP_cerr
    1.48 +#  define clog _STLP_clog
    1.49 +#endif
    1.50 +
    1.51 +_STLP_BEGIN_NAMESPACE
    1.52 +
    1.53 +#if defined (__BORLANDC__) && ! defined (_STLP_USE_GLIBC)
    1.54 +using _STLP_VENDOR_CSTD::_streams;
    1.55 +#endif
    1.56 +
    1.57 +// This file handles iostream initialization.  It is inherently
    1.58 +// nonportable, since the C++ language definition provides no mechanism
    1.59 +// for controlling order of initialization of nonlocal objects.
    1.60 +// Initialization has three parts, which must be performed in the following
    1.61 +// order:
    1.62 +//  (1) Initialize the locale system
    1.63 +//  (2) Call the constructors for the eight global stream objects.
    1.64 +//  (3) Create streambufs for the global stream objects, and initialize
    1.65 +//      the stream objects by calling the init() member function.
    1.66 +
    1.67 +
    1.68 +#if defined (_STLP_USE_NOT_INIT_SEGMENT)
    1.69 +
    1.70 +// Definitions of the eight global I/O objects that are declared in
    1.71 +// <iostream>. For some compilers we use pragmas to put the global I/O
    1.72 +// objects into an initialization segment that will not
    1.73 +// be executed. We then explicitly invoke the constructors
    1.74 +// with placement new in ios_base::_S_initialize()
    1.75 +
    1.76 +#  if defined (__MWERKS__)
    1.77 +#    pragma suppress_init_code on
    1.78 +#  else
    1.79 +#    pragma init_seg("STLPORT_NO_INIT")
    1.80 +#  endif
    1.81 +
    1.82 +#if defined(__SYMBIAN32__NO_STATIC_IMPORTS__)
    1.83 +istream cin(0);
    1.84 +
    1.85 +#  ifdef _STLP_REDIRECT_STDSTREAMS
    1.86 +ofstream cout;
    1.87 +ofstream cerr;
    1.88 +ofstream clog;
    1.89 +#  else
    1.90 +ostream cout(0);
    1.91 +ostream cerr(0);
    1.92 +ostream clog(0);
    1.93 +#  endif
    1.94 +
    1.95 +#ifndef _STLP_NO_WCHAR_T
    1.96 +wistream wcin(0);
    1.97 +wostream wcout(0);
    1.98 +wostream wcerr(0);
    1.99 +wostream wclog(0);
   1.100 +#endif
   1.101 +
   1.102 +_STLP_DECLSPEC ostream& get_cerr()
   1.103 +	{	
   1.104 +	return cerr;
   1.105 +	}
   1.106 +
   1.107 +_STLP_DECLSPEC ostream& get_cout()
   1.108 +	{
   1.109 +    return cout;
   1.110 +	}
   1.111 +
   1.112 +_STLP_DECLSPEC ostream& get_clog()
   1.113 +	{
   1.114 +    return clog;
   1.115 +	}
   1.116 +
   1.117 +_STLP_DECLSPEC istream& get_cin()
   1.118 +	{
   1.119 +    return cin;
   1.120 +	}
   1.121 +
   1.122 +#  ifndef _STLP_NO_WCHAR_T
   1.123 +_STLP_DECLSPEC wostream& get_wcerr()
   1.124 +	{
   1.125 +	return wcerr;
   1.126 +	}
   1.127 +
   1.128 +_STLP_DECLSPEC wostream& get_wcout()
   1.129 +	{
   1.130 +	return wcout;
   1.131 +	}
   1.132 +
   1.133 +_STLP_DECLSPEC wostream& get_wclog()
   1.134 +	{
   1.135 +    return wclog;
   1.136 +	}
   1.137 +
   1.138 +_STLP_DECLSPEC wistream& get_wcin()
   1.139 +	{
   1.140 +    return wcin;
   1.141 +	}   
   1.142 +#endif //_STLP_NO_WCHAR_T
   1.143 +
   1.144 +
   1.145 +# elif defined (__SYMBIAN32__WSD__)
   1.146 +
   1.147 +_STLP_DECLSPEC ostream& get_cerr()
   1.148 +	{	
   1.149 +	return *get_libcpp_wsd().wsd_cerr;
   1.150 +	}
   1.151 +
   1.152 +_STLP_DECLSPEC ostream& get_cout()
   1.153 +	{
   1.154 +    return *get_libcpp_wsd().wsd_cout;
   1.155 +	}
   1.156 +
   1.157 +_STLP_DECLSPEC ostream& get_clog()
   1.158 +	{
   1.159 +    return *get_libcpp_wsd().wsd_clog;
   1.160 +	}
   1.161 +
   1.162 +_STLP_DECLSPEC istream& get_cin()
   1.163 +	{
   1.164 +    return *get_libcpp_wsd().wsd_cin;
   1.165 +	}
   1.166 +
   1.167 +#  ifndef _STLP_NO_WCHAR_T
   1.168 +_STLP_DECLSPEC wostream& get_wcerr()
   1.169 +	{
   1.170 +	return *get_libcpp_wsd().wsd_wcerr;
   1.171 +	}
   1.172 +
   1.173 +_STLP_DECLSPEC wostream& get_wcout()
   1.174 +	{
   1.175 +	return *get_libcpp_wsd().wsd_wcout;
   1.176 +	}
   1.177 +
   1.178 +_STLP_DECLSPEC wostream& get_wclog()
   1.179 +	{
   1.180 +    return *get_libcpp_wsd().wsd_wclog;
   1.181 +	}
   1.182 +
   1.183 +_STLP_DECLSPEC wistream& get_wcin()
   1.184 +	{
   1.185 +    return *get_libcpp_wsd().wsd_wcin;
   1.186 +	}   
   1.187 +#endif //_STLP_NO_WCHAR_T
   1.188 +
   1.189 +
   1.190 +#define _S_count 			get_ios_base_Init_S_count()
   1.191 +#define _S_was_synced 		get_ios_base_S_was_synced()
   1.192 +
   1.193 +#else
   1.194 +_STLP_DECLSPEC istream cin(0);
   1.195 +
   1.196 +#  ifdef _STLP_REDIRECT_STDSTREAMS
   1.197 +_STLP_DECLSPEC ofstream cout;
   1.198 +_STLP_DECLSPEC ofstream cerr;
   1.199 +_STLP_DECLSPEC ofstream clog;
   1.200 +#  else
   1.201 +_STLP_DECLSPEC ostream cout(0);
   1.202 +_STLP_DECLSPEC ostream cerr(0);
   1.203 +_STLP_DECLSPEC ostream clog(0);
   1.204 +#  endif
   1.205 +
   1.206 +#ifndef _STLP_NO_WCHAR_T
   1.207 +_STLP_DECLSPEC wistream wcin(0);
   1.208 +_STLP_DECLSPEC wostream wcout(0);
   1.209 +_STLP_DECLSPEC wostream wcerr(0);
   1.210 +_STLP_DECLSPEC wostream wclog(0);
   1.211 +#endif
   1.212 +#endif //__SYMBIAN32__NO_STATIC_IMPORTS__
   1.213 +
   1.214 +#  if defined (__MWERKS__)
   1.215 +#    pragma suppress_init_code off
   1.216 +#  endif
   1.217 +
   1.218 +#else
   1.219 +
   1.220 +// Definitions of the eight global I/O objects that are declared in
   1.221 +// <iostream>.  Disgusting hack: we deliberately define them with the
   1.222 +// wrong types so that the constructors don't get run automatically.
   1.223 +// We need special tricks to make sure that these objects are struct-
   1.224 +// aligned rather than byte-aligned.
   1.225 +
   1.226 +// This is not portable.  Declaring a variable with different types in
   1.227 +// two translations units is "undefined", according to the C++ standard.
   1.228 +// Most compilers, however, silently accept this instead of diagnosing
   1.229 +// it as an error.
   1.230 +
   1.231 +#  ifndef __DMC__
   1.232 +_STLP_DECLSPEC _Stl_aligned_buffer<istream> cin;
   1.233 +_STLP_DECLSPEC _Stl_aligned_buffer<ostream> cout;
   1.234 +_STLP_DECLSPEC _Stl_aligned_buffer<ostream> cerr;
   1.235 +_STLP_DECLSPEC _Stl_aligned_buffer<ostream> clog;
   1.236 +#  else
   1.237 +_Stl_aligned_buffer<istream> cin;
   1.238 +_Stl_aligned_buffer<ostream> cout;
   1.239 +_Stl_aligned_buffer<ostream> cerr;
   1.240 +_Stl_aligned_buffer<ostream> clog;
   1.241 +
   1.242 +#    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")
   1.243 +#    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")
   1.244 +#    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")
   1.245 +#    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")
   1.246 +#  endif
   1.247 +
   1.248 +#  ifndef _STLP_NO_WCHAR_T
   1.249 +
   1.250 +#    ifndef __DMC__
   1.251 +_STLP_DECLSPEC _Stl_aligned_buffer<wistream> wcin;
   1.252 +_STLP_DECLSPEC _Stl_aligned_buffer<wostream> wcout;
   1.253 +_STLP_DECLSPEC _Stl_aligned_buffer<wostream> wcerr;
   1.254 +_STLP_DECLSPEC _Stl_aligned_buffer<wostream> wclog;
   1.255 +#    else
   1.256 +_Stl_aligned_buffer<wistream> wcin;
   1.257 +_Stl_aligned_buffer<wostream> wcout;
   1.258 +_Stl_aligned_buffer<wostream> wcerr;
   1.259 +_Stl_aligned_buffer<wostream> wclog;
   1.260 +
   1.261 +#      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")
   1.262 +#      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")
   1.263 +#      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")
   1.264 +#      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")
   1.265 +#    endif
   1.266 +#  endif
   1.267 +#endif /* STL_MSVC || __MWERKS__ */
   1.268 +
   1.269 +// Member functions from class ios_base and ios_base::Init
   1.270 +#if !defined(__SYMBIAN32__WSD__)
   1.271 +long ios_base::Init::_S_count = 0;
   1.272 +// by default, those are synced
   1.273 +bool ios_base::_S_was_synced = true;
   1.274 +# endif //__SYMBIAN32__WSD__
   1.275 +
   1.276 +_STLP_DECLSPEC ios_base::Init::Init() {
   1.277 +  if (_S_count++ == 0) {
   1.278 +    _Locale_init();
   1.279 +    ios_base::_S_initialize();
   1.280 +    _Filebuf_base::_S_initialize();
   1.281 +  }
   1.282 +}
   1.283 +
   1.284 +_STLP_DECLSPEC ios_base::Init::~Init() {
   1.285 +  if (--_S_count == 0) {
   1.286 +    ios_base::_S_uninitialize();
   1.287 +    _Locale_final();
   1.288 +  }
   1.289 +}
   1.290 + 
   1.291 +#ifdef __SYMBIAN32__
   1.292 +#undef _FILE_fd
   1.293 +#define _FILE_fd fileno
   1.294 +#endif
   1.295 +
   1.296 +static filebuf*
   1.297 +_Stl_create_filebuf(FILE* f, ios_base::openmode mode ) {
   1.298 +  basic_filebuf<char, char_traits<char> >* result =
   1.299 +    new basic_filebuf<char, char_traits<char> >();
   1.300 +
   1.301 +  _STLP_TRY {
   1.302 +    result->_M_open(_FILE_fd(f), mode);
   1.303 +  }
   1.304 +  _STLP_CATCH_ALL {}
   1.305 +
   1.306 +  if (!result->is_open()) {
   1.307 +    delete result;
   1.308 +    result = 0;
   1.309 +  }
   1.310 +  return result;
   1.311 +}
   1.312 +
   1.313 +#if !defined (_STLP_NO_WCHAR_T)
   1.314 +static wfilebuf*
   1.315 +_Stl_create_wfilebuf(FILE* f, ios_base::openmode mode) {
   1.316 +  basic_filebuf<wchar_t, char_traits<wchar_t> >* result =
   1.317 +    new basic_filebuf<wchar_t, char_traits<wchar_t> >();
   1.318 +
   1.319 +  _STLP_TRY {
   1.320 +    result->_M_open(_FILE_fd(f), mode);
   1.321 +  }
   1.322 +  _STLP_CATCH_ALL {}
   1.323 +
   1.324 +  if (!result->is_open()) {
   1.325 +    delete result;
   1.326 +    result = 0;
   1.327 +  }
   1.328 +  return result;
   1.329 +}
   1.330 +#endif
   1.331 +
   1.332 +void  _STLP_CALL ios_base::_S_initialize() {
   1.333 +#if !defined (_STLP_HAS_NO_NAMESPACES) && !defined (_STLP_DONT_USE_PRIV_NAMESPACE)
   1.334 +  using _STLP_PRIV stdio_istreambuf;
   1.335 +  using _STLP_PRIV stdio_ostreambuf;
   1.336 +#endif
   1.337 +  _STLP_TRY {
   1.338 +    istream* ptr_cin  = new(static_cast<void*>(&cin))  istream(0);
   1.339 +#  ifdef _STLP_REDIRECT_STDSTREAMS
   1.340 +    ofstream* ptr_cout = new(static_cast<void*>(&cout)) ofstream;
   1.341 +    ofstream* ptr_cerr = new(static_cast<void*>(&cerr)) ofstream;
   1.342 +    ofstream* ptr_clog = new(static_cast<void*>(&clog)) ofstream;
   1.343 +
   1.344 +    // Initialize the four narrow stream objects.
   1.345 +    if (_S_was_synced) {
   1.346 +      ptr_cin->init(new stdio_istreambuf(stdin));
   1.347 +      ptr_cout->open("/stdout.txt", ios::out);
   1.348 +      ptr_cerr->open("/stderr.txt", ios::out);
   1.349 +      ptr_clog->open("/stdlog.txt", ios::out);
   1.350 +    } else {
   1.351 +      ptr_cin->init(_Stl_create_filebuf(stdin, ios_base::in));
   1.352 +      ptr_cin->init(_Stl_create_filebuf(stdout, ios_base::out));
   1.353 +      ptr_cin->init(_Stl_create_filebuf(stderr, ios_base::out));
   1.354 +      ptr_cin->init(_Stl_create_filebuf(stderr, ios_base::out));
   1.355 +    }
   1.356 +    ptr_cin->tie(ptr_cout);
   1.357 +    ptr_cerr->setf(ios_base::unitbuf);
   1.358 +#  else
   1.359 +    ostream* ptr_cout = new(static_cast<void*>(&cout)) ostream(0);
   1.360 +    ostream* ptr_cerr = new(static_cast<void*>(&cerr)) ostream(0);
   1.361 +    ostream* ptr_clog = new(static_cast<void*>(&clog)) ostream(0);
   1.362 +
   1.363 +    // Initialize the four narrow stream objects.
   1.364 +    if (_S_was_synced) {
   1.365 +      ptr_cin->init(new stdio_istreambuf(stdin));
   1.366 +      ptr_cout->init(new stdio_ostreambuf(stdout));
   1.367 +      ptr_cerr->init(new stdio_ostreambuf(stdout));
   1.368 +      ptr_clog->init(new stdio_ostreambuf(stdout));
   1.369 +    } else {
   1.370 +      ptr_cin->init(_Stl_create_filebuf(stdin, ios_base::in));
   1.371 +      ptr_cin->init(_Stl_create_filebuf(stdout, ios_base::out));
   1.372 +      ptr_cin->init(_Stl_create_filebuf(stderr, ios_base::out));
   1.373 +      ptr_cin->init(_Stl_create_filebuf(stderr, ios_base::out));
   1.374 +    }
   1.375 +    ptr_cin->tie(ptr_cout);
   1.376 +    ptr_cerr->setf(ios_base::unitbuf);
   1.377 +#  endif /* _STLP_REDIRECT_STDSTREAMS */
   1.378 +
   1.379 +#  ifndef _STLP_NO_WCHAR_T
   1.380 +    // Run constructors for the four wide stream objects.
   1.381 +    wistream* ptr_wcin  = new(&wcin)  wistream(0);
   1.382 +    wostream* ptr_wcout = new(&wcout) wostream(0);
   1.383 +    wostream* ptr_wcerr = new(&wcerr) wostream(0);
   1.384 +    wostream* ptr_wclog = new(&wclog) wostream(0);
   1.385 +
   1.386 +    wfilebuf* win  = _Stl_create_wfilebuf(stdin, ios_base::in);
   1.387 +    wfilebuf* wout = _Stl_create_wfilebuf(stdout, ios_base::out);
   1.388 +    wfilebuf* werr = _Stl_create_wfilebuf(stdout, ios_base::out);
   1.389 +    wfilebuf* wlog = _Stl_create_wfilebuf(stdout, ios_base::out);
   1.390 +
   1.391 +    ptr_wcin->init(win);
   1.392 +    ptr_wcout->init(wout);
   1.393 +    ptr_wcerr->init(werr);
   1.394 +    ptr_wclog->init(wlog);
   1.395 +
   1.396 +    ptr_wcin->tie(ptr_wcout);
   1.397 +    ptr_wcerr->setf(ios_base::unitbuf);
   1.398 +
   1.399 +#  endif /*  _STLP_NO_WCHAR_T */
   1.400 +  }
   1.401 +
   1.402 +  _STLP_CATCH_ALL {}
   1.403 +}
   1.404 +
   1.405 +void _STLP_CALL ios_base::_S_uninitialize() {
   1.406 +  // Note that destroying output streambufs flushes the buffers.
   1.407 +
   1.408 +  istream* ptr_cin  = &cin;
   1.409 +  ostream* ptr_cout = &cout;
   1.410 +  ostream* ptr_cerr = &cerr;
   1.411 +  ostream* ptr_clog = &clog;
   1.412 +
   1.413 +#ifndef _STLP_NO_WCHAR_T
   1.414 +  wistream* ptr_wcin  = &wcin;
   1.415 +  wostream* ptr_wcout = &wcout;
   1.416 +  wostream* ptr_wcerr = &wcerr;
   1.417 +  wostream* ptr_wclog = &wclog;
   1.418 +#endif
   1.419 +
   1.420 +  // we don't want any exceptions being thrown here
   1.421 +  ptr_cin->exceptions(0);
   1.422 +  ptr_cout->exceptions(0);
   1.423 +  ptr_cerr->exceptions(0);
   1.424 +  ptr_clog->exceptions(0);
   1.425 +
   1.426 +  delete ptr_cin->rdbuf(0);
   1.427 +  delete ptr_cout->rdbuf(0);
   1.428 +  delete ptr_cerr->rdbuf(0);
   1.429 +  delete ptr_clog->rdbuf(0);
   1.430 +
   1.431 +  _Destroy(ptr_cin);
   1.432 +  _Destroy(ptr_cout);
   1.433 +  _Destroy(ptr_cerr);
   1.434 +  _Destroy(ptr_clog);
   1.435 +
   1.436 +#ifndef _STLP_NO_WCHAR_T
   1.437 +  // we don't want any exceptions being thrown here
   1.438 +  ptr_wcin->exceptions(0);
   1.439 +  ptr_wcout->exceptions(0);
   1.440 +  ptr_wcerr->exceptions(0);
   1.441 +  ptr_wclog->exceptions(0);
   1.442 +
   1.443 +  delete ptr_wcin->rdbuf(0);
   1.444 +  delete ptr_wcout->rdbuf(0);
   1.445 +  delete ptr_wcerr->rdbuf(0);
   1.446 +  delete ptr_wclog->rdbuf(0);
   1.447 +
   1.448 +  _Destroy(ptr_wcin);
   1.449 +  _Destroy(ptr_wcout);
   1.450 +  _Destroy(ptr_wcerr);
   1.451 +  _Destroy(ptr_wclog);
   1.452 +#endif
   1.453 +}
   1.454 +
   1.455 +
   1.456 +_STLP_DECLSPEC bool _STLP_CALL ios_base::sync_with_stdio(bool sync) {
   1.457 +#  if !defined (_STLP_HAS_NO_NAMESPACES) && !defined (_STLP_DONT_USE_PRIV_NAMESPACE)
   1.458 +  using _STLP_PRIV stdio_istreambuf;
   1.459 +  using _STLP_PRIV stdio_ostreambuf;
   1.460 +#  endif
   1.461 +
   1.462 +  bool was_synced =  _S_was_synced;
   1.463 +
   1.464 +  // if by any chance we got there before std streams initialization,
   1.465 +  // just set the sync flag and exit
   1.466 +  if (Init::_S_count == 0) {
   1.467 +    _S_was_synced = sync;
   1.468 +    return was_synced;
   1.469 +  }
   1.470 +
   1.471 +  istream* ptr_cin  = &cin;
   1.472 +  ostream* ptr_cout = &cout;
   1.473 +  ostream* ptr_cerr = &cerr;
   1.474 +  ostream* ptr_clog = &clog;
   1.475 +
   1.476 +  streambuf* old_cin  = ptr_cin->rdbuf();
   1.477 +  streambuf* old_cout = ptr_cout->rdbuf();
   1.478 +  streambuf* old_cerr = ptr_cerr->rdbuf();
   1.479 +  streambuf* old_clog = ptr_clog->rdbuf();
   1.480 +
   1.481 +  streambuf* new_cin  = 0;
   1.482 +  streambuf* new_cout = 0;
   1.483 +  streambuf* new_cerr = 0;
   1.484 +  streambuf* new_clog = 0;
   1.485 +
   1.486 +  _STLP_TRY {
   1.487 +    if (sync && !was_synced) {
   1.488 +      new_cin  = new stdio_istreambuf(stdin);
   1.489 +      new_cout = new stdio_ostreambuf(stdout);
   1.490 +      new_cerr = new stdio_ostreambuf(stdout);
   1.491 +      new_clog = new stdio_ostreambuf(stdout);
   1.492 +    }
   1.493 +    else if (!sync && was_synced) {
   1.494 +      new_cin  = _Stl_create_filebuf(stdin, ios_base::in);
   1.495 +      new_cout = _Stl_create_filebuf(stdout, ios_base::out);
   1.496 +      new_cerr = _Stl_create_filebuf(stdout, ios_base::out);
   1.497 +      new_clog = _Stl_create_filebuf(stdout, ios_base::out);
   1.498 +    }
   1.499 +  }
   1.500 +  _STLP_CATCH_ALL {}
   1.501 +
   1.502 +  if (new_cin && new_cout && new_cerr && new_clog) {
   1.503 +    ptr_cin->rdbuf(new_cin);
   1.504 +    ptr_cout->rdbuf(new_cout);
   1.505 +    ptr_cerr->rdbuf(new_cerr);
   1.506 +    ptr_clog->rdbuf(new_clog);
   1.507 +
   1.508 +    delete old_cin;
   1.509 +    delete old_cout;
   1.510 +    delete old_cerr;
   1.511 +    delete old_clog;
   1.512 +  }
   1.513 +  else {
   1.514 +    delete new_cin;
   1.515 +    delete new_cout;
   1.516 +    delete new_cerr;
   1.517 +    delete new_clog;
   1.518 +  }
   1.519 +
   1.520 +  return was_synced;
   1.521 +}
   1.522 +
   1.523 +_STLP_END_NAMESPACE
   1.524 +
   1.525 +// Local Variables:
   1.526 +// mode:C++
   1.527 +// End: