sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // FUNCTION sl@0: // <>---definition of impure data. sl@0: // INDEX sl@0: // reent sl@0: // This module defines the impure data area used by the sl@0: // non-rentrant functions, such as strtok. sl@0: // sl@0: // sl@0: sl@0: #include "SYSIF.H" sl@0: #include sl@0: #include sl@0: sl@0: /* Interim cleanup code */ sl@0: sl@0: static void cleanup_glue (struct _glue *glue) sl@0: { sl@0: /* Have to reclaim these in reverse order: */ sl@0: if (glue->_next) sl@0: cleanup_glue (glue->_next); sl@0: free (glue); sl@0: } sl@0: sl@0: extern "C" { sl@0: sl@0: /** sl@0: The struct _reent is managed on a per-thread basis by EPOC32, so there is no sl@0: global variable _impure_pointer and everyone has to use _REENT (panics in the sl@0: event of an error) or REENT2 (which returns a NULL pointer in the event of an sl@0: error). sl@0: sl@0: @return sl@0: @param ptr sl@0: */ sl@0: EXPORT_C void sl@0: _reclaim_reent (struct _reent *ptr) sl@0: { sl@0: /* atexit stuff */ sl@0: if ((ptr->_atexit) && (ptr->_atexit != &ptr->_atexit0)) sl@0: { sl@0: struct _atexit *p, *q; sl@0: for (p = ptr->_atexit; p != &ptr->_atexit0;) sl@0: { sl@0: q = p; sl@0: p = p->_next; sl@0: free(q); sl@0: } sl@0: } sl@0: sl@0: if (ptr->environ) sl@0: free(ptr->environ); sl@0: sl@0: if (ptr->_netdb) sl@0: free(ptr->_netdb); sl@0: sl@0: if (ptr->__sdidinit) sl@0: { sl@0: /* cleanup won't reclaim memory 'coz usually it's run sl@0: before the program exits, and who wants to wait for that? */ sl@0: ptr->__cleanup (ptr); sl@0: if (ptr->__sglue._next) sl@0: cleanup_glue (ptr->__sglue._next); sl@0: } sl@0: sl@0: // narrow environment buffer sl@0: if (ptr->_pNarrowEnvBuffer) sl@0: { sl@0: free(ptr->_pNarrowEnvBuffer); sl@0: ptr->_pNarrowEnvBuffer = 0; sl@0: } sl@0: sl@0: MSystemInterface& sysIf=Interface(ptr); sl@0: sysIf.Release(); sl@0: sl@0: ptr->_system=0; sl@0: } sl@0: sl@0: EXPORT_C void _REENT_INIT(struct _reent *ptr) sl@0: { sl@0: MSystemInterface& sysIf=Interface(ImpurePtr()); sl@0: _init_reent(ptr,&sysIf.Clone()); sl@0: } sl@0: sl@0: extern "C" void __sinit(struct _reent*); // LSTDIO/LOCAL.H sl@0: sl@0: EXPORT_C void _init_reent(struct _reent *ptr, void* _system) sl@0: { sl@0: ptr->_system=_system; sl@0: __sinit(ptr); sl@0: ptr->_next[0]=1; sl@0: ptr->_next[1]=1; sl@0: sl@0: ptr->_pNarrowEnvBuffer = 0; sl@0: } sl@0: sl@0: } // extern "C"