Esempio n. 1
0
INTN
EFIAPI
DriverInitMain(
IN UINTN Argc,
IN CHAR16 **Argv
)
{
    struct __filedes   *mfd;
    //char              **nArgv;
    INTN   ExitVal;
    int                 i;

    ExitVal = (INTN)RETURN_SUCCESS;
    gMD = AllocateZeroPool(sizeof(struct __MainData));
    if (gMD == NULL) {
        ExitVal = (INTN)RETURN_OUT_OF_RESOURCES;
    }
    else {
        /* Initialize data */
        extern   int __sse2_available;
        __sse2_available = 0;
        _fltused = 1;
        errno = 0;
        EFIerrno = 0;

        gMD->ClocksPerSecond = 1;
        gMD->AppStartTime = (clock_t)((UINT32)time(NULL));

        // Initialize file descriptors
        mfd = gMD->fdarray;
        for (i = 0; i < (FOPEN_MAX); ++i) {
            mfd[i].MyFD = (UINT16)i;
        }

        i = open("stdin:", O_RDONLY, 0444);
        if (i == 0) {
            i = open("stdout:", O_WRONLY, 0222);
            if (i == 1) {
                i = open("stderr:", O_WRONLY, 0222);
            }
        }
        if (i != 2) {
            Print(L"ERROR Initializing Standard IO: %a.\n    %r\n",
                strerror(errno), EFIerrno);
        }

        /* Create mbcs versions of the Argv strings. */
#if 0
        nArgv = ArgvConvert(Argc, Argv);
        if (nArgv == NULL) {
            ExitVal = (INTN)RETURN_INVALID_PARAMETER;
        }
        else {
            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;
        }
#endif

#if 0
        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);
        }
#endif
    }
    return ExitVal;
}
Esempio n. 2
0
/** The exit function causes normal program termination to occur. If more than
    one call to the exit function is executed by a program,
    the behavior is undefined.

    First, all functions registered by the atexit function are called, in the
    reverse order of their registration. If, during the call to any such function, a
    call to the longjmp function is made that would terminate the call to the
    registered function, the behavior is undefined.

    Next, all open streams with unwritten buffered data are flushed, all open
    streams are closed, and all files created by the tmpfile function
    are removed.

    The status returned to the host environment is determined in the same way
    as for the _Exit function.
**/
void
exit(int status)
{
  exitCleanup((INTN) status);
  _Exit(status);
}