os/ossrv/genericopenlibs/cppstdlib/src/set_new_handler.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Name        : new_handler.cpp
sl@0
    15
// Part of     : libstdcpp
sl@0
    16
// Adaptation layer to get locale functionality.
sl@0
    17
// Version     : 
sl@0
    18
// This material, including documentation and any related 
sl@0
    19
// computer programs, is protected by copyright controlled by 
sl@0
    20
// Nokia Corporation. All rights are reserved. Copying, 
sl@0
    21
// including reproducing, storing, adapting or translating, any 
sl@0
    22
// or all of this material requires the prior written consent of 
sl@0
    23
// Nokia Corporation. This material also contains confidential 
sl@0
    24
// information which may not be disclosed to others without the 
sl@0
    25
// prior written consent of Nokia Corporation.
sl@0
    26
//
sl@0
    27
sl@0
    28
sl@0
    29
sl@0
    30
#include "new"
sl@0
    31
#include <e32std.h>
sl@0
    32
sl@0
    33
_LIT(K,"set_new_handler");
sl@0
    34
sl@0
    35
sl@0
    36
using std::new_handler;
sl@0
    37
sl@0
    38
#ifdef __SYMBIAN_STDCPP_SUPPORT__ 
sl@0
    39
sl@0
    40
EXPORT_C new_handler std::set_new_handler(new_handler a_new_nh) __NO_THROW
sl@0
    41
	{
sl@0
    42
	new_handler current_nh;
sl@0
    43
	TAny* tls_word_p = Dll::Tls();
sl@0
    44
sl@0
    45
	if (!tls_word_p)
sl@0
    46
		{
sl@0
    47
		// This is the first time we're called, so we need to set up the TLS.
sl@0
    48
sl@0
    49
		tls_word_p = User::Alloc( sizeof(new_handler) );
sl@0
    50
		if ( !tls_word_p )
sl@0
    51
			{
sl@0
    52
			User::Panic(K, KErrNoMemory);
sl@0
    53
			}
sl@0
    54
sl@0
    55
		Dll::SetTls(tls_word_p);
sl@0
    56
		current_nh = 0;
sl@0
    57
		}
sl@0
    58
	else
sl@0
    59
		{
sl@0
    60
		// Get the currently installed new_handler function.
sl@0
    61
		current_nh = *reinterpret_cast<new_handler*>(tls_word_p);
sl@0
    62
		}
sl@0
    63
	
sl@0
    64
	// Set the new new_handler.
sl@0
    65
	*reinterpret_cast<new_handler*>(tls_word_p) = a_new_nh;
sl@0
    66
sl@0
    67
	return current_nh;
sl@0
    68
	}
sl@0
    69
sl@0
    70
#endif // __SYMBIAN_STDCPP_SUPPORT__