os/ossrv/genericopenlibs/cppstdlib/src/set_new_handler.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/src/set_new_handler.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,70 @@
     1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Name        : new_handler.cpp
    1.18 +// Part of     : libstdcpp
    1.19 +// Adaptation layer to get locale functionality.
    1.20 +// Version     : 
    1.21 +// This material, including documentation and any related 
    1.22 +// computer programs, is protected by copyright controlled by 
    1.23 +// Nokia Corporation. All rights are reserved. Copying, 
    1.24 +// including reproducing, storing, adapting or translating, any 
    1.25 +// or all of this material requires the prior written consent of 
    1.26 +// Nokia Corporation. This material also contains confidential 
    1.27 +// information which may not be disclosed to others without the 
    1.28 +// prior written consent of Nokia Corporation.
    1.29 +//
    1.30 +
    1.31 +
    1.32 +
    1.33 +#include "new"
    1.34 +#include <e32std.h>
    1.35 +
    1.36 +_LIT(K,"set_new_handler");
    1.37 +
    1.38 +
    1.39 +using std::new_handler;
    1.40 +
    1.41 +#ifdef __SYMBIAN_STDCPP_SUPPORT__ 
    1.42 +
    1.43 +EXPORT_C new_handler std::set_new_handler(new_handler a_new_nh) __NO_THROW
    1.44 +	{
    1.45 +	new_handler current_nh;
    1.46 +	TAny* tls_word_p = Dll::Tls();
    1.47 +
    1.48 +	if (!tls_word_p)
    1.49 +		{
    1.50 +		// This is the first time we're called, so we need to set up the TLS.
    1.51 +
    1.52 +		tls_word_p = User::Alloc( sizeof(new_handler) );
    1.53 +		if ( !tls_word_p )
    1.54 +			{
    1.55 +			User::Panic(K, KErrNoMemory);
    1.56 +			}
    1.57 +
    1.58 +		Dll::SetTls(tls_word_p);
    1.59 +		current_nh = 0;
    1.60 +		}
    1.61 +	else
    1.62 +		{
    1.63 +		// Get the currently installed new_handler function.
    1.64 +		current_nh = *reinterpret_cast<new_handler*>(tls_word_p);
    1.65 +		}
    1.66 +	
    1.67 +	// Set the new new_handler.
    1.68 +	*reinterpret_cast<new_handler*>(tls_word_p) = a_new_nh;
    1.69 +
    1.70 +	return current_nh;
    1.71 +	}
    1.72 +
    1.73 +#endif // __SYMBIAN_STDCPP_SUPPORT__