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
This commit is contained in:
@@ -29,6 +29,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <MainData.h>
|
||||
|
||||
/** Internal worker function used by exit().
|
||||
**/
|
||||
void exitCleanup(INTN ExitVal);
|
||||
|
||||
/* ################# Public Functions ################################### */
|
||||
|
||||
/** The abort function causes abnormal program termination to occur, unless
|
||||
@@ -92,24 +96,7 @@ atexit(void (*handler)(void))
|
||||
void
|
||||
exit(int status)
|
||||
{
|
||||
void (*CleanUp)(void); // Pointer to Cleanup Function
|
||||
int i;
|
||||
|
||||
if(gMD != NULL) {
|
||||
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);
|
||||
}
|
||||
|
||||
if (CleanUp != NULL) {
|
||||
CleanUp();
|
||||
}
|
||||
}
|
||||
exitCleanup((INTN) status);
|
||||
_Exit(status);
|
||||
}
|
||||
|
||||
@@ -129,17 +116,12 @@ exit(int status)
|
||||
void
|
||||
_Exit(int status)
|
||||
{
|
||||
RETURN_STATUS ExitVal = (RETURN_STATUS)status;
|
||||
gMD->ExitValue = status; // Save our exit status. Allows a status of 0.
|
||||
longjmp(gMD->MainExit, 0x55); // Get out of here. longjmp can't return 0. Use 0x55 for a non-zero value.
|
||||
|
||||
if( ExitVal == EXIT_FAILURE) {
|
||||
ExitVal = RETURN_ABORTED;
|
||||
}
|
||||
|
||||
if(gMD->FinalCleanup != NULL) {
|
||||
gMD->FinalCleanup(); // gMD does not exist when this returns.
|
||||
}
|
||||
|
||||
gBS->Exit(gImageHandle, ExitVal, 0, NULL); /* abort() */
|
||||
#ifdef __GNUC__
|
||||
__builtin__Exit(status); /* Keep GCC happy - never reached */
|
||||
#endif
|
||||
}
|
||||
|
||||
/** If string is a null pointer, the system function determines whether the
|
||||
|
@@ -8,7 +8,7 @@
|
||||
- atol: strtol(nptr, (char **)NULL, 10)
|
||||
- atoll: strtoll(nptr, (char **)NULL, 10)
|
||||
|
||||
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||
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
|
||||
@@ -120,7 +120,7 @@ atoll(const char *nptr)
|
||||
static int
|
||||
Digit2Val( int c)
|
||||
{
|
||||
if(__isHexLetter(c)) { /* If c is one of [A-Fa-f]... */
|
||||
if(isalpha(c)) { /* If c is one of [A-Za-z]... */
|
||||
c = toupper(c) - 7; // Adjust so 'A' is ('9' + 1)
|
||||
}
|
||||
return c - '0'; // Value returned is between 0 and 35, inclusive.
|
||||
@@ -183,13 +183,18 @@ Digit2Val( int c)
|
||||
long
|
||||
strtol(const char * __restrict nptr, char ** __restrict endptr, int base)
|
||||
{
|
||||
const char *pEnd;
|
||||
long Result = 0;
|
||||
long Previous;
|
||||
int temp;
|
||||
BOOLEAN Negative = FALSE;
|
||||
|
||||
pEnd = nptr;
|
||||
|
||||
if((base < 0) || (base == 1) || (base > 36)) {
|
||||
if(endptr != NULL) {
|
||||
*endptr = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// Skip leading spaces.
|
||||
@@ -204,9 +209,29 @@ strtol(const char * __restrict nptr, char ** __restrict endptr, int base)
|
||||
Negative = TRUE;
|
||||
++nptr;
|
||||
}
|
||||
if( (base == 16) && (*nptr == '0') && (toupper(nptr[1]) == 'X')) {
|
||||
nptr += 2;
|
||||
|
||||
if(*nptr == '0') { /* Might be Octal or Hex */
|
||||
if(toupper(nptr[1]) == 'X') { /* Looks like Hex */
|
||||
if((base == 0) || (base == 16)) {
|
||||
nptr += 2; /* Skip the "0X" */
|
||||
base = 16; /* In case base was 0 */
|
||||
}
|
||||
}
|
||||
else { /* Looks like Octal */
|
||||
if((base == 0) || (base == 8)) {
|
||||
++nptr; /* Skip the leading "0" */
|
||||
base = 8; /* In case base was 0 */
|
||||
}
|
||||
}
|
||||
}
|
||||
if(base == 0) { /* If still zero then must be decimal */
|
||||
base = 10;
|
||||
}
|
||||
if(*nptr == '0') {
|
||||
for( ; *nptr == '0'; ++nptr); /* Skip any remaining leading zeros */
|
||||
pEnd = nptr;
|
||||
}
|
||||
|
||||
while( isalnum(*nptr) && ((temp = Digit2Val(*nptr)) < base)) {
|
||||
Previous = Result;
|
||||
Result = (Result * base) + (long int)temp;
|
||||
@@ -221,15 +246,15 @@ strtol(const char * __restrict nptr, char ** __restrict endptr, int base)
|
||||
errno = ERANGE;
|
||||
break;
|
||||
}
|
||||
++nptr;
|
||||
pEnd = ++nptr;
|
||||
}
|
||||
if(Negative) {
|
||||
Result = -Result;
|
||||
}
|
||||
|
||||
// Save pointer to final sequence
|
||||
if( endptr != NULL) {
|
||||
*endptr = (char *)nptr;
|
||||
if(endptr != NULL) {
|
||||
*endptr = (char *)pEnd;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
@@ -247,12 +272,17 @@ strtol(const char * __restrict nptr, char ** __restrict endptr, int base)
|
||||
unsigned long
|
||||
strtoul(const char * __restrict nptr, char ** __restrict endptr, int base)
|
||||
{
|
||||
const char *pEnd;
|
||||
unsigned long Result = 0;
|
||||
unsigned long Previous;
|
||||
int temp;
|
||||
|
||||
pEnd = nptr;
|
||||
|
||||
if((base < 0) || (base == 1) || (base > 36)) {
|
||||
if(endptr != NULL) {
|
||||
*endptr = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// Skip leading spaces.
|
||||
@@ -262,9 +292,29 @@ strtoul(const char * __restrict nptr, char ** __restrict endptr, int base)
|
||||
if(*nptr == '+') {
|
||||
++nptr;
|
||||
}
|
||||
if( (base == 16) && (*nptr == '0') && (toupper(nptr[1]) == 'X')) {
|
||||
nptr += 2;
|
||||
|
||||
if(*nptr == '0') { /* Might be Octal or Hex */
|
||||
if(toupper(nptr[1]) == 'X') { /* Looks like Hex */
|
||||
if((base == 0) || (base == 16)) {
|
||||
nptr += 2; /* Skip the "0X" */
|
||||
base = 16; /* In case base was 0 */
|
||||
}
|
||||
}
|
||||
else { /* Looks like Octal */
|
||||
if((base == 0) || (base == 8)) {
|
||||
++nptr; /* Skip the leading "0" */
|
||||
base = 8; /* In case base was 0 */
|
||||
}
|
||||
}
|
||||
}
|
||||
if(base == 0) { /* If still zero then must be decimal */
|
||||
base = 10;
|
||||
}
|
||||
if(*nptr == '0') {
|
||||
for( ; *nptr == '0'; ++nptr); /* Skip any remaining leading zeros */
|
||||
pEnd = nptr;
|
||||
}
|
||||
|
||||
while( isalnum(*nptr) && ((temp = Digit2Val(*nptr)) < base)) {
|
||||
Previous = Result;
|
||||
Result = (Result * base) + (unsigned long)temp;
|
||||
@@ -273,12 +323,12 @@ strtoul(const char * __restrict nptr, char ** __restrict endptr, int base)
|
||||
errno = ERANGE;
|
||||
break;
|
||||
}
|
||||
++nptr;
|
||||
pEnd = ++nptr;
|
||||
}
|
||||
|
||||
// Save pointer to final sequence
|
||||
if( endptr != NULL) {
|
||||
*endptr = (char *)nptr;
|
||||
if(endptr != NULL) {
|
||||
*endptr = (char *)pEnd;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
@@ -297,13 +347,18 @@ strtoul(const char * __restrict nptr, char ** __restrict endptr, int base)
|
||||
long long
|
||||
strtoll(const char * __restrict nptr, char ** __restrict endptr, int base)
|
||||
{
|
||||
const char *pEnd;
|
||||
long long Result = 0;
|
||||
long long Previous;
|
||||
int temp;
|
||||
BOOLEAN Negative = FALSE;
|
||||
|
||||
pEnd = nptr;
|
||||
|
||||
if((base < 0) || (base == 1) || (base > 36)) {
|
||||
if(endptr != NULL) {
|
||||
*endptr = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// Skip leading spaces.
|
||||
@@ -318,9 +373,29 @@ strtoll(const char * __restrict nptr, char ** __restrict endptr, int base)
|
||||
Negative = TRUE;
|
||||
++nptr;
|
||||
}
|
||||
if( (base == 16) && (*nptr == '0') && (toupper(nptr[1]) == 'X')) {
|
||||
nptr += 2;
|
||||
|
||||
if(*nptr == '0') { /* Might be Octal or Hex */
|
||||
if(toupper(nptr[1]) == 'X') { /* Looks like Hex */
|
||||
if((base == 0) || (base == 16)) {
|
||||
nptr += 2; /* Skip the "0X" */
|
||||
base = 16; /* In case base was 0 */
|
||||
}
|
||||
}
|
||||
else { /* Looks like Octal */
|
||||
if((base == 0) || (base == 8)) {
|
||||
++nptr; /* Skip the leading "0" */
|
||||
base = 8; /* In case base was 0 */
|
||||
}
|
||||
}
|
||||
}
|
||||
if(base == 0) { /* If still zero then must be decimal */
|
||||
base = 10;
|
||||
}
|
||||
if(*nptr == '0') {
|
||||
for( ; *nptr == '0'; ++nptr); /* Skip any remaining leading zeros */
|
||||
pEnd = nptr;
|
||||
}
|
||||
|
||||
while( isalnum(*nptr) && ((temp = Digit2Val(*nptr)) < base)) {
|
||||
Previous = Result;
|
||||
Result = (Result * base) + (long long int)temp;
|
||||
@@ -335,15 +410,15 @@ strtoll(const char * __restrict nptr, char ** __restrict endptr, int base)
|
||||
errno = ERANGE;
|
||||
break;
|
||||
}
|
||||
++nptr;
|
||||
pEnd = ++nptr;
|
||||
}
|
||||
if(Negative) {
|
||||
Result = -Result;
|
||||
}
|
||||
|
||||
// Save pointer to final sequence
|
||||
if( endptr != NULL) {
|
||||
*endptr = (char *)nptr;
|
||||
if(endptr != NULL) {
|
||||
*endptr = (char *)pEnd;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
@@ -361,12 +436,17 @@ strtoll(const char * __restrict nptr, char ** __restrict endptr, int base)
|
||||
unsigned long long
|
||||
strtoull(const char * __restrict nptr, char ** __restrict endptr, int base)
|
||||
{
|
||||
const char *pEnd;
|
||||
unsigned long long Result = 0;
|
||||
unsigned long long Previous;
|
||||
int temp;
|
||||
|
||||
pEnd = nptr;
|
||||
|
||||
if((base < 0) || (base == 1) || (base > 36)) {
|
||||
if(endptr != NULL) {
|
||||
*endptr = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// Skip leading spaces.
|
||||
@@ -376,9 +456,29 @@ strtoull(const char * __restrict nptr, char ** __restrict endptr, int base)
|
||||
if(*nptr == '+') {
|
||||
++nptr;
|
||||
}
|
||||
if( (base == 16) && (*nptr == '0') && (toupper(nptr[1]) == 'X')) {
|
||||
nptr += 2;
|
||||
|
||||
if(*nptr == '0') { /* Might be Octal or Hex */
|
||||
if(toupper(nptr[1]) == 'X') { /* Looks like Hex */
|
||||
if((base == 0) || (base == 16)) {
|
||||
nptr += 2; /* Skip the "0X" */
|
||||
base = 16; /* In case base was 0 */
|
||||
}
|
||||
}
|
||||
else { /* Looks like Octal */
|
||||
if((base == 0) || (base == 8)) {
|
||||
++nptr; /* Skip the leading "0" */
|
||||
base = 8; /* In case base was 0 */
|
||||
}
|
||||
}
|
||||
}
|
||||
if(base == 0) { /* If still zero then must be decimal */
|
||||
base = 10;
|
||||
}
|
||||
if(*nptr == '0') {
|
||||
for( ; *nptr == '0'; ++nptr); /* Skip any remaining leading zeros */
|
||||
pEnd = nptr;
|
||||
}
|
||||
|
||||
while( isalnum(*nptr) && ((temp = Digit2Val(*nptr)) < base)) {
|
||||
Previous = Result;
|
||||
Result = (Result * base) + (unsigned long long)temp;
|
||||
@@ -387,12 +487,12 @@ strtoull(const char * __restrict nptr, char ** __restrict endptr, int base)
|
||||
errno = ERANGE;
|
||||
break;
|
||||
}
|
||||
++nptr;
|
||||
pEnd = ++nptr;
|
||||
}
|
||||
|
||||
// Save pointer to final sequence
|
||||
if( endptr != NULL) {
|
||||
*endptr = (char *)nptr;
|
||||
if(endptr != NULL) {
|
||||
*endptr = (char *)pEnd;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
## @file
|
||||
# Standard C library: StdLib implementations.
|
||||
#
|
||||
# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
|
||||
# Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
@@ -36,6 +36,8 @@
|
||||
strtoumax.c
|
||||
Xabs.c
|
||||
Xdiv.c
|
||||
realpath.c
|
||||
setprogname.c
|
||||
|
||||
[Packages]
|
||||
StdLib/StdLib.dec
|
||||
@@ -53,6 +55,7 @@
|
||||
LibC
|
||||
LibCType
|
||||
LibSignal
|
||||
PathLib
|
||||
|
||||
################################################################
|
||||
#
|
||||
|
57
StdLib/LibC/StdLib/realpath.c
Normal file
57
StdLib/LibC/StdLib/realpath.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/** @file
|
||||
Implement the realpath function.
|
||||
|
||||
Copyright (c) 2011, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
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 <LibConfig.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/PathLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <errno.h>
|
||||
|
||||
/**
|
||||
The realpath() function shall derive, from the pathname pointed to by
|
||||
file_name, an absolute pathname that names the same file, whose resolution
|
||||
does not involve '.', '..', or symbolic links. The generated pathname shall
|
||||
be stored as a null-terminated string, up to a maximum of {PATH_MAX} bytes,
|
||||
in the buffer pointed to by resolved_name.
|
||||
|
||||
If resolved_name is a null pointer, the behavior of realpath() is
|
||||
implementation-defined.
|
||||
|
||||
@param[in] file_name The filename to convert.
|
||||
@param[in,out] resolved_name The resultant name.
|
||||
|
||||
@retval NULL An error occured.
|
||||
@return resolved_name.
|
||||
**/
|
||||
char *
|
||||
realpath(
|
||||
char *file_name,
|
||||
char *resolved_name
|
||||
)
|
||||
{
|
||||
CHAR16 *Temp;
|
||||
if (file_name == NULL || resolved_name == NULL) {
|
||||
errno = EINVAL;
|
||||
return (NULL);
|
||||
}
|
||||
Temp = AllocateZeroPool((1+AsciiStrLen(file_name))*sizeof(CHAR16));
|
||||
if (Temp == NULL) {
|
||||
errno = ENOMEM;
|
||||
return (NULL);
|
||||
}
|
||||
AsciiStrToUnicodeStr(file_name, Temp);
|
||||
PathCleanUpDirectories(Temp);
|
||||
UnicodeStrToAsciiStr(Temp, resolved_name);
|
||||
return (resolved_name);
|
||||
}
|
64
StdLib/LibC/StdLib/setprogname.c
Normal file
64
StdLib/LibC/StdLib/setprogname.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/** @file setprogname and getprogname
|
||||
|
||||
$NetBSD: setprogname.c,v 1.5 2008/04/28 20:24:12 martin Exp $
|
||||
|
||||
Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
* Copyright (c) 2001 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Todd Vierling.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <LibConfig.h>
|
||||
|
||||
#ifndef HAVE_SETPROGNAME
|
||||
#include <string.h>
|
||||
|
||||
static const char *__progname = NULL;
|
||||
|
||||
void
|
||||
setprogname(const char *progname)
|
||||
{
|
||||
__progname = strrchr(progname, '/');
|
||||
if (__progname == NULL)
|
||||
__progname = progname;
|
||||
else
|
||||
__progname++;
|
||||
}
|
||||
|
||||
const char *
|
||||
getprogname(void)
|
||||
{
|
||||
return __progname;
|
||||
}
|
||||
|
||||
#endif
|
@@ -48,6 +48,8 @@ __RCSID("$NetBSD: strtoumax.c,v 1.1 2006/04/22 15:33:33 thorpej Exp $");
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <Library/BaseLib.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(strtoumax, _strtoumax)
|
||||
#endif
|
||||
@@ -98,8 +100,8 @@ strtoumax(const char *nptr, char **endptr, int base)
|
||||
if (base == 0)
|
||||
base = c == '0' ? 8 : 10;
|
||||
|
||||
cutoff = UINTMAX_MAX / (uintmax_t)base;
|
||||
cutlim = (int)(UINTMAX_MAX % (uintmax_t)base);
|
||||
cutoff = DivU64x32 ((UINT64) UINTMAX_MAX, (UINT32) base);
|
||||
cutlim = (int) ModU64x32 ((UINT64) UINTMAX_MAX, (UINT32) base);
|
||||
for (acc = 0, any = 0;; c = (unsigned char) *s++) {
|
||||
if (isdigit(c))
|
||||
c -= '0';
|
||||
|
Reference in New Issue
Block a user