Update contrib.
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 // Category for the panic.
19 _LIT(KEstlibInit, "ESTLIB-INIT");
21 // Access for the outside world
24 EXPORT_C void CloseSTDLIB()
26 struct _reent* p=(struct _reent*)Dll::Tls();
29 _reclaim_reent(p); // Reclaiming calls the atexit processing and generally tries to tidy up
30 User::Free(p); // then we give back the struct _reent itself
31 Dll::SetTls(0); // ... so we don't free it again when the DLL exits
35 Allocates memory for the library globals struct and returns a pointer to it. If the
36 memory has been allocated previously then it simply returns a pointer to the memory.
37 Panics if any error/failure occurs.
39 @return On Success, a pointer to the memory containing the library globals.
41 EXPORT_C struct _reent *ImpurePtr(void)
43 struct _reent* p=(struct _reent*)Dll::Tls();
45 return p; // Memory is already allocated for the library globals.
47 // First use, so construct the default struct _reent and the associated SystemInterface
48 p=(struct _reent*)User::Alloc(sizeof(struct _reent));
51 User::Panic(KEstlibInit,KErrNoMemory);
54 TInt err= Dll::SetTls(p);
61 User::Panic(KEstlibInit, err);
66 CProcessSystemInterface* pSysIf=new CProcessSystemInterface;
67 if (pSysIf && pSysIf->Connect()==KErrNone)
76 CTrapCleanup *cleanup = NULL;
77 if(User::TrapHandler() == NULL)
79 cleanup = CTrapCleanup::New();
82 //use static_cast to perform the valid conversion from CLocalSystemInterface to base class MSystemInterface
83 TRAP(err, sysIf = static_cast<MSystemInterface*> (CLocalSystemInterface::NewL()));
93 //use static_cast to perform the valid conversion from CLocalSystemInterface to base class MSystemInterface
94 TRAP(err, sysIf = static_cast<MSystemInterface*> (CLocalSystemInterface::NewL()));
103 User::Panic(KEstlibInit, err);
106 Mem::FillZ(p,sizeof(struct _reent));
107 _init_reent(p,sysIf);
113 This is a panic free version of ImpurePtr. It allocates memory for the library globals
114 struct and returns a pointer to it. If the memory has been allocated previously then it
115 simply returns a pointer to the memory.
116 If there is not enough memory available to set up the library globals or other error occurs,
117 a NULL pointer will be returned.
119 @return On Success, a pointer to the memory containing the library globals.
120 On Failure, a NULL pointer.
122 EXPORT_C struct _reent * ImpurePtr2(void)
124 struct _reent* p = (struct _reent*)Dll::Tls();
126 return p; // Memory is already allocated for the library globals.
128 // First use, so construct the default struct _reent and the associated SystemInterface
129 p =(struct _reent*)User::Alloc(sizeof(struct _reent));
142 CProcessSystemInterface* pSysIf=new CProcessSystemInterface;
143 if (pSysIf && pSysIf->Connect()==KErrNone)
153 CTrapCleanup *cleanup = NULL;
154 if(User::TrapHandler() == NULL)
156 cleanup = CTrapCleanup::New();
159 //use static_cast to perform the valid conversion from CLocalSystemInterface to base class MSystemInterface
160 TRAP(err, sysIf = static_cast<MSystemInterface*> (CLocalSystemInterface::NewL()));
166 //use static_cast to perform the valid conversion from CLocalSystemInterface to base class MSystemInterface
167 TRAP(err, sysIf = static_cast<MSystemInterface*> (CLocalSystemInterface::NewL()));
179 Mem::FillZ(p,sizeof(struct _reent));
180 _init_reent(p,sysIf);
182 return p; // Library globals have been set up correctly.
186 EXPORT_C int *__errno(void)
188 return &(ImpurePtr()->_errno);
191 EXPORT_C void _exit (int status) _ATTRIBUTE((noreturn))
193 struct _reent* p=(struct _reent*)Dll::Tls();
196 MSystemInterface& sysIf=Interface(p);
197 sysIf.TerminateProcess(status);
199 RProcess().Terminate(status); // just in case
205 GLDEF_C TInt E32Dll(TDllReason)