summaryrefslogtreecommitdiff
path: root/StdLib/LibC/Main
diff options
context:
space:
mode:
authordarylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524>2011-07-30 00:30:44 +0000
committerdarylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524>2011-07-30 00:30:44 +0000
commitd7ce700605e1af0e455e31ec11f19ff21d26b525 (patch)
tree243b582ac3350e8c6ce6ca96fff13805318fd65c /StdLib/LibC/Main
parentf766dd76fde231ecd4f2e9faf99293e90902cebb (diff)
downloadedk2-platforms-d7ce700605e1af0e455e31ec11f19ff21d26b525.tar.xz
Add Socket Libraries.
Add Posix functions for porting compatibility. Fix compliance issues with ISO/IEC 9899:199409 New Functions: setenv(), fparseln(), GetFileNameFromPath(), rename(), realpath(), setprogname(), getprogname(), strlcat(), strlcpy(), strsep(), setitimer(), getitimer(), timegm(), getopt(), basename(), mkstemp(), ffs(), vsnprintf(), snprintf(), getpass(), usleep(), select(), writev(), strcasecmp(), getcwd(), chdir(), tcgetpgrp(), getpgrp(), gettimeofday(), bcopy(), git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12061 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'StdLib/LibC/Main')
-rw-r--r--StdLib/LibC/Main/Main.c70
-rw-r--r--StdLib/LibC/Main/assert.c1
-rw-r--r--StdLib/LibC/Main/x86flt_rounds.c1
3 files changed, 54 insertions, 18 deletions
diff --git a/StdLib/LibC/Main/Main.c b/StdLib/LibC/Main/Main.c
index 47103ce388..3a5cca5b24 100644
--- a/StdLib/LibC/Main/Main.c
+++ b/StdLib/LibC/Main/Main.c
@@ -8,13 +8,14 @@
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Uefi.h>
#include <Library/UefiLib.h>
+#include <Library/DebugLib.h>
#include <Library/ShellCEntryLib.h>
#include <Library/MemoryAllocationLib.h>
@@ -40,23 +41,30 @@ void __main()
;
}
-static
+/** Clean up data as required by the exit() function.
+
+**/
void
-FinalCleanup( void )
+exitCleanup(INTN ExitVal)
{
+ void (*CleanUp)(void); // Pointer to Cleanup Function
int i;
- /* Close any open files */
- for(i = OPEN_MAX - 1; i >= 0; --i) {
- (void)close(i); // Close properly handles closing a closed file.
+ if(gMD != NULL) {
+ gMD->ExitValue = (int)ExitVal;
+ CleanUp = gMD->cleanup; // Preserve the pointer to the Cleanup Function
+
+ // Call all registered atexit functions in reverse order
+ i = gMD->num_atexit;
+ if( i > 0) {
+ do {
+ (gMD->atexit_handler[--i])();
+ } while( i > 0);
}
- /* Free the global MainData structure */
- if(gMD != NULL) {
- if(gMD->NCmdLine != NULL) {
- FreePool( gMD->NCmdLine );
+ if (CleanUp != NULL) {
+ CleanUp();
}
- FreePool( gMD );
}
}
@@ -71,6 +79,13 @@ ArgvConvert(UINTN Argc, CHAR16 **Argv)
char *string;
INTN nArgvSize; /* Cumulative size of narrow Argv[i] */
+DEBUG_CODE_BEGIN();
+ Print(L"ArgvConvert called with %d arguments.\n", Argc);
+ for(count = 0; count < ((Argc > 5)? 5: Argc); ++count) {
+ Print(L"Argument[%d] = \"%s\".\n", count, Argv[count]);
+ }
+DEBUG_CODE_END();
+
nArgvSize = Argc;
/* Determine space needed for narrow Argv strings. */
for(count = 0; count < Argc; ++count) {
@@ -98,6 +113,7 @@ ArgvConvert(UINTN Argc, CHAR16 **Argv)
nArgv[count] = string;
AVsz = wcstombs(string, Argv[count], nArgvSize);
string[AVsz] = 0; /* NULL terminate the argument */
+ DEBUG((DEBUG_INFO, "Cvt[%d] %d \"%s\" --> \"%a\"\n", (INT32)count, (INT32)AVsz, Argv[count], nArgv[count]));
string += AVsz + 1;
nArgvSize -= AVsz + 1;
if(nArgvSize < 0) {
@@ -119,7 +135,7 @@ ShellAppMain (
struct __filedes *mfd;
char **nArgv;
INTN ExitVal;
- INTN i;
+ int i;
ExitVal = (INTN)RETURN_SUCCESS;
gMD = AllocateZeroPool(sizeof(struct __MainData));
@@ -132,7 +148,6 @@ ShellAppMain (
_fltused = 1;
errno = 0;
EFIerrno = 0;
- gMD->FinalCleanup = &FinalCleanup;
#ifdef NT32dvm
gMD->ClocksPerSecond = 1; // For NT32 only
@@ -166,10 +181,33 @@ ShellAppMain (
ExitVal = (INTN)RETURN_INVALID_PARAMETER;
}
else {
- ExitVal = (INTN)main( (int)Argc, nArgv);
+ if( setjmp(gMD->MainExit) == 0) {
+ ExitVal = (INTN)main( (int)Argc, gMD->NArgV);
+ exitCleanup(ExitVal);
+ }
+ /* You reach here if:
+ * normal return from main()
+ * call to _Exit(), either directly or through exit().
+ */
+ ExitVal = (INTN)gMD->ExitValue;
+ }
+
+ if( ExitVal == EXIT_FAILURE) {
+ ExitVal = RETURN_ABORTED;
+ }
+
+ /* Close any open files */
+ for(i = OPEN_MAX - 1; i >= 0; --i) {
+ (void)close(i); // Close properly handles closing a closed file.
+ }
+
+ /* Free the global MainData structure */
+ if(gMD != NULL) {
+ if(gMD->NCmdLine != NULL) {
+ FreePool( gMD->NCmdLine );
+ }
+ FreePool( gMD );
}
}
- exit((int)ExitVal);
- /* Not Reached */
return ExitVal;
}
diff --git a/StdLib/LibC/Main/assert.c b/StdLib/LibC/Main/assert.c
index 6bb53d6abd..a20a656ef0 100644
--- a/StdLib/LibC/Main/assert.c
+++ b/StdLib/LibC/Main/assert.c
@@ -18,7 +18,6 @@
#include <stdlib.h>
void
-EFIAPI
__assert(const char *func, const char *file, int line, const char *failedexpr)
{
if (func == NULL)
diff --git a/StdLib/LibC/Main/x86flt_rounds.c b/StdLib/LibC/Main/x86flt_rounds.c
index d0478e2c1b..86b4846098 100644
--- a/StdLib/LibC/Main/x86flt_rounds.c
+++ b/StdLib/LibC/Main/x86flt_rounds.c
@@ -16,7 +16,6 @@ extern int internal_FPU_rmode( void );
static INT8 rmode[] = { 1, 3, 2, 0 };
int
-EFIAPI
__flt_rounds ( void )
{
return rmode[ internal_FPU_rmode() ];