]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add device abstraction code for the UEFI Console and UEFI Shell-based file systems.
authordarylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 28 Jun 2011 02:34:10 +0000 (02:34 +0000)
committerdarylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 28 Jun 2011 02:34:10 +0000 (02:34 +0000)
Make argv use narrow characters instead of wide characters.
Add setenv functionality.
Add poll() system call.
Change signal names into macros – required for standards compliance.  The enums were renamed and moved to sys/signal.h and the new macros reference the enums.
Added SIGBREAK, which is required for Python.
Modify stdio functions to fail cleanly when called with a NULL File Pointer argument.
Added <sys/cdefs.h> that just includes <sys/EfiCdefs.h>.  By adding this wrapper, we improve compatibility with *nix files which assume <sys/cdefs> exists.
Add <netdb.h>
Added macros for bcopy(), bcmp() and strsep().
Modify the clock() function so that it does not hang when running under an emulation environment such as NT32.
Move TM structure specific macros from the private tzfile.h into <time.h>
Add strncasecmp function.
Add strptime function.
Add gettimeofday function.
Add getcwd function.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11908 6f19259b-4bc3-4df7-8a09-765794883524

98 files changed:
StdLib/Include/netdb.h [new file with mode: 0644]
StdLib/Include/netinet6/in6.h
StdLib/Include/paths.h
StdLib/Include/signal.h
StdLib/Include/stdio.h
StdLib/Include/stdlib.h
StdLib/Include/string.h
StdLib/Include/sys/EfiSysCall.h
StdLib/Include/sys/ansi.h
StdLib/Include/sys/cdefs.h [new file with mode: 0644]
StdLib/Include/sys/cdefs_aout.h
StdLib/Include/sys/dirent.h
StdLib/Include/sys/fcntl.h
StdLib/Include/sys/ioctl.h [new file with mode: 0644]
StdLib/Include/sys/poll.h [new file with mode: 0644]
StdLib/Include/sys/signal.h
StdLib/Include/sys/socket.h
StdLib/Include/sys/stat.h
StdLib/Include/sys/syslimits.h
StdLib/Include/sys/time.h
StdLib/Include/sys/types.h
StdLib/Include/sys/uio.h
StdLib/Include/sys/unistd.h [new file with mode: 0644]
StdLib/Include/time.h
StdLib/Include/unistd.h [new file with mode: 0644]
StdLib/Include/wchar.h
StdLib/Include/wctype.h
StdLib/LibC/CRT/Gcc.c
StdLib/LibC/LibC.inf
StdLib/LibC/Main/Main.c
StdLib/LibC/StdLib/Environs.c
StdLib/LibC/Stdio/Stdio.inf
StdLib/LibC/Stdio/clrerr.c
StdLib/LibC/Stdio/fclose.c
StdLib/LibC/Stdio/feof.c
StdLib/LibC/Stdio/ferror.c
StdLib/LibC/Stdio/fflush.c
StdLib/LibC/Stdio/fgetc.c
StdLib/LibC/Stdio/fgetpos.c
StdLib/LibC/Stdio/fgets.c
StdLib/LibC/Stdio/fgetstr.c
StdLib/LibC/Stdio/fgetwc.c
StdLib/LibC/Stdio/fgetws.c
StdLib/LibC/Stdio/fileno.c
StdLib/LibC/Stdio/fparseln.c
StdLib/LibC/Stdio/fprintf.c
StdLib/LibC/Stdio/fpurge.c
StdLib/LibC/Stdio/fputc.c
StdLib/LibC/Stdio/fputs.c
StdLib/LibC/Stdio/fputwc.c
StdLib/LibC/Stdio/fputws.c
StdLib/LibC/Stdio/fread.c
StdLib/LibC/Stdio/freopen.c
StdLib/LibC/Stdio/fseeko.c
StdLib/LibC/Stdio/fvwrite.c
StdLib/LibC/Stdio/fwide.c
StdLib/LibC/Stdio/fwrite.c
StdLib/LibC/Stdio/getc.c
StdLib/LibC/Stdio/makebuf.c
StdLib/LibC/Stdio/putc.c
StdLib/LibC/Stdio/refill.c
StdLib/LibC/Stdio/rewind.c
StdLib/LibC/Stdio/rget.c
StdLib/LibC/Stdio/setvbuf.c
StdLib/LibC/Stdio/stdio.c
StdLib/LibC/Stdio/tmpfile.c
StdLib/LibC/Stdio/ungetc.c
StdLib/LibC/Stdio/vfscanf.c
StdLib/LibC/Stdio/vfwprintf.c
StdLib/LibC/Stdio/vsnprintf.c
StdLib/LibC/Stdio/wbuf.c
StdLib/LibC/Stdio/wsetup.c
StdLib/LibC/String/Copying.c
StdLib/LibC/String/String.inf
StdLib/LibC/String/strncasecmp.c [new file with mode: 0644]
StdLib/LibC/Time/Time.c
StdLib/LibC/Time/Time.inf
StdLib/LibC/Time/gettimeofday.c [new file with mode: 0644]
StdLib/LibC/Time/strftime.c
StdLib/LibC/Time/strptime.c [new file with mode: 0644]
StdLib/LibC/Time/tzfile.h
StdLib/LibC/Uefi/Console.c [deleted file]
StdLib/LibC/Uefi/Devices/Console/daConsole.c [new file with mode: 0644]
StdLib/LibC/Uefi/Devices/UefiShell/daShell.c [new file with mode: 0644]
StdLib/LibC/Uefi/Devices/Utility/DevGenisis.c [new file with mode: 0644]
StdLib/LibC/Uefi/Devices/Utility/DevSearch.c [new file with mode: 0644]
StdLib/LibC/Uefi/Devices/Utility/Path.c [new file with mode: 0644]
StdLib/LibC/Uefi/Devices/daConsole.inf [new file with mode: 0644]
StdLib/LibC/Uefi/Devices/daShell.inf [new file with mode: 0644]
StdLib/LibC/Uefi/Devices/daUtility.inf [new file with mode: 0644]
StdLib/LibC/Uefi/SysCalls.c
StdLib/LibC/Uefi/SysEfi.h [deleted file]
StdLib/LibC/Uefi/Uefi.inf
StdLib/LibC/Uefi/Xform.c
StdLib/LibC/Wchar/ConsDecons.c
StdLib/LibC/Wchar/Searching.c
StdLib/LibC/Wchar/Wchar.inf
StdLib/StdLib.dsc

diff --git a/StdLib/Include/netdb.h b/StdLib/Include/netdb.h
new file mode 100644 (file)
index 0000000..e645f77
--- /dev/null
@@ -0,0 +1,362 @@
+/*     $NetBSD: netdb.h,v 1.55.2.1 2007/05/17 21:25:10 jdc Exp $       */\r
+\r
+/*\r
+ * Copyright (c) 1980, 1983, 1988, 1993\r
+ *     The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * -\r
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.\r
+ *\r
+ * Permission to use, copy, modify, and distribute this software for any\r
+ * purpose with or without fee is hereby granted, provided that the above\r
+ * copyright notice and this permission notice appear in all copies, and that\r
+ * the name of Digital Equipment Corporation not be used in advertising or\r
+ * publicity pertaining to distribution of the document or software without\r
+ * specific, written prior permission.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL\r
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES\r
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT\r
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL\r
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR\r
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\r
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\r
+ * SOFTWARE.\r
+ * -\r
+ * Portions Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *    This product includes software developed by WIDE Project and\r
+ *    its contributors.\r
+ * 4. Neither the name of the project nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ * -\r
+ * --Copyright--\r
+ */\r
+\r
+/*\r
+ *      @(#)netdb.h    8.1 (Berkeley) 6/2/93\r
+ *     Id: netdb.h,v 1.15.18.6 2006/10/02 01:23:09 marka Exp\r
+ */\r
+\r
+#ifndef _NETDB_H_\r
+#define        _NETDB_H_\r
+\r
+#include <machine/ansi.h>\r
+#include <machine/endian_machdep.h>\r
+#include <sys/ansi.h>\r
+#include <sys/cdefs.h>\r
+#include <sys/featuretest.h>\r
+#include <inttypes.h>\r
+/*\r
+ * Data types\r
+ */\r
+#ifndef socklen_t\r
+typedef __socklen_t    socklen_t;\r
+#define        socklen_t       __socklen_t\r
+#endif\r
+\r
+#ifdef _EFI_SIZE_T_\r
+  typedef _EFI_SIZE_T_  size_t;\r
+  #undef _EFI_SIZE_T_\r
+  #undef _BSD_SIZE_T_\r
+#endif\r
+\r
+////#if defined(_NETBSD_SOURCE)\r
+////#ifndef _PATH_HEQUIV\r
+////#define    _PATH_HEQUIV    "/etc/hosts.equiv"\r
+////#endif\r
+#ifndef _PATH_HOSTS\r
+#define        _PATH_HOSTS     "/etc/hosts"\r
+#endif\r
+#ifndef _PATH_NETWORKS\r
+#define        _PATH_NETWORKS  "/etc/networks"\r
+#endif\r
+#ifndef _PATH_PROTOCOLS\r
+#define        _PATH_PROTOCOLS "/etc/protocols"\r
+#endif\r
+#ifndef _PATH_SERVICES\r
+#define        _PATH_SERVICES  "/etc/services"\r
+#endif\r
+////#ifndef _PATH_SERVICES_DB\r
+////#define    _PATH_SERVICES_DB "/var/db/services.db"\r
+////#endif\r
+////#endif\r
+\r
+__BEGIN_DECLS\r
+extern int h_errno;\r
+__END_DECLS\r
+\r
+/*%\r
+ * Structures returned by network data base library.  All addresses are\r
+ * supplied in host order, and returned in network order (suitable for\r
+ * use in system calls).\r
+ */\r
+struct hostent {\r
+       char    *h_name;        /*%< official name of host */\r
+       char    **h_aliases;    /*%< alias list */\r
+       int     h_addrtype;     /*%< host address type */\r
+       int     h_length;       /*%< length of address */\r
+       char    **h_addr_list;  /*%< list of addresses from name server */\r
+#define        h_addr  h_addr_list[0]  /*%< address, for backward compatiblity */\r
+};\r
+\r
+/*%\r
+ * Assumption here is that a network number\r
+ * fits in an unsigned long -- probably a poor one.\r
+ */\r
+struct netent {\r
+       char            *n_name;        /*%< official name of net */\r
+       char            **n_aliases;    /*%< alias list */\r
+       int             n_addrtype;     /*%< net address type */\r
+#if (defined(__sparc__) && defined(_LP64)) || \\r
+    (defined(__sh__) && defined(_LP64) && (_BYTE_ORDER == _BIG_ENDIAN))\r
+       int             __n_pad0;       /* ABI compatibility */\r
+#endif\r
+       uint32_t        n_net;          /*%< network # */\r
+#if defined(__alpha__) || (defined(__i386__) && defined(_LP64)) || \\r
+    (defined(__sh__) && defined(_LP64) && (_BYTE_ORDER == _LITTLE_ENDIAN))\r
+       int             __n_pad0;       /* ABI compatibility */\r
+#endif\r
+};\r
+\r
+struct servent {\r
+       char    *s_name;        /*%< official service name */\r
+       char    **s_aliases;    /*%< alias list */\r
+       int     s_port;         /*%< port # */\r
+       char    *s_proto;       /*%< protocol to use */\r
+};\r
+\r
+struct protoent {\r
+       char    *p_name;        /*%< official protocol name */\r
+       char    **p_aliases;    /*%< alias list */\r
+       int     p_proto;        /*%< protocol # */\r
+};\r
+\r
+/*\r
+ * Note: ai_addrlen used to be a size_t, per RFC 2553.\r
+ * In XNS5.2, and subsequently in POSIX-2001 and\r
+ * draft-ietf-ipngwg-rfc2553bis-02.txt it was changed to a socklen_t.\r
+ * To accommodate for this while preserving binary compatibility with the\r
+ * old interface, we prepend or append 32 bits of padding, depending on\r
+ * the (LP64) architecture's endianness.\r
+ *\r
+ * This should be deleted the next time the libc major number is\r
+ * incremented.\r
+ */\r
+#if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \\r
+    defined(_NETBSD_SOURCE)\r
+struct addrinfo {\r
+       int             ai_flags;       /*%< AI_PASSIVE, AI_CANONNAME */\r
+       int             ai_family;      /*%< PF_xxx */\r
+       int             ai_socktype;    /*%< SOCK_xxx */\r
+       int             ai_protocol;    /*%< 0 or IPPROTO_xxx for IPv4 and IPv6 */\r
+#if defined(__sparc__) && defined(_LP64)\r
+       int             __ai_pad0;      /* ABI compatibility */\r
+#endif\r
+       socklen_t        ai_addrlen;    /*%< length of ai_addr */\r
+#if defined(__alpha__) || (defined(__i386__) && defined(_LP64))\r
+       int             __ai_pad0;      /* ABI compatibility */\r
+#endif\r
+       char            *ai_canonname;  /*%< canonical name for hostname */\r
+       struct sockaddr *ai_addr;       /*%< binary address */\r
+       struct addrinfo *ai_next;       /*%< next structure in linked list */\r
+};\r
+#endif\r
+\r
+/*%\r
+ * Error return codes from gethostbyname() and gethostbyaddr()\r
+ * (left in extern int h_errno).\r
+ */\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+#define        NETDB_INTERNAL  -1      /*%< see errno */\r
+#define        NETDB_SUCCESS   0       /*%< no problem */\r
+#endif\r
+////#define    NO_ADDRESS      NO_DATA         /* no address, look for MX record */\r
+#define        HOST_NOT_FOUND  1 /*%< Authoritative Answer Host not found */\r
+#define        TRY_AGAIN       2 /*%< Non-Authoritive Host not found, or SERVERFAIL */\r
+#define        NO_RECOVERY     3 /*%< Non recoverable errors, FORMERR, REFUSED, NOTIMP */\r
+////#define    NO_DATA         4 /*%< Valid name, no data record of requested type */\r
+////#if defined(_NETBSD_SOURCE)\r
+////#define    NO_ADDRESS      NO_DATA         /*%< no address, look for MX record */\r
+////#endif\r
+\r
+/*\r
+ * Error return codes from getaddrinfo()\r
+ */\r
+#if 0  //  Not supported by UEFI\r
+#if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \\r
+    defined(_NETBSD_SOURCE)\r
+#define        EAI_ADDRFAMILY   1      /*%< address family for hostname not supported */\r
+#define        EAI_AGAIN        2      /*%< temporary failure in name resolution */\r
+#define        EAI_BADFLAGS     3      /*%< invalid value for ai_flags */\r
+#define        EAI_FAIL         4      /*%< non-recoverable failure in name resolution */\r
+#define        EAI_FAMILY       5      /*%< ai_family not supported */\r
+#define        EAI_MEMORY       6      /*%< memory allocation failure */\r
+#define        EAI_NODATA       7      /*%< no address associated with hostname */\r
+#define        EAI_NONAME       8      /*%< hostname nor servname provided, or not known */\r
+#define        EAI_SERVICE      9      /*%< servname not supported for ai_socktype */\r
+#define        EAI_SOCKTYPE    10      /*%< ai_socktype not supported */\r
+#define        EAI_SYSTEM      11      /*%< system error returned in errno */\r
+#define        EAI_BADHINTS    12      /* invalid value for hints */\r
+#define        EAI_PROTOCOL    13      /* resolved protocol is unknown */\r
+#define        EAI_OVERFLOW    14      /* argument buffer overflow */\r
+#define        EAI_MAX         15\r
+#endif /* _POSIX_C_SOURCE >= 200112 || _XOPEN_SOURCE >= 520 || _NETBSD_SOURCE */\r
+#endif  // 0  Not supported by UEFI\r
+\r
+/*%\r
+ * Flag values for getaddrinfo()\r
+ */\r
+#if 0  //  Not supported by UEFI\r
+#if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \\r
+    defined(_NETBSD_SOURCE)\r
+#define        AI_PASSIVE      0x00000001 /* get address to use bind() */\r
+#endif\r
+#endif  // 0  Not supported by UEFI\r
+\r
+#define AI_CANONNAME  0x00000002 /* fill ai_canonname */\r
+\r
+#if 0  //  Not supported by UEFI\r
+#if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \\r
+    defined(_NETBSD_SOURCE)\r
+#define        AI_NUMERICHOST  0x00000004 /* prevent host name resolution */\r
+#define        AI_NUMERICSERV  0x00000008 /* prevent service name resolution */\r
+/* valid flags for addrinfo (not a standard def, apps should not use it) */\r
+#define        AI_MASK \\r
+    (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV)\r
+#endif\r
+#endif  // 0  Not supported by UEFI\r
+\r
+/*%\r
+ * Constants for getnameinfo()\r
+ */\r
+////#if defined(_NETBSD_SOURCE)\r
+#define        NI_MAXHOST      1025\r
+#define        NI_MAXSERV      32\r
+////#endif\r
+\r
+/*%\r
+ * Flag values for getnameinfo()\r
+ */\r
+////#define    NI_NOFQDN       0x00000001\r
+#define NI_NUMERICHOST  0x00000002\r
+////#define    NI_NAMEREQD     0x00000004\r
+#define NI_NUMERICSERV  0x00000008\r
+////#define    NI_DGRAM        0x00000010\r
+////#define    NI_NUMERICSCOPE 0x00000040\r
+\r
+#if 0  //  Not supported by UEFI\r
+#if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \\r
+    defined(_NETBSD_SOURCE)\r
+/*%\r
+ * Scope delimit character\r
+ */\r
+#if defined(_NETBSD_SOURCE)\r
+#define        SCOPE_DELIMITER '%'\r
+#endif\r
+#endif /* (_POSIX_C_SOURCE - 0) >= 200112L || ... */\r
+#endif  // 0  Not supported by UEFI\r
+\r
+__BEGIN_DECLS\r
+void           endhostent(void);\r
+void           endnetent(void);\r
+void           endprotoent(void);\r
+void           endservent(void);\r
+#if 0  //  Not supported by UEFI\r
+#if (_XOPEN_SOURCE - 0) >= 520 && (_XOPEN_SOURCE - 0) < 600 || \\r
+    defined(_NETBSD_SOURCE)\r
+#if 0 /* we do not ship this */\r
+void           freehostent(struct hostent *);\r
+#endif\r
+#endif\r
+#endif  // 0  Not supported by UEFI\r
+struct hostent *gethostbyaddr(const char *, socklen_t, int);\r
+struct hostent *gethostbyname(const char *);\r
+#if defined(_NETBSD_SOURCE)\r
+struct hostent *gethostbyname2(const char *, int);\r
+#endif\r
+struct hostent *gethostent(void);\r
+struct netent  *getnetbyaddr(uint32_t, int);\r
+struct netent  *getnetbyname(const char *);\r
+struct netent  *getnetent(void);\r
+struct protoent        *getprotobyname(const char *);\r
+struct protoent        *getprotobynumber(int);\r
+struct protoent        *getprotoent(void);\r
+struct servent *getservbyname(const char *, const char *);\r
+struct servent *getservbyport(int, const char *);\r
+struct servent *getservent(void);\r
+////#if defined(_NETBSD_SOURCE)\r
+////void               herror(const char *);\r
+////const char *hstrerror(int);\r
+////#endif\r
+void           sethostent(int);\r
+////#if defined(_NETBSD_SOURCE)\r
+/* void                sethostfile(const char *); */\r
+////#endif\r
+void           setnetent(int);\r
+void           setprotoent(int);\r
+#if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \\r
+    defined(_NETBSD_SOURCE)\r
+void           setservent(int);\r
+int            getaddrinfo(const char * __restrict, const char * __restrict,\r
+                                const struct addrinfo * __restrict,\r
+                                struct addrinfo ** __restrict);\r
+int            getnameinfo(const struct sockaddr * __restrict, socklen_t,\r
+                                char * __restrict, socklen_t,\r
+                                char * __restrict, socklen_t, int);\r
+void           freeaddrinfo(struct addrinfo *);\r
+const char     *gai_strerror(int);\r
+#endif\r
+void           setservent(int);\r
+\r
+__END_DECLS\r
+\r
+#endif /* !_NETDB_H_ */\r
index 7e81bb70848fa579ca4fae074b99be91f60d78a3..f9a645aef14e9b88d3f9252aef06856401efacb5 100644 (file)
@@ -736,9 +736,10 @@ extern  u_char  ip6_protox[];
 \r
 #include <machine/ansi.h>\r
 \r
-#ifdef  _BSD_SIZE_T_\r
-typedef _BSD_SIZE_T_    size_t;\r
+#ifdef  _EFI_SIZE_T_\r
+typedef _EFI_SIZE_T_    size_t;\r
 #define _SIZE_T\r
+#undef  _EFI_SIZE_T_\r
 #undef  _BSD_SIZE_T_\r
 #endif\r
 \r
index 44c1dd1eceff4228825eb702682369c75340dd89..389272f0d9e820ac0be9c4cce4b5251b9ed6f0b2 100644 (file)
 //#define _PATH_AUDIOCTL0 "/dev/audioctl0"\r
 //#define _PATH_BPF "/dev/bpf"\r
 //#define _PATH_CLOCKCTL  "/dev/clockctl"\r
-#define _PATH_CONSOLE "console:"\r
-#define _PATH_CONSTTY "constty:"\r
 //#define _PATH_CSMAPPER  "/usr/share/i18n/csmapper"\r
 //#define _PATH_DEFTAPE "/dev/nrst0"\r
 //#define _PATH_DEVDB "/var/run/dev.db"\r
-#define _PATH_DEVNULL "null:"\r
 //#define _PATH_DRUM  "/dev/drum"\r
 //#define _PATH_ESDB  "/usr/share/i18n/esdb"\r
 //#define _PATH_FTPUSERS  "/etc/ftpusers"\r
@@ -72,7 +69,6 @@
 //#define _PATH_KMEM  "/dev/kmem"\r
 //#define _PATH_KSYMS "/dev/ksyms"\r
 //#define _PATH_KVMDB "/var/db/kvm.db"\r
-#define _PATH_LOCALE  "/Efi/Locale"\r
 //#define _PATH_MAILDIR "/var/mail"\r
 //#define _PATH_MAN "/usr/share/man"\r
 //#define _PATH_MEM "/dev/mem"\r
 //#define _PATH_SOUND "/dev/sound"\r
 //#define _PATH_SOUND0  "/dev/sound0"\r
 //#define _PATH_SYSMON  "/dev/sysmon"\r
-#define _PATH_TTY "tty:"\r
 //#define _PATH_UNIX  "/netbsd"\r
 //#define _PATH_URANDOM "/dev/urandom"\r
 //#define _PATH_VI  "/usr/bin/vi"\r
+\r
+// DOS style device paths\r
+#define _PATH_TTYDEV "tty:"\r
+#define _PATH_NULLDEV "null:"\r
+#define _PATH_CONSOLE "console:"\r
+#define _PATH_CONSTTY "constty:"\r
 #define _PATH_STDIN   "stdin:"\r
 #define _PATH_STDOUT  "stdout:"\r
 #define _PATH_STDERR  "stderr:"\r
+#define _PATH_SOCKET  "socket:"\r
+\r
+// *nix style device paths\r
+#define _PATH_DEVTTY      "/dev/tty"\r
+#define _PATH_DEVNULL     "/dev/null"\r
+#define _PATH_DEVCONSOLE  "/dev/console"\r
+#define _PATH_DEVCONSTTY  "/dev/constty"\r
+#define _PATH_DEVSTDIN    "/dev/stdin"\r
+#define _PATH_DEVSTDOUT   "/dev/stdout"\r
+#define _PATH_DEVSTDERR   "/dev/stderr"\r
+#define _PATH_DEVSOCKET   "/dev/socket"\r
+\r
+// Special files and locations\r
+#define _PATH_HOSTS       "/Efi/etc/hosts"\r
+#define _PATH_SERVICES    "/Efi/etc/services"\r
+#define _PATH_HOSTNAME    "/Efi/etc/hostname"\r
+#define _PATH_LOCALE      "/Efi/etc/Locale"\r
+#define _PATH_FSTAB       "/Efi/etc/fstab"\r
 \r
 /*\r
  * Provide trailing slash, since mostly used for building pathnames.\r
  * see the __CONCAT() macro from <sys/EfiCdefs.h> for cpp examples.\r
  */\r
-//#define _PATH_DEV "/dev/"\r
+#define _PATH_DEV "/dev/"\r
+#define _PATH_TMP "/Efi/Temp/"\r
 //#define _PATH_DEV_PTS "/dev/pts/"\r
 //#define _PATH_EMUL_AOUT "/emul/aout/"\r
-#define _PATH_TMP "/Efi/Temp/"\r
 //#define _PATH_VARDB "/var/db/"\r
 //#define _PATH_VARRUN  "/var/run/"\r
 //#define _PATH_VARTMP  "/var/tmp/"\r
 \r
-//#ifdef RESCUEDIR\r
 //#define _PATH_BSHELL  RESCUEDIR "/sh"\r
 //#define _PATH_CSHELL  RESCUEDIR "/csh"\r
-//#else\r
-//#define _PATH_BSHELL  "/bin/sh"\r
-//#define _PATH_CSHELL  "/bin/csh"\r
-//#endif\r
 \r
 #endif /* !_PATHS_H_ */\r
 \r
index 52873c764d6a8c9494f7135fcc7e3563046918a0..a84369f31059263d10b17addf5d052d5b905cd64 100644 (file)
@@ -50,13 +50,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     corresponding to the specified condition.\r
     Many existing programs expect these to be macros.\r
 **/\r
-#define SIGINT    1   ///< receipt of an interactive attention signal\r
-#define SIGILL    2   ///< detection of an invalid function image, such as an invalid instruction\r
-#define SIGABRT   3   ///< abnormal termination, such as is initiated by the abort function\r
-#define SIGFPE    4   ///< an erroneous arithmetic operation, such as zero divide or an operation resulting in overflow\r
-#define SIGSEGV   5   ///< an invalid access to storage\r
-#define SIGTERM   6   ///< a termination request sent to the program\r
-#define SIG_LAST  7   ///< One more than the largest signal number\r
+#define SIGINT     __SigInt     ///< receipt of an interactive attention signal\r
+#define SIGILL     __SigIll     ///< detection of an invalid function image, such as an invalid instruction\r
+#define SIGABRT    __SigAbrt    ///< abnormal termination, such as is initiated by the abort function\r
+#define SIGFPE     __SigFpe     ///< an erroneous arithmetic operation, such as zero divide or an operation resulting in overflow\r
+#define SIGSEGV    __SigSegv    ///< an invalid access to storage\r
+#define SIGTERM    __SigTerm    ///< a termination request sent to the program\r
+#define SIGBREAK   __SigBreak   ///< added for Python\r
+#define SIG_LAST   __Sig_Last   ///< One more than the largest signal number\r
 \r
 __BEGIN_DECLS\r
 \r
index d6eadf513c5873d2cbb402884178f126a33b5749..7a60a290acb905cc2676e1be0ae4cec6f4e483c7 100644 (file)
@@ -44,6 +44,7 @@
 #ifdef _EFI_SIZE_T_\r
   typedef _EFI_SIZE_T_  size_t;\r
   #undef _EFI_SIZE_T_\r
+  #undef _BSD_SIZE_T_\r
 #endif\r
 \r
 /*\r
index 2b19fd224b0b8db92bfa11d4bd744a26574aaaaa..2cfc9fe1ff2731bd977cd4771eadb53b78021d47 100644 (file)
@@ -2,7 +2,7 @@
   The header <stdlib.h> declares five types and several functions of general\r
   utility, and defines several macros.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials are licensed and made available under\r
   the terms and conditions of the BSD License that accompanies this distribution.\r
   The full text of the license may be found at\r
@@ -133,10 +133,14 @@ void    exit(int status) __noreturn;
     buffered data are not flushed, open streams are not closed, and temporary\r
     files are not removed by abort.\r
 \r
+    While this function does not return, it can NOT be marked as "__noreturn"\r
+    without causing a warning to be emitted because the compilers can not\r
+    determine that the function truly does not return.\r
+\r
     The status returned to the host environment is determined in the same way\r
     as for the exit function.\r
 **/\r
-void    _Exit(int status) __noreturn;\r
+void    _Exit(int status);\r
 \r
 /** The getenv function searches an environment list, provided by the host\r
     environment, for a string that matches the string pointed to by name.  The\r
@@ -151,6 +155,24 @@ void    _Exit(int status) __noreturn;
 **/\r
 char   *getenv(const char *name);\r
 \r
+/**\r
+  Add or update a variable in the environment list\r
+\r
+  @param name     Address of a zero terminated name string\r
+  @param value    Address of a zero terminated value string\r
+  @param rewrite  TRUE allows overwriting existing values\r
+\r
+  @retval Returns 0 upon success\r
+  @retval Returns -1 upon failure, sets errno with more information\r
+\r
+**/\r
+int\r
+setenv (\r
+  register const char * name,\r
+  register const char * value,\r
+  int rewrite\r
+  );\r
+\r
 /** If string is a null pointer, the system function determines whether the\r
     host environment has a command processor. If string is not a null pointer,\r
     the system function passes the string pointed to by string to that command\r
@@ -499,37 +521,125 @@ void qsort( void *base, size_t nmemb, size_t size,
 \r
 /* ################  Multibyte/wide character conversion functions  ####### */\r
 \r
-/**\r
+/** Determine the number of bytes comprising a multibyte character.\r
 \r
-  @return\r
+  If s is not a null pointer, the mblen function determines the number of bytes\r
+  contained in the multibyte character pointed to by s. Except that the\r
+  conversion state of the mbtowc function is not affected, it is equivalent to\r
+    mbtowc((wchar_t *)0, s, n);\r
+\r
+  The implementation shall behave as if no library function calls the mblen\r
+  function.\r
+\r
+  @return   If s is a null pointer, the mblen function returns a nonzero or\r
+            zero value, if multibyte character encodings, respectively, do\r
+            or do not have state-dependent encodings. If s is not a null\r
+            pointer, the mblen function either returns 0 (if s points to the\r
+            null character), or returns the number of bytes that are contained\r
+            in the multibyte character (if the next n or fewer bytes form a\r
+            valid multibyte character), or returns -1 (if they do not form a\r
+            valid multibyte character).\r
 **/\r
 int     mblen(const char *, size_t);\r
 \r
-/**\r
+/** Convert a multibyte character into a wide character.\r
 \r
-  @return\r
+    If s is not a null pointer, the mbtowc function inspects at most n bytes\r
+    beginning with the byte pointed to by s to determine the number of bytes\r
+    needed to complete the next multibyte character (including any shift\r
+    sequences). If the function determines that the next multibyte character\r
+    is complete and valid, it determines the value of the corresponding wide\r
+    character and then, if pwc is not a null pointer, stores that value in\r
+    the object pointed to by pwc. If the corresponding wide character is the\r
+    null wide character, the function is left in the initial conversion state.\r
+\r
+    The implementation shall behave as if no library function calls the\r
+    mbtowc function.\r
+\r
+    @return   If s is a null pointer, the mbtowc function returns a nonzero or\r
+              zero value, if multibyte character encodings, respectively, do\r
+              or do not have state-dependent encodings. If s is not a null\r
+              pointer, the mbtowc function either returns 0 (if s points to\r
+              the null character), or returns the number of bytes that are\r
+              contained in the converted multibyte character (if the next n or\r
+              fewer bytes form a valid multibyte character), or returns -1\r
+              (if they do not form a valid multibyte character).\r
+\r
+              In no case will the value returned be greater than n or the value\r
+              of the MB_CUR_MAX macro.\r
 **/\r
 int     mbtowc(wchar_t * __restrict, const char * __restrict, size_t);\r
 \r
 /**\r
+The wctomb function determines the number of bytes needed to represent the multibyte\r
+character corresponding to the wide character given by wc (including any shift\r
+sequences), and stores the multibyte character representation in the array whose first\r
+element is pointed to by s (if s is not a null pointer). At most MB_CUR_MAX characters\r
+are stored. If wc is a null wide character, a null byte is stored, preceded by any shift\r
+sequence needed to restore the initial shift state, and the function is left in the initial\r
+conversion state.\r
+\r
+The implementation shall behave as if no library function calls the wctomb function.\r
 \r
   @return\r
+If s is a null pointer, the wctomb function returns a nonzero or zero value, if multibyte\r
+character encodings, respectively, do or do not have state-dependent encodings. If s is\r
+not a null pointer, the wctomb function returns -1 if the value of wc does not correspond\r
+to a valid multibyte character, or returns the number of bytes that are contained in the\r
+multibyte character corresponding to the value of wc.\r
+\r
+In no case will the value returned be greater than the value of the MB_CUR_MAX macro.\r
+\r
 **/\r
 int     wctomb(char *, wchar_t);\r
 \r
 /* ################  Multibyte/wide string conversion functions  ########## */\r
 \r
-/**\r
+/** Convert a multibyte character string into a wide-character string.\r
+\r
+    The mbstowcs function converts a sequence of multibyte characters that\r
+    begins in the initial shift state from the array pointed to by src into\r
+    a sequence of corresponding wide characters and stores not more than limit\r
+    wide characters into the array pointed to by dest.  No multibyte\r
+    characters that follow a null character (which is converted into a null\r
+    wide character) will be examined or converted. Each multibyte character\r
+    is converted as if by a call to the mbtowc function, except that the\r
+    conversion state of the mbtowc function is not affected.\r
+\r
+    No more than limit elements will be modified in the array pointed to by dest.\r
+    If copying takes place between objects that overlap,\r
+    the behavior is undefined.\r
+\r
+  @return   If an invalid multibyte character is encountered, the mbstowcs\r
+            function returns (size_t)(-1). Otherwise, the mbstowcs function\r
+            returns the number of array elements modified, not including a\r
+            terminating null wide character, if any.\r
 \r
-  @return\r
 **/\r
-size_t  mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);\r
+size_t  mbstowcs(wchar_t * __restrict dest, const char * __restrict src, size_t limit);\r
 \r
-/**\r
+/** Convert a wide-character string into a multibyte character string.\r
 \r
-  @return\r
+    The wcstombs function converts a sequence of wide characters from the\r
+    array pointed to by src into a sequence of corresponding multibyte\r
+    characters that begins in the initial shift state, and stores these\r
+    multibyte characters into the array pointed to by dest, stopping if a\r
+    multibyte character would exceed the limit of limit total bytes or if a\r
+    null character is stored. Each wide character is converted as if by\r
+    a call to the wctomb function, except that the conversion state of\r
+    the wctomb function is not affected.\r
+\r
+    No more than limit bytes will be modified in the array pointed to by dest.\r
+    If copying takes place between objects that overlap,\r
+    the behavior is undefined.\r
+\r
+  @return   If a wide character is encountered that does not correspond to a\r
+            valid multibyte character, the wcstombs function returns\r
+            (size_t)(-1). Otherwise, the wcstombs function returns the number\r
+            of bytes modified, not including a terminating null character,\r
+            if any.\r
 **/\r
-size_t  wcstombs(char * __restrict, const wchar_t * __restrict, size_t);\r
+size_t  wcstombs(char * __restrict dest, const wchar_t * __restrict src, size_t limit);\r
 \r
 __END_DECLS\r
 \r
index 920d6c8dd6b2d9e2e72e845a7bbb3c31e698eb02..992ca0ba18a5d17cc3dcac7f026e1c62eb8ee438 100644 (file)
@@ -15,7 +15,7 @@
   interpreted as if it had the type unsigned char (and therefore every possible\r
   object representation is valid and has a different value).\r
 \r
-Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available under\r
 the terms and conditions of the BSD License that accompanies this distribution.\r
 The full text of the license may be found at\r
@@ -323,6 +323,16 @@ char   *strdup    (const char *);
 int     strerror_r(int, char *, size_t);\r
 int     strcasecmp(const char *s1, const char *s2);\r
 void   *memccpy   (void *, const void *, int, size_t);\r
+int     strncasecmp(const char *s1, const char *s2, size_t n);\r
+\r
+// bcopy is same as memcpy but it is a void function, being used in socket lib\r
+#define bcopy(a,b,c) ( memcpy((void *)a, (void *)b, (size_t)c))\r
+\r
+// bcmp is same as memcmp, returns 0 for successful compare, non-zero otherwise\r
+#define bcmp(a,b,c) ( memcmp((void *)a, (void *)b, (size_t)c))\r
+\r
+//strsep is the same as strtok, the only difference is for strsep the 1st parameter is a char**\r
+#define strsep(a,b) (strtok(*a,b))\r
 \r
 __END_DECLS\r
 \r
index 14ecb49890f95f27e3990e5fdb61448207c25c3c..7b299108e6e7ff616068874694f29c91bc752535 100644 (file)
@@ -3,7 +3,7 @@
 \r
   Concept derived from NetBSD's unistd.h file.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials are licensed and made available under\r
   the terms and conditions of the BSD License that accompanies this distribution.\r
   The full text of the license may be found at\r
@@ -19,7 +19,7 @@
 #include  <sys/EfiCdefs.h>\r
 #include  <sys/types.h>\r
 \r
-struct stat;  // Structure declared in <sys/stat.h>\r
+struct stat;  /* Structure declared in <sys/stat.h> */\r
 \r
 #define STDIN_FILENO  0 /* standard input file descriptor */\r
 #define STDOUT_FILENO 1 /* standard output file descriptor */\r
@@ -31,53 +31,90 @@ struct stat;  // Structure declared in <sys/stat.h>
 #define W_OK    0x02  /* test for write permission */\r
 #define R_OK    0x04  /* test for read permission */\r
 \r
-/* whence values for lseek(2) */\r
-#define SEEK_SET  0 /* set file offset to offset */\r
-#define SEEK_CUR  1 /* set file offset to current plus offset */\r
-#define SEEK_END  2 /* set file offset to EOF plus offset */\r
+/* whence values for lseek(2)\r
+   Always ensure that these are consistent with <stdio.h> and <unistd.h>!\r
+*/\r
+#ifndef SEEK_SET\r
+  #define SEEK_SET  0 /* set file offset to offset */\r
+#endif\r
+#ifndef SEEK_CUR\r
+  #define SEEK_CUR  1 /* set file offset to current plus offset */\r
+#endif\r
+#ifndef SEEK_END\r
+  #define SEEK_END  2 /* set file offset to EOF plus offset */\r
+#endif\r
+\r
+// Parameters for the ValidateFD function.\r
+#define VALID_OPEN         1\r
+#define VALID_CLOSED       0\r
+#define VALID_DONT_CARE   -1\r
 \r
 __BEGIN_DECLS\r
 \r
 /* EFI versions of BSD system calls used in stdio */\r
-extern int      close     (int fd);\r
-extern ssize_t  read      (int fd, void *buf, size_t n);\r
-extern ssize_t  write     (int fd, const void *buf, size_t n);\r
-extern int      unlink    (const char *name);\r
-extern int      dup2      (int, int);\r
-extern int      rmdir     (const char *);\r
-extern int      isatty    (int);\r
+int       close     (int fd);\r
+ssize_t   read      (int fd, void *buf, size_t n);\r
+ssize_t   write     (int fd, const void *buf, size_t n);\r
+int       unlink    (const char *name);\r
+int       dup2      (int, int);\r
+int       rmdir     (const char *);\r
+int       isatty    (int);\r
 \r
 /* These system calls are also declared in sys/fcntl.h */\r
 #ifndef __FCNTL_SYSCALLS_DECLARED\r
   #define __FCNTL_SYSCALLS_DECLARED\r
-  extern int      open      (const char *name, int oflags, int mode);\r
-  extern int      creat     (const char *, mode_t);\r
-  extern int      fcntl     (int, int, ...);\r
+  int     open      (const char *name, int oflags, int mode);\r
+  int     creat     (const char *, mode_t);\r
+  int     fcntl     (int, int, ...);\r
 #endif  // __FCNTL_SYSCALLS_DECLARED\r
 \r
 /* These system calls are also declared in stat.h */\r
 #ifndef __STAT_SYSCALLS_DECLARED\r
   #define __STAT_SYSCALLS_DECLARED\r
-  extern int      mkdir     (const char *, mode_t);\r
-  extern int      fstat     (int, struct stat *);\r
-  extern int      lstat     (const char *, struct stat *);\r
-  extern int      stat      (const char *, void *);\r
-//  extern int      chmod     (const char *, mode_t);\r
+  int     mkdir     (const char *, mode_t);\r
+  int     fstat     (int, struct stat *);\r
+  int     lstat     (const char *, struct stat *);\r
+  int     stat      (const char *, void *);\r
+//  int      chmod     (const char *, mode_t);\r
 #endif  // __STAT_SYSCALLS_DECLARED\r
 \r
 // These are also declared in sys/types.h\r
 #ifndef __OFF_T_SYSCALLS_DECLARED\r
   #define __OFF_T_SYSCALLS_DECLARED\r
-  extern off_t    lseek     (int, off_t, int);\r
-  extern int      truncate  (const char *, off_t);\r
-  extern int      ftruncate (int, off_t);   //  IEEE Std 1003.1b-93\r
+  off_t   lseek     (int, off_t, int);\r
+  int     truncate  (const char *, off_t);\r
+  int     ftruncate (int, off_t);   //  IEEE Std 1003.1b-93\r
 #endif /* __OFF_T_SYSCALLS_DECLARED */\r
 \r
+/* EFI-specific Functions. */\r
+int       DeleteOnClose(int fd);    /* Mark an open file to be deleted when closed. */\r
+\r
+/* Find and reserve a free File Descriptor.\r
+\r
+  Returns the first free File Descriptor greater than or equal to the,\r
+  already validated, fd specified by Minfd.\r
+\r
+  @return   Returns -1 if there are no free FDs.  Otherwise returns the\r
+            found fd.\r
+*/\r
+int       FindFreeFD  (int MinFd);\r
+\r
+/*  Validate that fd refers to a valid file descriptor.\r
+    IsOpen is interpreted as follows:\r
+      - Positive  fd must be OPEN\r
+      - Zero      fd must be CLOSED\r
+      - Negative  fd may be OPEN or CLOSED\r
+\r
+    @retval TRUE  fd is VALID\r
+    @retval FALSE fd is INVALID\r
+*/\r
+BOOLEAN   ValidateFD (int fd, int IsOpen);\r
+\r
 /* These system calls don't YET have EFI implementations. */\r
-extern int      access    (const char *path, int amode);\r
-extern int      chdir     (const char *);\r
-extern char    *getcwd    (char *, size_t);\r
-extern int      reboot    (int, char *);\r
+int       access    (const char *path, int amode);\r
+int       chdir     (const char *);\r
+char     *getcwd    (char *, size_t);\r
+int       reboot    (int, char *);\r
 \r
 __END_DECLS\r
 \r
index a52a9994c965c427288f70d9310492f77701dd68..4fb12987a5b26f8c85ce011c1d52278177dc571e 100644 (file)
@@ -55,7 +55,7 @@ typedef __uint32_t  __mode_t;       /* file permissions */
 typedef __int64_t   __off_t;        /* file offset */\r
 typedef __int32_t   __pid_t;        /* process id */\r
 typedef __uint8_t   __sa_family_t;  /* socket address family */\r
-typedef UINTN       __socklen_t;    /* socket-related datum length */\r
+typedef UINT32       __socklen_t;    /* socket-related datum length */\r
 typedef __uint32_t  __uid_t;        /* user id */\r
 typedef __uint64_t  __fsblkcnt_t;   /* fs block count (statvfs) */\r
 typedef __uint64_t  __fsfilcnt_t;   /* fs file count */\r
diff --git a/StdLib/Include/sys/cdefs.h b/StdLib/Include/sys/cdefs.h
new file mode 100644 (file)
index 0000000..c6e3d7b
--- /dev/null
@@ -0,0 +1,15 @@
+/** @file\r
+    Wrapper to allow existing references to <sys/cdefs.h>,\r
+    in code being ported, to work.\r
+\r
+    Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+\r
+#include  <sys/EfiCdefs.h>\r
index ce4ca0619393e63db79e72a087cc3f488c506762..c7920a02b1780428f8073b4e981cd9a9f16af42c 100644 (file)
@@ -88,7 +88,8 @@
 \r
 #undef __KERNEL_RCSID\r
 \r
-#define __RCSID(_s) __IDSTRING(rcsid,_s)\r
+//#define __RCSID(_s) __IDSTRING(rcsid,_s)\r
+#define __RCSID(_s)\r
 #define __SCCSID(_s)\r
 #define __SCCSID2(_s)\r
 #if 0 /* XXX userland __COPYRIGHTs have \ns in them */\r
index 1d5f91185feb7f08fe15f9b7d0aaa3b1d629eccd..373664d091142ece052f83b412d6ce589ac460aa 100644 (file)
@@ -4,7 +4,7 @@
   The information is based upon the EFI_FILE_INFO structure\r
   in MdePkg/Include/Guid/FileInfo.h.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -49,6 +49,7 @@
 \r
 #include  <sys/featuretest.h>\r
 #include  <time.h>\r
+#include  <sys/time.h>\r
 \r
 #define MAXNAMLEN 511\r
 \r
@@ -66,10 +67,10 @@ struct dirent {
   UINT64    PhysicalSize;       // The amount of physical space the file consumes\r
                                   // on the file system volume.\r
   UINT64    Attribute;          // The time the file was created.\r
-  timespec  CreateTime;         // The time when the file was last accessed.\r
-  timespec  LastAccessTime;     // The time when the file’s contents were last modified.\r
-  timespec  ModificationTime;   // The attribute bits for the file. See below.\r
-  CHAR16    FileName[];         // The Null-terminated name of the file.\r
+  struct timespec  CreateTime;         // The time when the file was last accessed.\r
+  struct timespec  LastAccessTime;     // The time when the file’s contents were last modified.\r
+  struct timespec  ModificationTime;   // The attribute bits for the file. See below.\r
+  CHAR16    FileName[1];         // The Null-terminated name of the file.\r
 };\r
 \r
 /*\r
index cd720c03d9116df882142ea76ac1ca9f34531030..8b691b19f8ffb1db734a05c5ae0389a170be0f06 100644 (file)
@@ -57,8 +57,7 @@
 /*\r
  * File status flags: these are used by open(2), fcntl(2).\r
  * They are also used (indirectly) in the kernel file structure f_flags,\r
- * which is a superset of the open/fcntl flags.  Open flags and f_flags\r
- * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags).\r
+ * which is a superset of the open/fcntl flags.\r
  * Open/fcntl flags begin with O_; kernel-internal flags begin with F.\r
  */\r
 /* open-only flags */\r
 /*\r
  * Kernel encoding of open mode; separate read and write bits that are\r
  * independently testable: 1 greater than the above.\r
- *\r
- * XXX\r
- * FREAD and FWRITE are excluded from the #ifdef _KERNEL so that TIOCFLUSH,\r
- * which was documented to use FREAD/FWRITE, continues to work.\r
  */\r
 #define FREAD       0x00000001\r
 #define FWRITE      0x00000002\r
diff --git a/StdLib/Include/sys/ioctl.h b/StdLib/Include/sys/ioctl.h
new file mode 100644 (file)
index 0000000..2378fd2
--- /dev/null
@@ -0,0 +1,101 @@
+/** @file\r
+  Device Control, ioctl, definitions and declarations.\r
+\r
+  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ * Copyright (c) 1982, 1986, 1990, 1993, 1994\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ * (c) UNIX System Laboratories, Inc.\r
+ * All or some portions of this file are derived from material licensed\r
+ * to the University of California by American Telephone and Telegraph\r
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with\r
+ * the permission of UNIX System Laboratories, Inc.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+\r
+  NetBSD: ioctl.h,v 1.34 2005/12/11 12:25:20 christos Exp\r
+  ioctl.h 8.6 (Berkeley) 3/28/94\r
+**/\r
+#ifndef _SYS_IOCTL_H_\r
+#define _SYS_IOCTL_H_\r
+\r
+\r
+//#include <sys/ttycom.h>\r
+\r
+/*\r
+ * Pun for SunOS prior to 3.2.  SunOS 3.2 and later support TIOCGWINSZ\r
+ * and TIOCSWINSZ (yes, even 3.2-3.5, the fact that it wasn't documented\r
+ * nonwithstanding).\r
+ */\r
+struct ttysize {\r
+  unsigned short  ts_lines;\r
+  unsigned short  ts_cols;\r
+  unsigned short  ts_xxx;\r
+  unsigned short  ts_yyy;\r
+};\r
+//#define TIOCGSIZE TIOCGWINSZ\r
+//#define TIOCSSIZE TIOCSWINSZ\r
+\r
+//#include <sys/ioccom.h>\r
+\r
+//#include <sys/dkio.h>\r
+//#include <sys/filio.h>\r
+//#include <sys/sockio.h>\r
+\r
+/*\r
+ * Passthrough ioctl commands. These are passed through to devices\r
+ * as they are, it is expected that the device (an LKM, for example),\r
+ * will know how to deal with them. One for each emulation, so that\r
+ * no namespace clashes will occur between them, for devices that\r
+ * may be dealing with specific ioctls for multiple emulations.\r
+ */\r
+\r
+struct ioctl_pt {\r
+  unsigned long com;\r
+  void *data;\r
+};\r
+\r
+#define PTIOCNETBSD   _IOW('Z', 0, struct ioctl_pt)\r
+#define PTIOCSUNOS    _IOW('Z', 1, struct ioctl_pt)\r
+#define PTIOCSVR4     _IOW('Z', 2, struct ioctl_pt)\r
+#define PTIOCLINUX    _IOW('Z', 3, struct ioctl_pt)\r
+#define PTIOCFREEBSD  _IOW('Z', 4, struct ioctl_pt)\r
+#define PTIOCOSF1     _IOW('Z', 5, struct ioctl_pt)\r
+#define PTIOCULTRIX   _IOW('Z', 6, struct ioctl_pt)\r
+#define PTIOCWIN32    _IOW('Z', 7, struct ioctl_pt)\r
+\r
+#include <sys/EfiCdefs.h>\r
+\r
+__BEGIN_DECLS\r
+int ioctl(int, unsigned long, ...);\r
+__END_DECLS\r
+#endif /* !_SYS_IOCTL_H_ */\r
diff --git a/StdLib/Include/sys/poll.h b/StdLib/Include/sys/poll.h
new file mode 100644 (file)
index 0000000..ead648d
--- /dev/null
@@ -0,0 +1,91 @@
+/** @file\r
+    Definitions in support of the poll() function.\r
+\r
+ * Copyright (c) 1998 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to The NetBSD Foundation\r
+ * by Charles M. Hannum.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. All advertising materials mentioning features or use of this software\r
+ *    must display the following acknowledgement:\r
+ *  This product includes software developed by the NetBSD\r
+ *  Foundation, Inc. and its contributors.\r
+ * 4. Neither the name of The NetBSD Foundation nor the names of its\r
+ *    contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+\r
+    Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+    NetBSD: poll.h,v 1.11 2005/12/11 12:25:20 christos Exp\r
+**/\r
+#ifndef _SYS_POLL_H_\r
+#define _SYS_POLL_H_\r
+\r
+#include <sys/featuretest.h>\r
+#include <sys/EfiCdefs.h>\r
+\r
+typedef unsigned int  nfds_t;\r
+\r
+struct pollfd {\r
+  int   fd;       /* file descriptor */\r
+  short events;   /* events to look for */\r
+  short revents;  /* events returned */\r
+};\r
+\r
+/*\r
+ * Testable events (may be specified in events field).\r
+ */\r
+#define POLLIN      0x0001\r
+#define POLLPRI     0x0002\r
+#define POLLOUT     0x0004\r
+#define POLLRDNORM  0x0040\r
+#define POLLWRNORM  POLLOUT\r
+#define POLLRDBAND  0x0080\r
+#define POLLWRBAND  0x0100\r
+\r
+/*\r
+ * Non-testable events (ignored in events field, valid in return only).\r
+ */\r
+#define POLLERR     0x0008\r
+#define POLLHUP     0x0010\r
+#define POLLNVAL    0x0020    // Invalid parameter in POLL call\r
+#define POLL_RETONLY  (POLLERR | POLLHUP | POLLNVAL)\r
+\r
+/*\r
+ * Infinite timeout value.\r
+ */\r
+#define INFTIM    -1\r
+\r
+__BEGIN_DECLS\r
+int poll(struct pollfd *, nfds_t, int);\r
+__END_DECLS\r
+\r
+#endif /* !_SYS_POLL_H_ */\r
index 8cc32f08c935fd41c21587f98281b32cffdc7ef1..e945a62bfe2f8e80e6f5b6b2b86d8f79f076f5c1 100644 (file)
@@ -14,6 +14,17 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include  <sys/EfiCdefs.h>\r
 #include  <machine/signal.h>\r
 \r
+enum {\r
+  __SigInt    = 1,\r
+  __SigIll,\r
+  __SigAbrt,\r
+  __SigFpe,\r
+  __SigSegv,\r
+  __SigTerm,\r
+  __SigBreak,\r
+  __Sig_Last\r
+};\r
+\r
 /** The type of a signal handler function. **/\r
 typedef void __sighandler_t(int);\r
 \r
index 8cc297d58ba86814c8ab7413aca5d436ad637c68..11434ed641247069af910c81546044336bf78f5a 100644 (file)
@@ -86,8 +86,9 @@ typedef __socklen_t socklen_t;
 \r
 #include <machine/ansi.h>\r
 \r
-#ifdef  _BSD_SIZE_T_\r
-typedef _BSD_SIZE_T_  size_t;\r
+#ifdef  _EFI_SIZE_T_\r
+typedef _EFI_SIZE_T_  size_t;\r
+#undef  _EFI_SIZE_T_\r
 #undef  _BSD_SIZE_T_\r
 #endif\r
 \r
index adc61ecf8067f1f190abe953301a3813395b3b1b..47e993b8bea6fc0e8ae9f24fd2b2aa5ec062df26 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made\r
     available under  the terms and conditions of the BSD License that\r
     accompanies this distribution. The full text of the license may be found at\r
@@ -54,6 +54,7 @@
 struct stat {\r
   off_t           st_size;          /* file size, in bytes */\r
   off_t           st_physsize;      /* physical space the file consumes */\r
+  off_t           st_curpos;        /* current position within the file, or XY coord. for Console */\r
   dtime_t         st_birthtime;     /* time of creation */\r
   dtime_t         st_atime;         /* time of last access */\r
   dtime_t         st_mtime;         /* time of last data modification */\r
@@ -113,7 +114,8 @@ struct stat {
     Traditionally, the remainder of the flags are specified in Octal\r
     but they are expressed in Hex here for modern clarity.\r
 */\r
-#define _S_IFMT       0x0001F000   /* type-of-file mask */\r
+#define _S_IFMT       0x000FF000   /* type-of-file mask */\r
+#define _S_IFIFO      0x00001000   /* named pipe (fifo) */\r
 #define _S_IFCHR      0x00002000   /* character special */\r
 #define _S_IFDIR      0x00004000   /* directory */\r
 #define _S_IFBLK      0x00006000   /* block special */\r
@@ -121,9 +123,10 @@ struct stat {
 #define _S_IFSOCK     0x0000C000   /* socket */\r
 #define _S_ITTY       0x00010000   /* File connects to a TTY device */\r
 #define _S_IWTTY      0x00020000   /* TTY receives Wide characters */\r
+#define _S_ICONSOLE   0x00030000    /* UEFI Console Device */\r
 \r
 /*  UEFI specific (FAT file system) File attributes.\r
-    Specifiec in Hexadecimal instead of Octal.\r
+    Specified in Hexadecimal instead of Octal.\r
     These bits correspond to the xx portion of _S_IFMT\r
 */\r
 #define S_IREADONLY   0x00100000    // Read Only File\r
@@ -133,9 +136,10 @@ struct stat {
 #define S_IARCHIVE    0x02000000    // Archive Bit\r
 #define S_IROFS       0x08000000   /* Read Only File System */\r
 \r
+#define S_EFIONLY     0xF0000000  /* Flags only used by the EFI system calls. */\r
+\r
 #define S_EFISHIFT    20            // LS bit of the UEFI attributes\r
 \r
-//#define _S_IFIFO      0010000   /* named pipe (fifo) */\r
 //#define _S_IFLNK      0120000   /* symbolic link */\r
 //#define _S_IFWHT      0160000   /* whiteout */\r
 //#define _S_ARCH1      0200000   /* Archive state 1, ls -l shows 'a' */\r
@@ -146,12 +150,12 @@ struct stat {
 #define S_IFMT   _S_IFMT\r
 #define S_IFBLK  _S_IFBLK\r
 #define S_IFREG  _S_IFREG\r
-//#define S_IFIFO  _S_IFIFO\r
-//#define S_IFCHR  _S_IFCHR\r
-//#define S_IFDIR  _S_IFDIR\r
+#define S_IFIFO  _S_IFIFO\r
+#define S_IFCHR  _S_IFCHR\r
+#define S_IFDIR  _S_IFDIR\r
 //#define S_IFLNK  _S_IFLNK\r
 //#define S_ISVTX  _S_ISVTX\r
-//#define S_IFSOCK _S_IFSOCK\r
+#define S_IFSOCK _S_IFSOCK\r
 //#define S_IFWHT  _S_IFWHT\r
 \r
 //#define S_ARCH1 _S_ARCH1\r
@@ -163,7 +167,7 @@ struct stat {
 #define S_ISBLK(m)  ((m & _S_IFMT) == _S_IFBLK) /* block special */\r
 #define S_ISSOCK(m) ((m & _S_IFMT) == _S_IFSOCK)  /* socket */\r
 \r
-//#define S_ISFIFO(m) ((m & _S_IFMT) == _S_IFIFO) /* fifo */\r
+#define S_ISFIFO(m) ((m & _S_IFMT) == _S_IFIFO) /* fifo */\r
 //#define S_ISLNK(m)  ((m & _S_IFMT) == _S_IFLNK) /* symbolic link */\r
 //#define S_ISWHT(m)  ((m & _S_IFMT) == _S_IFWHT) /* whiteout */\r
 \r
index a26104c7f682357e4d8d2134e64fcdb72e27b615..80b18c3917632b4cb0c48f99aff07d7d651531ff 100644 (file)
@@ -37,6 +37,8 @@
 #include <sys/featuretest.h>\r
 \r
 #define ARG_MAX    (2 * 1024) /* max bytes for an exec function */\r
+#define ARGC_MAX    (ARG_MAX / 2)   /* Maximum value for argc */\r
+\r
 #ifndef CHILD_MAX\r
   #define CHILD_MAX     128 /* max simultaneous processes */\r
 #endif\r
index 1dd10b598f7fd6e96ec29f2effa8588ebe7b4f02..4b1731720057dfdaf8e0866241ce2adbcf020d8e 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     System-specific declarations and macros related to time.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available under\r
     the terms and conditions of the BSD License that accompanies this distribution.\r
     The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -180,4 +180,7 @@ void    Efi2Tm( EFI_TIME *EfiBDtime, struct tm *NewTime);
 \r
 __END_DECLS\r
 \r
+/* BSD compatibility functions */\r
+int gettimeofday (struct timeval *tp, void *ignore);\r
+\r
 #endif /* !_SYS_TIME_H_ */\r
index 9e95fd3ea33a67d207eef9c1de6065db05f732bb..68e3ba3ddd5840b635dcfde1de3616ddbb930e99 100644 (file)
@@ -243,8 +243,8 @@ typedef int64_t   dtime_t;  /* on-disk time_t */
   #undef  _EFI_CLOCK_T\r
 #endif\r
 \r
-#if   defined(_BSD_SIZE_T_) && defined(_EFI_SIZE_T_)\r
-  typedef _BSD_SIZE_T_      size_t;\r
+#ifdef  _EFI_SIZE_T_\r
+  typedef _EFI_SIZE_T_      size_t;\r
   #define _SIZE_T\r
   #undef  _BSD_SIZE_T_\r
   #undef  _EFI_SIZE_T_\r
index 8c3ee8fbf95814bb80ceb2c56fd1a408fb270e7f..e6d667ba3029e89f36e02011a7ff802acdd3ae76 100644 (file)
@@ -43,8 +43,9 @@
 #include <machine/ansi.h>\r
 #include <sys/featuretest.h>\r
 \r
-#ifdef  _BSD_SIZE_T_\r
-typedef _BSD_SIZE_T_  size_t;\r
+#ifdef  _EFI_SIZE_T_\r
+typedef _EFI_SIZE_T_  size_t;\r
+#undef  _EFI_SIZE_T_\r
 #undef  _BSD_SIZE_T_\r
 #endif\r
 \r
diff --git a/StdLib/Include/sys/unistd.h b/StdLib/Include/sys/unistd.h
new file mode 100644 (file)
index 0000000..0e7158c
--- /dev/null
@@ -0,0 +1,192 @@
+/*  $NetBSD: unistd.h,v 1.35 2006/08/14 18:17:48 rpaulo Exp $ */\r
+\r
+/*\r
+ * Copyright (c) 1989, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  @(#)unistd.h  8.2 (Berkeley) 1/7/94\r
+ */\r
+\r
+#ifndef _SYS_UNISTD_H_\r
+#define _SYS_UNISTD_H_\r
+\r
+#include <sys/featuretest.h>\r
+\r
+/* compile-time symbolic constants */\r
+#define _POSIX_JOB_CONTROL  /* implementation supports job control */\r
+\r
+/*\r
+ * According to POSIX 1003.1:\r
+ * "The saved set-user-ID capability allows a program to regain the\r
+ * effective user ID established at the last exec call."\r
+ * However, the setuid/setgid function as specified by POSIX 1003.1 does\r
+ * not allow changing the effective ID from the super-user without also\r
+ * changed the saved ID, so it is impossible to get super-user privileges\r
+ * back later.  Instead we provide this feature independent of the current\r
+ * effective ID through the seteuid/setegid function.  In addition, we do\r
+ * not use the saved ID as specified by POSIX 1003.1 in setuid/setgid,\r
+ * because this would make it impossible for a set-user-ID executable\r
+ * owned by a user other than the super-user to permanently revoke its\r
+ * extra privileges.\r
+ */\r
+#ifdef  _NOT_AVAILABLE\r
+#define _POSIX_SAVED_IDS  /* saved set-user-ID and set-group-ID */\r
+#endif\r
+\r
+#define _POSIX_VERSION    199009L\r
+#define _POSIX2_VERSION   199212L\r
+\r
+/* execution-time symbolic constants */\r
+        /* chown requires appropriate privileges */\r
+#define _POSIX_CHOWN_RESTRICTED 1\r
+        /* clock selection */\r
+#define _POSIX_CLOCK_SELECTION  -1\r
+        /* too-long path components generate errors */\r
+#define _POSIX_NO_TRUNC   1\r
+        /* may disable terminal special characters */\r
+#define _POSIX_VDISABLE   ((unsigned char)'\377')\r
+        /* file synchronization is available */\r
+#define _POSIX_FSYNC    1\r
+        /* synchronized I/O is available */\r
+#define _POSIX_SYNCHRONIZED_IO  1\r
+        /* memory mapped files */\r
+#define _POSIX_MAPPED_FILES 1\r
+        /* memory locking of whole address space */\r
+#define _POSIX_MEMLOCK    1\r
+        /* memory locking address ranges */\r
+#define _POSIX_MEMLOCK_RANGE  1\r
+        /* memory access protections */\r
+#define _POSIX_MEMORY_PROTECTION 1\r
+        /* monotonic clock */\r
+#define _POSIX_MONOTONIC_CLOCK  200112L\r
+        /* threads */\r
+#define _POSIX_THREADS    200112L\r
+        /* semaphores */\r
+#define _POSIX_SEMAPHORES 0\r
+        /* barriers */\r
+#define _POSIX_BARRIERS   200112L\r
+        /* timers */\r
+#define _POSIX_TIMERS   200112L\r
+        /* spin locks */\r
+#define _POSIX_SPIN_LOCKS 200112L\r
+        /* read/write locks */\r
+#define _POSIX_READER_WRITER_LOCKS  200112L\r
+        /* XPG4.2 shared memory */\r
+#define _XOPEN_SHM    0\r
+\r
+#if defined(_NETBSD_SOURCE)\r
+/* whence values for lseek(2); renamed by POSIX 1003.1 */\r
+#define L_SET   SEEK_SET\r
+#define L_INCR    SEEK_CUR\r
+#define L_XTND    SEEK_END\r
+\r
+/*\r
+ * fsync_range values.\r
+ *\r
+ * Note the following flag values were chosen to not overlap\r
+ * values for SEEK_XXX flags.  While not currently implemented,\r
+ * it is possible to extend this call to respect SEEK_CUR and\r
+ * SEEK_END offset addressing modes.\r
+ */\r
+#define FDATASYNC 0x0010  /* sync data and minimal metadata */\r
+#define FFILESYNC 0x0020  /* sync data and metadata */\r
+#define FDISKSYNC 0x0040  /* flush disk caches after sync */\r
+#endif\r
+\r
+/* configurable pathname variables; use as argument to pathconf(3) */\r
+#define _PC_LINK_MAX     1\r
+#define _PC_MAX_CANON    2\r
+#define _PC_MAX_INPUT    3\r
+#define _PC_NAME_MAX     4\r
+#define _PC_PATH_MAX     5\r
+#define _PC_PIPE_BUF     6\r
+#define _PC_CHOWN_RESTRICTED   7\r
+#define _PC_NO_TRUNC     8\r
+#define _PC_VDISABLE     9\r
+#define _PC_SYNC_IO   10\r
+#define _PC_FILESIZEBITS  11\r
+\r
+/* configurable system variables; use as argument to sysconf(3) */\r
+/*\r
+ * XXX The value of _SC_CLK_TCK is embedded in <time.h>.\r
+ * XXX The value of _SC_PAGESIZE is embedded in <sys/shm.h>.\r
+ */\r
+#define _SC_ARG_MAX    1\r
+#define _SC_CHILD_MAX    2\r
+#define _O_SC_CLK_TCK    3 /* Old version, always 100 */\r
+#define _SC_NGROUPS_MAX    4\r
+#define _SC_OPEN_MAX     5\r
+#define _SC_JOB_CONTROL    6\r
+#define _SC_SAVED_IDS    7\r
+#define _SC_VERSION    8\r
+#define _SC_BC_BASE_MAX    9\r
+#define _SC_BC_DIM_MAX    10\r
+#define _SC_BC_SCALE_MAX  11\r
+#define _SC_BC_STRING_MAX 12\r
+#define _SC_COLL_WEIGHTS_MAX  13\r
+#define _SC_EXPR_NEST_MAX 14\r
+#define _SC_LINE_MAX    15\r
+#define _SC_RE_DUP_MAX    16\r
+#define _SC_2_VERSION   17\r
+#define _SC_2_C_BIND    18\r
+#define _SC_2_C_DEV   19\r
+#define _SC_2_CHAR_TERM   20\r
+#define _SC_2_FORT_DEV    21\r
+#define _SC_2_FORT_RUN    22\r
+#define _SC_2_LOCALEDEF   23\r
+#define _SC_2_SW_DEV    24\r
+#define _SC_2_UPE   25\r
+#define _SC_STREAM_MAX    26\r
+#define _SC_TZNAME_MAX    27\r
+#define _SC_PAGESIZE    28\r
+#define _SC_PAGE_SIZE   _SC_PAGESIZE  /* 1170 compatibility */\r
+#define _SC_FSYNC   29\r
+#define _SC_XOPEN_SHM   30\r
+#define _SC_SYNCHRONIZED_IO 31\r
+#define _SC_IOV_MAX   32\r
+#define _SC_MAPPED_FILES  33\r
+#define _SC_MEMLOCK   34\r
+#define _SC_MEMLOCK_RANGE 35\r
+#define _SC_MEMORY_PROTECTION 36\r
+#define _SC_LOGIN_NAME_MAX  37\r
+#define _SC_MONOTONIC_CLOCK 38\r
+#define _SC_CLK_TCK   39 /* New, variable version */\r
+#define _SC_ATEXIT_MAX    40\r
+#define _SC_THREADS   41\r
+#define _SC_SEMAPHORES    42\r
+#define _SC_BARRIERS    43\r
+#define _SC_TIMERS    44\r
+#define _SC_SPIN_LOCKS    45\r
+#define _SC_READER_WRITER_LOCKS 46\r
+#define _SC_GETGR_R_SIZE_MAX  47\r
+#define _SC_GETPW_R_SIZE_MAX  48\r
+#define _SC_CLOCK_SELECTION 49\r
+\r
+/* configurable system strings */\r
+#define _CS_PATH     1\r
+\r
+#endif /* !_SYS_UNISTD_H_ */\r
index 386629cc6b422ee216215cd97338db0a10a8c4b5..8c7b8e14229fc52c09733ab2d2759a34558f152c 100644 (file)
     if Daylight Saving Time is not in effect, and negative if the information\r
     is not available.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available under\r
     the terms and conditions of the BSD License that accompanies this distribution.\r
     The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
   #undef _EFI_TIME_T\r
 #endif\r
 \r
+/** Value added to tm_year to get the full year value.  TM_YEAR_BASE + 110 --> 2010\r
+**/\r
+#define TM_YEAR_BASE  1900\r
+\r
+/** Values for the tm_wday member of struct tm.\r
+  @{\r
+**/\r
+#define TM_SUNDAY     0\r
+#define TM_MONDAY     1\r
+#define TM_TUESDAY    2\r
+#define TM_WEDNESDAY  3\r
+#define TM_THURSDAY   4\r
+#define TM_FRIDAY     5\r
+#define TM_SATURDAY   6\r
+/** @}  **/\r
+\r
+/** Values for the tm_mon member of struct tm.\r
+  @{\r
+**/\r
+#define TM_JANUARY     0\r
+#define TM_FEBRUARY    1\r
+#define TM_MARCH       2\r
+#define TM_APRIL       3\r
+#define TM_MAY         4\r
+#define TM_JUNE        5\r
+#define TM_JULY        6\r
+#define TM_AUGUST      7\r
+#define TM_SEPTEMBER   8\r
+#define TM_OCTOBER     9\r
+#define TM_NOVEMBER   10\r
+#define TM_DECEMBER   11\r
+/** @}  **/\r
+\r
 /** A structure holding the components of a calendar time, called the\r
     broken-down time.  The first nine (9) members are as mandated by the\r
     C95 standard.  Additional fields have been added for EFI support.\r
@@ -115,7 +148,7 @@ double EFIAPI difftime(time_t time1, time_t time0);
     same encoding as that of the values returned by the time function. The\r
     original values of the tm_wday and tm_yday components of the structure are\r
     ignored, and the original values of the other components are not\r
-    restricted to the ranges indicated above.270) On successful completion,\r
+    restricted to the ranges indicated above. On successful completion,\r
     the values of the tm_wday and tm_yday components of the structure are set\r
     appropriately, and the other components are set to represent the specified\r
     calendar time, but with their values forced to the ranges indicated above;\r
@@ -128,25 +161,50 @@ double EFIAPI difftime(time_t time1, time_t time0);
 **/\r
 time_t EFIAPI mktime(struct tm *timeptr);\r
 \r
-/**\r
+/** The time function determines the current calendar time.\r
+\r
+    The encoding of the value is unspecified.\r
+\r
+    @return   The time function returns the implementation\92s best approximation\r
+              of the current calendar time. The value (time_t)(-1) is returned\r
+              if the calendar time is not available. If timer is not a null\r
+              pointer, the return value is also assigned to the object it\r
+              points to.\r
 **/\r
 time_t EFIAPI time(time_t *timer);\r
 \r
 /* #################  Time Conversion Functions  ########################## */\r
 \r
-/**\r
+/** The asctime function converts the broken-down time in the structure pointed\r
+    to by timeptr into a string in the form\r
+          Sun Sep 16 01:03:52 1973\n\0\r
+\r
+    @return   The asctime function returns a pointer to the string.\r
 **/\r
 char * EFIAPI asctime(const struct tm *timeptr);\r
 \r
-/**\r
+/** The ctime function converts the calendar time pointed to by timer to local\r
+    time in the form of a string. It is equivalent to asctime(localtime(timer))\r
+\r
+    @return   The ctime function returns the pointer returned by the asctime\r
+              function with that broken-down time as argument.\r
 **/\r
 char * EFIAPI ctime(const time_t *timer);\r
 \r
-/**\r
+/** The gmtime function converts the calendar time pointed to by timer into a\r
+    brokendown time, expressed as UTC.\r
+\r
+    @return   The gmtime function returns a pointer to the broken-down time,\r
+              or a null pointer if the specified time cannot be converted to UTC.\r
 **/\r
 struct tm  * EFIAPI gmtime(const time_t *timer);\r
 \r
-/**\r
+/** The localtime function converts the calendar time pointed to by timer into\r
+    a broken-down time, expressed as local time.\r
+\r
+    @return   The localtime function returns a pointer to the broken-down time,\r
+              or a null pointer if the specified time cannot be converted to\r
+              local time.\r
 **/\r
 struct tm  * EFIAPI localtime(const time_t *timer);\r
 \r
@@ -304,6 +362,9 @@ size_t EFIAPI strftime( char * __restrict s, size_t maxsize,
                       const char * __restrict format,\r
                       const struct tm * __restrict timeptr);\r
 \r
+char *strptime(const char *, const char * format, struct tm*);\r
+\r
+\r
 /* #################  Implementation Functions  ########################### */\r
 \r
 clock_t EFIAPI __getCPS(void);\r
diff --git a/StdLib/Include/unistd.h b/StdLib/Include/unistd.h
new file mode 100644 (file)
index 0000000..fc8d738
--- /dev/null
@@ -0,0 +1,170 @@
+/** @file\r
+\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#ifndef _UNISTD_H_\r
+#define _UNISTD_H_\r
+\r
+//#include <machine/ansi.h>\r
+//#include <machine/int_types.h>\r
+//#include <sys/featuretest.h>\r
+//#include <sys/types.h>\r
+#include  <sys/unistd.h>\r
+#include  <sys/EfiSysCall.h>\r
+\r
+#define F_ULOCK   0\r
+#define F_LOCK    1\r
+#define F_TLOCK   2\r
+#define F_TEST    3\r
+\r
+\r
+__BEGIN_DECLS\r
+int             rename(const char *, const char *);\r
+\r
+// Networking\r
+long            gethostid(void);\r
+int             gethostname(char *, size_t);\r
+int             getdomainname(char *, size_t);\r
+int             setdomainname(const char *, size_t);\r
+int             sethostid(long);\r
+int             sethostname(const char *, size_t);\r
+\r
+// For Future implementation\r
+__dead   void   _exit(int) __attribute__((__noreturn__));\r
+ssize_t         pread(int, void *, size_t, off_t);\r
+ssize_t         pwrite(int, const void *, size_t, off_t);\r
+int             syscall(int, ...);\r
+int             dup(int);\r
+pid_t           fork(void);\r
+\r
+// The following *nix functions are not implemented\r
+unsigned int    alarm(unsigned int);\r
+int             chown(const char *, uid_t, gid_t);\r
+size_t          confstr(int, char *, size_t);\r
+int             execl(const char *, const char *, ...);\r
+int             execle(const char *, const char *, ...);\r
+int             execlp(const char *, const char *, ...);\r
+int             execv(const char *, char * const *);\r
+int             execve(const char *, char * const *, char * const *);\r
+int             execvp(const char *, char * const *);\r
+long            fpathconf(int, int);\r
+gid_t           getegid(void);\r
+uid_t           geteuid(void);\r
+gid_t           getgid(void);\r
+int             getgroups(int, gid_t []);\r
+__aconst char  *getlogin(void);\r
+pid_t           getpgrp(void);\r
+pid_t           getpid(void);\r
+pid_t           getppid(void);\r
+uid_t           getuid(void);\r
+int             link(const char *, const char *);\r
+long            pathconf(const char *, int);\r
+int             pause(void);\r
+int             pipe(int *);\r
+int             setgid(gid_t);\r
+int             setpgid(pid_t, pid_t);\r
+pid_t           setsid(void);\r
+int             setuid(uid_t);\r
+unsigned int    sleep(unsigned int);\r
+long            sysconf(int);\r
+pid_t           tcgetpgrp(int);\r
+int             tcsetpgrp(int, pid_t);\r
+__aconst char  *ttyname(int);\r
+\r
+int             getopt(int, char * const [], const char *);\r
+\r
+extern   char  *optarg;     /* getopt(3) external variables */\r
+extern   int    opterr;\r
+extern   int    optind;\r
+extern   int    optopt;\r
+extern   int    optreset;   /* getopt(3) external variable */\r
+extern   char  *suboptarg;  /* getsubopt(3) external variable */\r
+\r
+int             setegid(gid_t);\r
+int             seteuid(uid_t);\r
+int             fdatasync(int);\r
+int             fsync(int);\r
+int             ttyname_r(int, char *, size_t);\r
+int             chroot(const char *);\r
+int             nice(int);\r
+__aconst char *crypt(const char *, const char *);\r
+int             encrypt(char *, int);\r
+char           *getpass(const char *);\r
+pid_t           getsid(pid_t);\r
+\r
+#ifndef intptr_t\r
+typedef __intptr_t  intptr_t;\r
+#define intptr_t  __intptr_t\r
+#endif\r
+\r
+int             brk(void *);\r
+int             fchdir(int);\r
+int             fchown(int, uid_t, gid_t);\r
+int             getdtablesize(void);\r
+__pure int      getpagesize(void);    /* legacy */\r
+pid_t           getpgid(pid_t);\r
+int             lchown(const char *, uid_t, gid_t);\r
+int             lockf(int, int, off_t);\r
+ssize_t         readlink(const char * __restrict, char * __restrict, size_t);\r
+void           *sbrk(intptr_t);\r
+int             setregid(gid_t, gid_t);\r
+int             setreuid(uid_t, uid_t);\r
+void            swab(const void *, void *, size_t);\r
+int             symlink(const char *, const char *);\r
+void            sync(void);\r
+useconds_t      ualarm(useconds_t, useconds_t);\r
+int             usleep(useconds_t);\r
+pid_t           vfork(void) __RENAME(__vfork14);\r
+\r
+/*\r
+ * Implementation-defined extensions\r
+ */\r
+int             acct(const char *);\r
+int             closefrom(int);\r
+int             des_cipher(const char *, char *, long, int);\r
+int             des_setkey(const char *);\r
+void            endusershell(void);\r
+int             exect(const char *, char * const *, char * const *);\r
+int             fchroot(int);\r
+int             fsync_range(int, int, off_t, off_t);\r
+int             getgrouplist(const char *, gid_t, gid_t *, int *);\r
+int             getgroupmembership(const char *, gid_t, gid_t *, int, int *);\r
+mode_t          getmode(const void *, mode_t);\r
+int             getsubopt(char **, char * const *, char **);\r
+__aconst char  *getusershell(void);\r
+int             initgroups(const char *, gid_t);\r
+int             iruserok(uint32_t, int, const char *, const char *);\r
+int             issetugid(void);\r
+int             nfssvc(int, void *);\r
+int             profil(char *, size_t, u_long, u_int);\r
+void            psignal(unsigned int, const char *);\r
+int             rcmd(char **, int, const char *, const char *, const char *, int *);\r
+int             revoke(const char *);\r
+int             rresvport(int *);\r
+int             ruserok(const char *, int, const char *, const char *);\r
+int             setgroups(int, const gid_t *);\r
+int             setlogin(const char *);\r
+void           *setmode(const char *);\r
+int             setrgid(gid_t);\r
+int             setruid(uid_t);\r
+void            setusershell(void);\r
+void            strmode(mode_t, char *);\r
+__aconst char  *strsignal(int);\r
+int             swapctl(int, void *, int);\r
+quad_t          __syscall(quad_t, ...);\r
+int             undelete(const char *);\r
+int             rcmd_af(char **, int, const char *, const char *, const char *, int *, int);\r
+int             rresvport_af(int *, int);\r
+int             iruserok_sa(const void *, int, int, const char *, const char *);\r
+\r
+__END_DECLS\r
+\r
+#endif /* !_UNISTD_H_ */\r
index 360bdacc32698082d4721ad2b6530a049e64d537..c42594787d9a111f0d78287f2acb2c4d6f0a5c55 100644 (file)
@@ -506,11 +506,23 @@ size_t wcsftime(wchar_t * __restrict s, size_t maxsize, const wchar_t * __restri
 **/\r
 wint_t btowc(int c);\r
 \r
-/**\r
+/** The wctob function determines whether c corresponds to a member of the extended\r
+    character set whose multibyte character representation is a single byte when in the initial\r
+    shift state.\r
+\r
+    @Returns    The wctob function returns EOF if c does not correspond to a multibyte\r
+                character with length one in the initial shift state. Otherwise, it\r
+                returns the single-byte representation of that character as an\r
+                unsigned char converted to an int.\r
 **/\r
 int wctob(wint_t c);\r
 \r
-/**\r
+/** If ps is not a null pointer, the mbsinit function determines whether the\r
+    pointed-to mbstate_t object describes an initial conversion state.\r
+\r
+    @Returns    The mbsinit function returns nonzero if ps is a null pointer\r
+                or if the pointed-to object describes an initial conversion\r
+                state; otherwise, it returns zero.\r
 **/\r
 int mbsinit(const mbstate_t *ps);\r
 \r
@@ -532,7 +544,33 @@ size_t wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps);
 **/\r
 size_t mbsrtowcs(wchar_t * __restrict dst, const char ** __restrict src, size_t len, mbstate_t * __restrict ps);\r
 \r
-/**\r
+/** The wcsrtombs function converts a sequence of wide characters from the array\r
+    indirectly pointed to by src into a sequence of corresponding multibyte\r
+    characters that begins in the conversion state described by the object\r
+    pointed to by ps. If dst is not a null pointer, the converted characters\r
+    are then stored into the array pointed to by dst.  Conversion continues\r
+    up to and including a terminating null wide character, which is also\r
+    stored. Conversion stops earlier in two cases: when a wide character is\r
+    reached that does not correspond to a valid multibyte character, or\r
+    (if dst is not a null pointer) when the next multibyte character would\r
+    exceed the limit of len total bytes to be stored into the array pointed\r
+    to by dst. Each conversion takes place as if by a call to the wcrtomb\r
+    function.)\r
+\r
+    If dst is not a null pointer, the pointer object pointed to by src is\r
+    assigned either a null pointer (if conversion stopped due to reaching\r
+    a terminating null wide character) or the address just past the last wide\r
+    character converted (if any). If conversion stopped due to reaching a\r
+    terminating null wide character, the resulting state described is the\r
+    initial conversion state.\r
+\r
+    @Returns    If conversion stops because a wide character is reached that\r
+                does not correspond to a valid multibyte character, an\r
+                encoding error occurs: the wcsrtombs function stores the\r
+                value of the macro EILSEQ in errno and returns (size_t)(-1);\r
+                the conversion state is unspecified. Otherwise, it returns\r
+                the number of bytes in the resulting multibyte character\r
+                sequence, not including the terminating null character (if any).\r
 **/\r
 size_t wcsrtombs(char * __restrict dst, const wchar_t ** __restrict src, size_t len, mbstate_t * __restrict ps);\r
 \r
index 9aa89ef541ba501e55f5d2b08d7e18b29b57e258..3df726a353dec6e09a4f5efc8e30e06e33b18ce6 100644 (file)
@@ -1,6 +1,15 @@
-/*  $NetBSD: wctype.h,v 1.6 2005/02/03 04:39:32 perry Exp $ */\r
+/** @file\r
+    Wide character classification functions and macros.\r
+\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-/*-\r
  * Copyright (c)1999 Citrus Project,\r
  * All rights reserved.\r
  *\r
  * SUCH DAMAGE.\r
  *\r
  *  citrus Id: wctype.h,v 1.4 2000/12/21 01:50:21 itojun Exp\r
- */\r
 \r
+    NetBSD: wctype.h,v 1.6 2005/02/03 04:39:32 perry Exp\r
+**/\r
 #ifndef _WCTYPE_H_\r
 #define _WCTYPE_H_\r
 \r
 #include  <sys/EfiCdefs.h>\r
 #include  <machine/ansi.h>\r
 \r
-#ifdef  _BSD_WINT_T_\r
-typedef _BSD_WINT_T_    wint_t;\r
-#undef  _BSD_WINT_T_\r
+#ifdef _EFI_WINT_T\r
+  typedef _EFI_WINT_T  wint_t;\r
+  #undef _BSD_WINT_T_\r
+  #undef _EFI_WINT_T\r
 #endif\r
 \r
 #ifdef  _BSD_WCTRANS_T_\r
index 01fbe79dc9f395cd4d8e36cd410f50c10a5d542c..cbf4ec273f8cb5b208dc17a2063478aac9d6d8e2 100644 (file)
@@ -14,7 +14,6 @@
 \r
 **/\r
 #include <Uefi.h>\r
-#include  <Library/UefiLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <sys/EfiCdefs.h>\r
 \r
 \r
 // Shift Datum left by Count bits.\r
 // ===========================================================================\r
-//int __ashlsi3(int Datum, int Count)\r
-//{\r
-//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
-//  return (int) LShiftU64 ((UINT64)Datum, (UINTN)Count);\r
-//}\r
+int __ashlsi3(int Datum, int Count)\r
+{\r
+  DEBUG((DEBUG_INFO, "%a:\n", __func__));\r
+  return (int) LShiftU64 ((UINT64)Datum, (UINTN)Count);\r
+}\r
 \r
-INT64 __ashldi3(INT64 Datum, int Count)\r
+long __ashldi3(long Datum, int Count)\r
 {\r
-  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
-  return LShiftU64 (Datum, (UINTN)Count);\r
+  DEBUG((DEBUG_INFO, "%a:\n", __func__));\r
+  return (long) LShiftU64 ((UINT64)Datum, (UINTN)Count);\r
 }\r
 \r
-//long long __ashlti3(long long Datum, int Count)\r
-//{\r
-//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
-//  return (long long) LShiftU64 ((UINT64)Datum, (UINTN)Count);\r
-//}\r
+long long __ashlti3(long long Datum, int Count)\r
+{\r
+  DEBUG((DEBUG_INFO, "%a:\n", __func__));\r
+  return (long long) LShiftU64 ((UINT64)Datum, (UINTN)Count);\r
+}\r
 \r
 // Arithmetically shift Datum right by Count bits.\r
 // ===========================================================================\r
-//int __ashrsi3(int Datum, int Count)\r
-//{\r
-//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
-//  return (int) ARShiftU64 ((UINT64) Datum, (UINTN)Count);\r
-//}\r
+int __ashrsi3(int Datum, int Count)\r
+{\r
+  DEBUG((DEBUG_INFO, "%a:\n", __func__));\r
+  return (int) ARShiftU64 ((UINT64) Datum, (UINTN)Count);\r
+}\r
 \r
-INT64 __ashrdi3(INT64 Datum, int Count)\r
+long __ashrdi3(long Datum, int Count)\r
 {\r
-  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
-  return ARShiftU64 ( Datum, (UINTN)Count);\r
+  DEBUG((DEBUG_INFO, "%a:\n", __func__));\r
+  return (long) ARShiftU64 ((UINT64) Datum, (UINTN)Count);\r
 }\r
 \r
-//long long __ashrti3(long long Datum, int Count)\r
-//{\r
-//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
-//  return (long long) ARShiftU64 ((UINT64) Datum, (UINTN)Count);\r
-//}\r
+long long __ashrti3(long long Datum, int Count)\r
+{\r
+  DEBUG((DEBUG_INFO, "%a:\n", __func__));\r
+  return (long long) ARShiftU64 ((UINT64) Datum, (UINTN)Count);\r
+}\r
 \r
 // Return the quotient of the signed division of Dividend and Divisor\r
 // ===========================================================================\r
-//int __divsi3(int Dividend, int Divisor)\r
-//{\r
-//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
-//  return (int) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);\r
-//}\r
+int __divsi3(int Dividend, int Divisor)\r
+{\r
+  DEBUG((DEBUG_INFO, "%a:\n", __func__));\r
+  return (int) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);\r
+}\r
 \r
 INT64 __divdi3(INT64 Dividend, INT64 Divisor)\r
 {\r
   INT64 Quotient;\r
 \r
   Quotient = DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);\r
-  DebugPrint(DEBUG_INFO, "%a: %Ld / %Ld = %Ld\n", __func__, Dividend, Divisor, Quotient);\r
+  DEBUG((DEBUG_INFO, "%a: %Ld / %Ld = %Ld\n", __func__, Dividend, Divisor, Quotient));\r
 \r
   return Quotient;\r
 }\r
 \r
-//long long __divti3(long long Dividend, long long Divisor)\r
-//{\r
-//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
-//  return (long long) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);\r
-//}\r
+long long __divti3(long long Dividend, long long Divisor)\r
+{\r
+  DEBUG((DEBUG_INFO, "%a:\n", __func__));\r
+  return (long long) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, NULL);\r
+}\r
 \r
 // Logically shift Datum right by Count bits\r
 // ===========================================================================\r
-//int __lshrsi3(int Datum, int Count)\r
-//{\r
-//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
-//  return (int) RShiftU64 ((UINT64) Datum, (UINTN)Count);\r
-//}\r
+int __lshrsi3(int Datum, int Count)\r
+{\r
+  DEBUG((DEBUG_INFO, "%a:\n", __func__));\r
+  return (int) RShiftU64 ((UINT64) Datum, (UINTN)Count);\r
+}\r
 \r
-INT64 __lshrdi3(INT64 Datum, int Count)\r
+long __lshrdi3(int Datum, int Count)\r
 {\r
-  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
-  return RShiftU64 ( Datum, (UINTN)Count);\r
+  DEBUG((DEBUG_INFO, "%a:\n", __func__));\r
+  return (long) RShiftU64 ((UINT64) Datum, (UINTN)Count);\r
 }\r
 \r
-//long long __lshrti3(int Datum, int Count)\r
-//{\r
-//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
-//  return (long long) RShiftU64 ((UINT64) Datum, (UINTN)Count);\r
-//}\r
+long long __lshrti3(int Datum, int Count)\r
+{\r
+  DEBUG((DEBUG_INFO, "%a:\n", __func__));\r
+  return (long long) RShiftU64 ((UINT64) Datum, (UINTN)Count);\r
+}\r
 \r
 // Return the remainder of the signed division of Dividend and Divisor\r
 // ===========================================================================\r
-//int __modsi3(int Dividend, int Divisor)\r
-//{\r
-//  INT64 Remainder;\r
+int __modsi3(int Dividend, int Divisor)\r
+{\r
+  INT64 Remainder;\r
 \r
-//  (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);\r
-//  DebugPrint(DEBUG_INFO, "modsi3: %d %% %d = %d\n", Dividend, Divisor, (int)Remainder);\r
+  (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);\r
+  DEBUG((DEBUG_INFO, "modsi3: %d %% %d = %d\n", Dividend, Divisor, (int)Remainder));\r
 \r
-//  return (int) Remainder;\r
-//}\r
+  return (int) Remainder;\r
+}\r
 \r
 INT64 __moddi3(INT64 Dividend, INT64 Divisor)\r
 {\r
   INT64 Remainder;\r
 \r
   (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);\r
-  DebugPrint(DEBUG_INFO, "moddi3: %Ld %% %Ld = %Ld\n", (INT64)Dividend, (INT64)Divisor, Remainder);\r
+  DEBUG((DEBUG_INFO, "moddi3: %Ld %% %Ld = %Ld\n", (INT64)Dividend, (INT64)Divisor, Remainder));\r
 \r
   return Remainder;\r
 }\r
 \r
-//long long __modti3(long long Dividend, long long Divisor)\r
-//{\r
-//  INT64 Remainder;\r
+long long __modti3(long long Dividend, long long Divisor)\r
+{\r
+  INT64 Remainder;\r
 \r
-//  (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);\r
-//  DebugPrint(DEBUG_INFO, "modti3: %Ld %% %Ld = %Ld\n", (INT64)Dividend, (INT64)Divisor, Remainder);\r
+  (void) DivS64x64Remainder ((INT64) Dividend, (INT64) Divisor, &Remainder);\r
+  DEBUG((DEBUG_INFO, "modti3: %Ld %% %Ld = %Ld\n", (INT64)Dividend, (INT64)Divisor, Remainder));\r
 \r
-//  return (long long) Remainder;\r
-//}\r
+  return (long long) Remainder;\r
+}\r
 \r
 // These functions return the product of the Multiplicand and Multiplier.\r
 // ===========================================================================\r
-//long long __multi3(long long Multiplicand, long long Multiplier)\r
-//{\r
-//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
-//  return (long long) MultS64x64 ((INT64)Multiplicand, (INT64)Multiplier);\r
-//}\r
+long long __multi3(long long Multiplicand, long long Multiplier)\r
+{\r
+  DEBUG((DEBUG_INFO, "%a:\n", __func__));\r
+  return (long long) MultS64x64 ((INT64)Multiplicand, (INT64)Multiplier);\r
+}\r
 \r
 // Return the quotient of the unsigned division of a and b.\r
 // ===========================================================================\r
-//unsigned int __udivsi3(unsigned int Dividend, unsigned int Divisor)\r
-//{\r
-//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
-//  return (int) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);\r
-//}\r
+unsigned int __udivsi3(unsigned int Dividend, unsigned int Divisor)\r
+{\r
+  DEBUG((DEBUG_INFO, "%a:\n", __func__));\r
+  return (int) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);\r
+}\r
 \r
-UINT64 __udivdi3(UINT64 Dividend, UINT64 Divisor)\r
+unsigned long __udivdi3(unsigned long Dividend, unsigned long Divisor)\r
 {\r
-  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
-  return DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);\r
+  DEBUG((DEBUG_INFO, "%a:\n", __func__));\r
+  return (long) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);\r
 }\r
 \r
-//unsigned long long __udivti3(unsigned long long Dividend, unsigned long long Divisor)\r
-//{\r
-//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
-//  return (long long) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);\r
-//}\r
+unsigned long long __udivti3(unsigned long long Dividend, unsigned long long Divisor)\r
+{\r
+  DEBUG((DEBUG_INFO, "%a:\n", __func__));\r
+  return (long long) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, NULL);\r
+}\r
 \r
 // ===========================================================================\r
-//unsigned int __umodsi3(unsigned int Dividend, unsigned int Divisor)\r
-//{\r
-//  UINT64 Remainder;\r
+unsigned int __umodsi3(unsigned int Dividend, unsigned int Divisor)\r
+{\r
+  UINT64 Remainder;\r
 \r
-//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
-//  (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);\r
+  DEBUG((DEBUG_INFO, "%a:\n", __func__));\r
+  (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);\r
 \r
-//  return (unsigned int) Remainder;\r
-//}\r
+  return (unsigned int) Remainder;\r
+}\r
 \r
-UINT64 __umoddi3(UINT64 Dividend, UINT64 Divisor)\r
+unsigned long __umoddi3(unsigned long Dividend, unsigned long Divisor)\r
 {\r
   UINT64 Remainder;\r
 \r
-  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
+  DEBUG((DEBUG_INFO, "%a:\n", __func__));\r
   (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);\r
 \r
-  return Remainder;\r
+  return (unsigned long) Remainder;\r
 }\r
 \r
-//unsigned long long __umodti3(unsigned long long Dividend, unsigned long long Divisor)\r
-//{\r
-//  UINT64 Remainder;\r
+unsigned long long __umodti3(unsigned long long Dividend, unsigned long long Divisor)\r
+{\r
+  UINT64 Remainder;\r
 \r
-//  DebugPrint(DEBUG_INFO, "%a:\n", __func__);\r
-//  (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);\r
+  DEBUG((DEBUG_INFO, "%a:\n", __func__));\r
+  (void) DivU64x64Remainder ((UINT64) Dividend, (UINT64) Divisor, &Remainder);\r
 \r
-//  return (unsigned long long) Remainder;\r
-//}\r
+  return (unsigned long long) Remainder;\r
+}\r
index 4af3ffe45e182d11c1150d4b9e145ba893358fb9..451b9b0e649957441876d6736a2bd18d183e00ec 100644 (file)
   LibStdLib\r
   LibStdio\r
   LibString\r
+  DevConsole\r
 \r
 ################################################################\r
 #\r
index 0336d8b36a771643ac2e378ce11954126a6bd3c2..47103ce388a31620fa675291025feff45144c78c 100644 (file)
@@ -4,7 +4,7 @@
   All of the global data in the gMD structure is initialized to 0, NULL, or\r
   SIG_DFL; as appropriate.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials are licensed and made available under\r
   the terms and conditions of the BSD License that accompanies this distribution.\r
   The full text of the license may be found at\r
 \r
 #include  <errno.h>\r
 #include  <stdio.h>\r
+#include  <stdlib.h>\r
 #include  <string.h>\r
 #include  <MainData.h>\r
+#include  <sys/EfiSysCall.h>\r
 \r
-extern int main( int, wchar_t**);\r
+extern int main( int, char**);\r
 extern int __sse2_available;\r
 \r
 struct  __MainData  *gMD;\r
@@ -38,6 +40,75 @@ void __main()
   ;\r
 }\r
 \r
+static\r
+void\r
+FinalCleanup( void )\r
+{\r
+  int i;\r
+\r
+  /* Close any open files */\r
+  for(i = OPEN_MAX - 1; i >= 0; --i) {\r
+    (void)close(i);   // Close properly handles closing a closed file.\r
+  }\r
+\r
+  /* Free the global MainData structure */\r
+  if(gMD != NULL) {\r
+    if(gMD->NCmdLine != NULL) {\r
+      FreePool( gMD->NCmdLine );\r
+    }\r
+    FreePool( gMD );\r
+  }\r
+}\r
+\r
+/* Create mbcs versions of the Argv strings. */\r
+static\r
+char **\r
+ArgvConvert(UINTN Argc, CHAR16 **Argv)\r
+{\r
+  size_t  AVsz;       /* Size of a single nArgv string */\r
+  UINTN   count;\r
+  char  **nArgv;\r
+  char   *string;\r
+  INTN    nArgvSize;  /* Cumulative size of narrow Argv[i] */\r
+\r
+  nArgvSize = Argc;\r
+  /* Determine space needed for narrow Argv strings. */\r
+  for(count = 0; count < Argc; ++count) {\r
+    AVsz = wcstombs(NULL, Argv[count], ARG_MAX);\r
+    if(AVsz < 0) {\r
+      Print(L"ABORTING: Argv[%d] contains an unconvertable character.\n", count);\r
+      exit(EXIT_FAILURE);\r
+      /* Not Reached */\r
+    }\r
+    nArgvSize += AVsz;\r
+  }\r
+\r
+  /* Reserve space for the converted strings. */\r
+  gMD->NCmdLine = (char *)AllocateZeroPool(nArgvSize+1);\r
+  if(gMD->NCmdLine == NULL) {\r
+    Print(L"ABORTING: Insufficient memory.\n");\r
+    exit(EXIT_FAILURE);\r
+    /* Not Reached */\r
+  }\r
+\r
+  /* Convert Argument Strings. */\r
+  nArgv   = gMD->NArgV;\r
+  string  = gMD->NCmdLine;\r
+  for(count = 0; count < Argc; ++count) {\r
+    nArgv[count] = string;\r
+    AVsz = wcstombs(string, Argv[count], nArgvSize);\r
+    string[AVsz] = 0;   /* NULL terminate the argument */\r
+    string += AVsz + 1;\r
+    nArgvSize -= AVsz + 1;\r
+    if(nArgvSize < 0) {\r
+      Print(L"ABORTING: Internal Argv[%d] conversion error.\n", count);\r
+      exit(EXIT_FAILURE);\r
+      /* Not Reached */\r
+    }\r
+  }\r
+  return gMD->NArgV;\r
+}\r
+\r
 INTN\r
 EFIAPI\r
 ShellAppMain (\r
@@ -45,10 +116,10 @@ ShellAppMain (
   IN CHAR16 **Argv\r
   )\r
 {\r
+  struct __filedes   *mfd;\r
+  char              **nArgv;\r
   INTN   ExitVal;\r
   INTN   i;\r
-  struct __filedes *mfd;\r
-  FILE  *fp;\r
 \r
   ExitVal = (INTN)RETURN_SUCCESS;\r
   gMD = AllocateZeroPool(sizeof(struct __MainData));\r
@@ -61,10 +132,11 @@ ShellAppMain (
     _fltused              = 1;\r
     errno                 = 0;\r
     EFIerrno              = 0;\r
+    gMD->FinalCleanup     = &FinalCleanup;\r
 \r
 #ifdef NT32dvm\r
-    gMD->ClocksPerSecond  = 0;  // For NT32 only\r
-    gMD->AppStartTime     = 0;  // For NT32 only\r
+    gMD->ClocksPerSecond  = 1;  // For NT32 only\r
+    gMD->AppStartTime     = 1;  // For NT32 only\r
 #else\r
     gMD->ClocksPerSecond = (clock_t)GetPerformanceCounterProperties( NULL, NULL);\r
     gMD->AppStartTime = (clock_t)GetPerformanceCounter();\r
@@ -76,27 +148,28 @@ ShellAppMain (
       mfd[i].MyFD = (UINT16)i;\r
     }\r
 \r
-    // Open stdin, stdout, stderr\r
-    fp = freopen("stdin:", "r", stdin);\r
-    if(fp != NULL) {\r
-      fp = freopen("stdout:", "w", stdout);\r
-      if(fp != NULL) {\r
-        fp = freopen("stderr:", "w", stderr);\r
+    i = open("stdin:", O_RDONLY, 0444);\r
+    if(i == 0) {\r
+      i = open("stdout:", O_WRONLY, 0222);\r
+      if(i == 1) {\r
+        i = open("stderr:", O_WRONLY, 0222);\r
       }\r
     }\r
-    if(fp == NULL) {\r
+    if(i != 2) {\r
       Print(L"ERROR Initializing Standard IO: %a.\n    %r\n",\r
             strerror(errno), EFIerrno);\r
     }\r
 \r
-    ExitVal = (INTN)main( (int)Argc, (wchar_t **)Argv);\r
-\r
-    if (gMD->cleanup != NULL) {\r
-      gMD->cleanup();\r
+    /* Create mbcs versions of the Argv strings. */\r
+    nArgv = ArgvConvert(Argc, Argv);\r
+    if(nArgv == NULL) {\r
+      ExitVal = (INTN)RETURN_INVALID_PARAMETER;\r
     }\r
+    else {\r
+      ExitVal = (INTN)main( (int)Argc, nArgv);\r
   }\r
-  if(gMD != NULL) {\r
-    FreePool( gMD );\r
   }\r
+  exit((int)ExitVal);\r
+  /* Not Reached */\r
   return ExitVal;\r
 }\r
index 5d1584ddea1f9852d8cd9582e449d602a6286d63..8472d0ef4c95a36c01f78be1df107f45a9420959 100644 (file)
@@ -6,11 +6,11 @@
     - exit(int status)\r
     - _Exit(int status)\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials are licensed and made available under\r
   the terms and conditions of the BSD License that accompanies this distribution.\r
   The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php.\r
+  http://opensource.org/licenses/bsd-license.\r
 \r
   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -92,30 +92,27 @@ atexit(void (*handler)(void))
 void\r
 exit(int status)\r
 {\r
-  int i = gMD->num_atexit;\r
+  void (*CleanUp)(void);   // Pointer to Cleanup Function\r
+  int   i;\r
+\r
+  if(gMD != NULL) {\r
+    CleanUp = gMD->cleanup; // Preserve the pointer to the Cleanup Function\r
 \r
   // Call all registered atexit functions in reverse order\r
+    i = gMD->num_atexit;\r
   if( i > 0) {\r
     do {\r
       (gMD->atexit_handler[--i])();\r
     } while( i > 0);\r
   }\r
 \r
-  if (gMD->cleanup != NULL) {\r
-    gMD->cleanup();\r
+    if (CleanUp != NULL) {\r
+      CleanUp();\r
+    }\r
   }\r
   _Exit(status);\r
 }\r
 \r
-typedef\r
-EFI_STATUS\r
-(EFIAPI *ExitFuncPtr)(\r
-  IN  EFI_HANDLE                   ImageHandle,\r
-  IN  EFI_STATUS                   ExitStatus,\r
-  IN  UINTN                        ExitDataSize,\r
-  IN  CHAR16                       *ExitData     OPTIONAL\r
-) __noreturn;\r
-\r
 /** The _Exit function causes normal program termination to occur and control\r
     to be returned to the host environment.\r
 \r
@@ -133,16 +130,16 @@ void
 _Exit(int status)\r
 {\r
   RETURN_STATUS ExitVal = (RETURN_STATUS)status;\r
-  ExitFuncPtr   ExitFunc;\r
 \r
   if( ExitVal == EXIT_FAILURE) {\r
     ExitVal = RETURN_ABORTED;\r
   }\r
 \r
-  ExitFunc = (ExitFuncPtr)gBS->Exit;\r
+  if(gMD->FinalCleanup != NULL) {\r
+    gMD->FinalCleanup();  // gMD does not exist when this returns.\r
+  }\r
 \r
-  //gBS->Exit(gImageHandle, ExitVal, 0, NULL);   /* abort() */\r
-  ExitFunc(gImageHandle, ExitVal, 0, NULL);   /* abort() */\r
+  gBS->Exit(gImageHandle, ExitVal, 0, NULL);   /* abort() */\r
 }\r
 \r
 /** If string is a null pointer, the system function determines whether the\r
@@ -206,3 +203,98 @@ char   *getenv(const char *name)
 \r
   return retval;\r
 }\r
+\r
+\r
+/**\r
+  Add or update a variable in the environment list\r
+\r
+  @param name     Address of a zero terminated name string\r
+  @param value    Address of a zero terminated value string\r
+  @param rewrite  TRUE allows overwriting existing values\r
+\r
+  @retval Returns 0 upon success\r
+  @retval Returns -1 upon failure, sets errno with more information\r
+\r
+  Errors\r
+\r
+  EINVAL - name is NULL or points to a zero length string\r
+  EALREADY - name already set and rewrite set to FALSE\r
+  ENODEV - Unable to set non-volatile version of environment variable\r
+  ENOMEM - Unable to set volatile version of environment variable\r
+  ENOTSUP - Variable storage not supported\r
+\r
+**/\r
+int\r
+setenv (\r
+  register const char * name,\r
+  register const char * value,\r
+  int rewrite\r
+  )\r
+{\r
+  CONST CHAR16 * HostName;\r
+  int retval;\r
+  EFI_STATUS Status;\r
+  CHAR16 * UName;\r
+  CHAR16 * UValue;\r
+\r
+  //\r
+  //  Assume failure\r
+  //\r
+  retval = -1;\r
+\r
+  //\r
+  //  Validate the inputs\r
+  //\r
+  errno = EINVAL;\r
+  if (( NULL != name ) && ( 0 != *name )) {\r
+    //\r
+    //  Get the storage locations for the unicode strings\r
+    //\r
+    UName = &gMD->UString[0];\r
+    UValue = &gMD->UString2[0];\r
+\r
+    //\r
+    //  Convert the strings\r
+    //\r
+    AsciiStrToUnicodeStr ( name, UName );\r
+    AsciiStrToUnicodeStr ( value, UValue );\r
+\r
+    //\r
+    //  Determine if the string is already present\r
+    //\r
+    errno = EALREADY;\r
+    HostName = ShellGetEnvironmentVariable ( UName );\r
+    if ( rewrite || ( NULL == HostName )) {\r
+      //\r
+      //  Support systems that don't have non-volatile memory\r
+      //\r
+      errno = ENOMEM;\r
+      Status = ShellSetEnvironmentVariable ( UName, UValue, TRUE );\r
+      if ( EFI_ERROR ( Status )) {\r
+        if ( EFI_UNSUPPORTED == Status ) {\r
+          errno = ENOTSUP;\r
+        }\r
+      }\r
+      else {\r
+        //\r
+        //  Permanently set the environment variable\r
+        //\r
+        errno = ENODEV;\r
+        Status = ShellSetEnvironmentVariable ( UName, UValue, FALSE );\r
+        if ( !EFI_ERROR ( Status )) {\r
+          //\r
+          //  Success\r
+          //\r
+          errno = 0;\r
+          retval = 0;\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  //\r
+  //  Return the operation status\r
+  //\r
+  return retval;\r
+}\r
+\r
index 56eaae32914880244b73d4de1e387cf3749f24ba..9d2adef1f63739d85b3569879cbeee7ec579c9d4 100644 (file)
@@ -70,6 +70,9 @@
   vprintf.c           #\r
   vsprintf.c          #\r
 \r
+  snprintf.c\r
+  vsnprintf.c\r
+\r
   # Wide character functions\r
   fgetwc.c            #\r
   fgetws.c            #\r
index bda0d04ce816686cf0414f746380b32f5183ac4c..469dc8c96a599735f2c29f9b0e3b6de2b6af8ff9 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
     Implementation of clearerr as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
@@ -47,6 +47,7 @@
 \r
 #include <assert.h>\r
 #include <stdio.h>\r
+#include  <errno.h>\r
 #include "reentrant.h"\r
 #include "local.h"\r
 \r
 void\r
 clearerr(FILE *fp)\r
 {\r
-  //_DIAGASSERT(fp != NULL);\r
-\r
+  _DIAGASSERT(fp != NULL);\r
+  if(fp != NULL) {\r
   FLOCKFILE(fp);\r
   __sclearerr(fp);\r
   FUNLOCKFILE(fp);\r
+  }\r
 }\r
index 3745e20f94e2b8306eb6e110dc16fbf4aeda774c..1ce28bcab4c3d10755a6879af8893cf29f5f1b6c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
     Implementation of fclose as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
@@ -59,6 +59,10 @@ fclose(FILE *fp)
   int r;\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   if (fp->_flags == 0) {  /* not open! */\r
     errno = EBADF;\r
index 70b5e5090e315bee0c543a4b3a3c585f6e7a2a4e..7850e3926829cd1c7d9ae3e96f2c6c9c00f1eb83 100644 (file)
@@ -2,7 +2,7 @@
     Implementation of a subroutine version of the macro feof,\r
     as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
@@ -48,6 +48,7 @@
 \r
 #include <assert.h>\r
 #include <stdio.h>\r
+#include  <errno.h>\r
 #include "reentrant.h"\r
 #include "local.h"\r
 \r
@@ -59,6 +60,10 @@ feof(FILE *fp)
   int r;\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   FLOCKFILE(fp);\r
   r = __sfeof(fp);\r
index 5641b48038f909e661d32bdb46df1082b8e3e457..4a3996fadd800185b3f61331b57f6091a165fd73 100644 (file)
@@ -2,7 +2,7 @@
     Implementation of a subroutine version of the macro ferror,\r
     as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
@@ -48,6 +48,7 @@
 \r
 #include <assert.h>\r
 #include <stdio.h>\r
+#include  <errno.h>\r
 #include "reentrant.h"\r
 #include "local.h"\r
 \r
@@ -59,6 +60,10 @@ ferror(FILE *fp)
   int r;\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   FLOCKFILE(fp);\r
   r = __sferror(fp);\r
index fd21e37a1330a18e5aaeaf47a1bc7c9985d453d3..5a4d62468eddc6c7328bd22a304a7f93722fef9e 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Implementation of fflush as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -87,6 +87,10 @@ __sflush(FILE *fp)
   int   t;\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   t = fp->_flags;\r
   if ((t & __SWR) == 0)\r
index b6e1a258ba27a00c03f065971c530d6cccd4fa5e..aee896fea5f75517313f1ffa043fe6ed15508429 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Implementation of fgetc as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -58,8 +58,14 @@ fgetc(FILE *fp)
 \r
   _DIAGASSERT(fp != NULL);\r
 \r
+  if(fp != NULL) {\r
   FLOCKFILE(fp);\r
   r = __sgetc(fp);\r
   FUNLOCKFILE(fp);\r
+  }\r
+  else {\r
+    r = EOF;\r
+    errno = ENOSTR;\r
+  }\r
   return r;\r
 }\r
index f076718278e4962f25e14c09c4172c7289ee106d..61d6f756d0fd4e4bcd9ca105a375dfdcdfced30c 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Implementation of fgetpos as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -56,5 +56,10 @@ fgetpos(FILE *fp, fpos_t *pos)
   _DIAGASSERT(fp != NULL);\r
   _DIAGASSERT(pos != NULL);\r
 \r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
+\r
   return((*pos = (off_t)ftello(fp)) == (off_t)-1);\r
 }\r
index cf107ab8678794829aa257c0845e6ea37c63e979..cb07154ada467a36d406a0b0b6f56f531ca316b9 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Implementation of fgets as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -48,6 +48,7 @@
 #include <assert.h>\r
 #include <stdio.h>\r
 #include <string.h>\r
+#include  <errno.h>\r
 #include "reentrant.h"\r
 #include "local.h"\r
 \r
@@ -65,8 +66,10 @@ fgets(char *buf, int n, FILE *fp)
 \r
   _DIAGASSERT(buf != NULL);\r
   _DIAGASSERT(fp != NULL);\r
-  if (n <= 0)         /* sanity check */\r
+  if ((fp == NULL) || (n <= 0)) {        /* sanity check */\r
+    errno = EINVAL;\r
     return (NULL);\r
+  }\r
 \r
   FLOCKFILE(fp);\r
   _SET_ORIENTATION(fp, -1);\r
index 7364d3b8910045236f2c6de24e2bb65b7030b8d9..9e898f3263bce5f693a0f218b1d673702311b9c4 100644 (file)
@@ -1,6 +1,13 @@
-/*  $NetBSD: fgetstr.c,v 1.4 2006/11/24 19:46:58 christos Exp $ */\r
+/*\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-/*-\r
  * Copyright (c) 1990, 1993\r
  *  The Regents of the University of California.  All rights reserved.\r
  *\r
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
  * SUCH DAMAGE.\r
+\r
+    $NetBSD: fgetstr.c,v 1.4 2006/11/24 19:46:58 christos Exp $\r
+    fgetline.c  8.1 (Berkeley) 6/4/93\r
+*/\r
+\r
+/*-\r
  */\r
 #include  <LibConfig.h>\r
 #include <sys/EfiCdefs.h>\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-#if 0\r
-static char sccsid[] = "@(#)fgetline.c  8.1 (Berkeley) 6/4/93";\r
-#else\r
-__RCSID("$NetBSD: fgetstr.c,v 1.4 2006/11/24 19:46:58 christos Exp $");\r
-#endif\r
-#endif /* LIBC_SCCS and not lint */\r
 \r
 #include "namespace.h"\r
 \r
 #include <assert.h>\r
+#include  <errno.h>\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
 #include <string.h>\r
@@ -66,6 +73,10 @@ __slbexpand(FILE *fp, size_t newsize)
   ++newsize;\r
 #endif\r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (-1);\r
+  }\r
 \r
   if ((size_t)fp->_lb._size >= newsize)\r
     return (0);\r
@@ -92,6 +103,10 @@ __fgetstr(FILE *fp, size_t *lenp, int sep)
 \r
   _DIAGASSERT(fp != NULL);\r
   _DIAGASSERT(lenp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (NULL);\r
+  }\r
 \r
   /* make sure there is input */\r
   if (fp->_r <= 0 && __srefill(fp)) {\r
index 548192390dd2f810a9f76d2fdae8e48c4a390e17..f2159d7e415477d19e9f36b5ffb736e3a7144a37 100644 (file)
@@ -1,4 +1,13 @@
 /*-\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
  * Copyright (c)2001 Citrus Project,\r
  * All rights reserved.\r
  *\r
@@ -46,6 +55,10 @@ __fgetwc_unlock(FILE *fp)
   size_t size;\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = ENOSTR;\r
+    return WEOF;\r
+  }\r
 \r
   _SET_ORIENTATION(fp, 1);\r
   wcio = WCIO_GET(fp);\r
@@ -91,6 +104,10 @@ fgetwc(FILE *fp)
   wint_t r;\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (WEOF);\r
+  }\r
 \r
   FLOCKFILE(fp);\r
   r = __fgetwc_unlock(fp);\r
index 0113557965c0bff0a3891148201944389633e424..44a885ac54cb27692618e0541067a721dce52a99 100644 (file)
@@ -1,6 +1,13 @@
-/* $NetBSD: fgetws.c,v 1.2 2006/07/03 17:06:36 tnozaki Exp $ */\r
+/*\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-/*-\r
  * Copyright (c) 2002 Tim J. Robbins.\r
  * All rights reserved.\r
  *\r
  *\r
  * Original version ID:\r
  * FreeBSD: src/lib/libc/stdio/fgetws.c,v 1.4 2002/09/20 13:25:40 tjr Exp\r
- *\r
- */\r
+\r
+    $NetBSD: fgetws.c,v 1.2 2006/07/03 17:06:36 tnozaki Exp $\r
+*/\r
 #include  <LibConfig.h>\r
 #include <sys/EfiCdefs.h>\r
-#if defined(LIB_SCCS) && !defined(lint)\r
-__RCSID("$NetBSD: fgetws.c,v 1.2 2006/07/03 17:06:36 tnozaki Exp $");\r
-#endif\r
 \r
 #include <assert.h>\r
 #include <errno.h>\r
@@ -54,6 +59,10 @@ fgetws(
 \r
   _DIAGASSERT(fp != NULL);\r
   _DIAGASSERT(ws != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (NULL);\r
+  }\r
 \r
   FLOCKFILE(fp);\r
   _SET_ORIENTATION(fp, 1);\r
index b9468c7cfc93273413acdb7ef7e430a76173f1cc..779cbd86829b0cb61b4a8bf13f9555480248eefc 100644 (file)
@@ -1,6 +1,13 @@
-/*  $NetBSD: fileno.c,v 1.12 2004/05/09 17:27:53 kleink Exp $ */\r
+/*\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-/*-\r
  * Copyright (c) 1990, 1993\r
  *  The Regents of the University of California.  All rights reserved.\r
  *\r
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
  * SUCH DAMAGE.\r
- */\r
+\r
+    NetBSD: fileno.c,v 1.12 2004/05/09 17:27:53 kleink Exp\r
+    fileno.c  8.1 (Berkeley) 6/4/93\r
+*/\r
 #include  <LibConfig.h>\r
 #include <sys/EfiCdefs.h>\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-#if 0\r
-static char sccsid[] = "@(#)fileno.c  8.1 (Berkeley) 6/4/93";\r
-#else\r
-__RCSID("$NetBSD: fileno.c,v 1.12 2004/05/09 17:27:53 kleink Exp $");\r
-#endif\r
-#endif /* LIBC_SCCS and not lint */\r
 \r
 #include "namespace.h"\r
 #include <assert.h>\r
@@ -63,6 +66,10 @@ _fileno(fp)
   int r;\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   FLOCKFILE(fp);\r
   r = __sfileno(fp);\r
index c1ce12be2ece393d3cc47856830e65976ec537b2..be1a42fb6b0ca409ca80cdfd57dd082b61271271 100644 (file)
@@ -1,6 +1,13 @@
-/*  $NetBSD: fparseln.c,v 1.5 2004/06/20 22:20:15 jmc Exp $ */\r
-\r
 /*\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
  * Copyright (c) 1997 Christos Zoulas.  All rights reserved.\r
  *\r
  * Redistribution and use in source and binary forms, with or without\r
  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- */\r
+\r
+    NetBSD: fparseln.c,v 1.5 2004/06/20 22:20:15 jmc Exp\r
+*/\r
 #include  <LibConfig.h>\r
 #include <sys/EfiCdefs.h>\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-__RCSID("$NetBSD: fparseln.c,v 1.5 2004/06/20 22:20:15 jmc Exp $");\r
-#endif /* LIBC_SCCS and not lint */\r
 \r
 #include "namespace.h"\r
 \r
@@ -107,6 +113,10 @@ fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)
   char  esc, con, nl, com;\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (NULL);\r
+  }\r
 \r
   len = 0;\r
   buf = NULL;\r
index ba6ec0c22e5387612d99a7346734c6977b9e715a..7134c5c5e63a3a900fbba602d43b0d4ef162e2ef 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Implementation of fprintf as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -58,6 +58,10 @@ fprintf(FILE *fp, const char *fmt, ...)
 \r
   _DIAGASSERT(fp != NULL);\r
   _DIAGASSERT(fmt != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   va_start(ap, fmt);\r
   ret = vfprintf(fp, fmt, ap);\r
index cc649eee49744e9fe7b10a432ef977500331b947..48c5482a7ca890bf9dc8fa2c93469e66bf86b5bc 100644 (file)
@@ -1,6 +1,13 @@
-/*  $NetBSD: fpurge.c,v 1.13 2003/08/07 16:43:24 agc Exp $  */\r
+/*\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-/*-\r
  * Copyright (c) 1990, 1993\r
  *  The Regents of the University of California.  All rights reserved.\r
  *\r
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
  * SUCH DAMAGE.\r
- */\r
+\r
+    NetBSD: fpurge.c,v 1.13 2003/08/07 16:43:24 agc Exp\r
+    fpurge.c  8.1 (Berkeley) 6/4/93\r
+*/\r
 #include  <LibConfig.h>\r
 #include <sys/EfiCdefs.h>\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-#if 0\r
-static char sccsid[] = "@(#)fpurge.c  8.1 (Berkeley) 6/4/93";\r
-#else\r
-__RCSID("$NetBSD: fpurge.c,v 1.13 2003/08/07 16:43:24 agc Exp $");\r
-#endif\r
-#endif /* LIBC_SCCS and not lint */\r
 \r
 #include <assert.h>\r
 #include <errno.h>\r
@@ -59,6 +62,10 @@ fpurge(fp)
 {\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   if (fp->_flags == 0) {\r
     errno = EBADF;\r
index b9ae5aa8286c2ef09d226859cd866c4bfd000c25..a7dfdef485cb7e04f6cef95ef3aed03d5d5f5f7d 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Implementation of fputc as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -58,8 +58,14 @@ fputc(int c, FILE *fp)
 \r
   _DIAGASSERT(fp != NULL);\r
 \r
+  if(fp != NULL) {\r
   FLOCKFILE(fp);\r
   r = __sputc(c, fp);\r
   FUNLOCKFILE(fp);\r
+  }\r
+  else {\r
+    r = EOF;\r
+    errno = ENOSTR;\r
+  }\r
   return r;\r
 }\r
index 081ee1a099e47ba826c2e0ed22db80c58316f71c..56e622276a014b8b262219eb428c1f1f1cda19a7 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Implementation of fputs as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -65,6 +65,10 @@ fputs(const char *s, FILE *fp)
 \r
   _DIAGASSERT(s != NULL);\r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   if (s == NULL)\r
     s = "(null)";\r
index 49f670222734074b10134073ef8bde9432b9eeac..8bbd407362f3346801047380132b9cbdaa074567 100644 (file)
@@ -1,6 +1,13 @@
-/* $NetBSD: fputwc.c,v 1.4 2005/06/12 05:21:27 lukem Exp $ */\r
+/*\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-/*-\r
  * Copyright (c)2001 Citrus Project,\r
  * All rights reserved.\r
  *\r
  * SUCH DAMAGE.\r
  *\r
  * $Citrus$\r
- */\r
+\r
+NetBSD: fputwc.c,v 1.4 2005/06/12 05:21:27 lukem Exp\r
+*/\r
 #include  <LibConfig.h>\r
 #include <sys/EfiCdefs.h>\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-__RCSID("$NetBSD: fputwc.c,v 1.4 2005/06/12 05:21:27 lukem Exp $");\r
-#endif /* LIBC_SCCS and not lint */\r
 \r
 #include <assert.h>\r
 #include <errno.h>\r
@@ -53,6 +59,10 @@ __fputwc_unlock(wchar_t wc, FILE *fp)
   struct __siov iov;\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (WEOF);\r
+  }\r
 \r
   /* LINTED we don't play with buf */\r
   iov.iov_base = (void *)buf;\r
@@ -91,6 +101,10 @@ fputwc(wchar_t wc, FILE *fp)
   wint_t r;\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (WEOF);\r
+  }\r
 \r
   FLOCKFILE(fp);\r
   r = __fputwc_unlock(wc, fp);\r
index ce373bb4027caa714ff05260200de039999041e2..ddfc5ddd304dc0740c95402ce1f32b5e245383f1 100644 (file)
@@ -1,6 +1,13 @@
-/* $NetBSD: fputws.c,v 1.1 2003/03/07 07:11:37 tshiozak Exp $ */\r
+/*\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-/*-\r
  * Copyright (c) 2002 Tim J. Robbins.\r
  * All rights reserved.\r
  *\r
  *\r
  * Original version ID:\r
  * FreeBSD: src/lib/libc/stdio/fputws.c,v 1.4 2002/09/20 13:25:40 tjr Exp\r
- */\r
+    NetBSD: fputws.c,v 1.1 2003/03/07 07:11:37 tshiozak Exp\r
+*/\r
 #include  <LibConfig.h>\r
 #include <sys/EfiCdefs.h>\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-__RCSID("$NetBSD: fputws.c,v 1.1 2003/03/07 07:11:37 tshiozak Exp $");\r
-#endif\r
 \r
 #include <assert.h>\r
 #include <errno.h>\r
@@ -49,6 +54,10 @@ fputws(
 {\r
   _DIAGASSERT(fp != NULL);\r
   _DIAGASSERT(ws != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   FLOCKFILE(fp);\r
   _SET_ORIENTATION(fp, 1);\r
index 21013d7ff471d20a8137cfdfa26e069f0450816a..7693ab3c06cefbd0466c317214481f334d1c0e15 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Implementation of fread as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -61,6 +61,10 @@ fread(void *buf, size_t size, size_t count, FILE *fp)
   size_t total;\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (0);\r
+  }\r
   /*\r
    * The ANSI standard requires a return value of 0 for a count\r
    * or a size of 0.  Whilst ANSI imposes no such requirements on\r
index 186ab9ad66079174374e8f8803a2096dccac1792..4d34497317bc062efa57056021d60a872edc9404 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Implementation of freopen as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -73,6 +73,10 @@ freopen(const char *file, const char *mode, FILE *fp)
   _DIAGASSERT(file != NULL);\r
   _DIAGASSERT(mode != NULL);\r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (NULL);\r
+  }\r
 \r
   if ((flags = __sflags(mode, &oflags)) == 0) {\r
     (void) fclose(fp);\r
index 3c406eaec83d14b36999fb66b6bb95ab966e0c90..7fc7e426616f428cbc62a14d89ce173da9dadad6 100644 (file)
@@ -1,6 +1,13 @@
-/*  $NetBSD: fseeko.c,v 1.5 2005/03/04 16:04:58 dsl Exp $ */\r
+/*\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-/*-\r
  * Copyright (c) 1990, 1993\r
  *  The Regents of the University of California.  All rights reserved.\r
  *\r
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
  * SUCH DAMAGE.\r
+\r
+    NetBSD: fseeko.c,v 1.5 2005/03/04 16:04:58 dsl Exp\r
  */\r
 //#include <Uefi.h>               // REMOVE, For DEBUG only\r
 //#include <Library/UefiLib.h>    // REMOVE, For DEBUG only\r
 \r
 #include  <LibConfig.h>\r
 #include <sys/EfiCdefs.h>\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-__RCSID("$NetBSD: fseeko.c,v 1.5 2005/03/04 16:04:58 dsl Exp $");\r
-#endif /* LIBC_SCCS and not lint */\r
 \r
 #include "namespace.h"\r
 #include <sys/types.h>\r
@@ -72,6 +78,10 @@ fseeko(FILE *fp, off_t offset, int whence)
   int havepos;\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return -1;\r
+  }\r
 \r
 #ifdef __GNUC__\r
   /* This outrageous construct just to shut up a GCC warning. */\r
index fcbb25606791de1c5da909b11599824de4bc26e6..12773eff68e23470f1ac71ad36515c397feac711 100644 (file)
@@ -1,6 +1,13 @@
-/*  $NetBSD: fvwrite.c,v 1.16.2.1 2007/05/07 19:49:09 pavel Exp $ */\r
+/*\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-/*-\r
  * Copyright (c) 1990, 1993\r
  *  The Regents of the University of California.  All rights reserved.\r
  *\r
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
  * SUCH DAMAGE.\r
- */\r
+\r
+    NetBSD: fvwrite.c,v 1.16.2.1 2007/05/07 19:49:09 pavel Exp\r
+    fvwrite.c 8.1 (Berkeley) 6/4/93\r
+*/\r
 #include  <LibConfig.h>\r
 #include <sys/EfiCdefs.h>\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-#if 0\r
-static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93";\r
-#else\r
-__RCSID("$NetBSD: fvwrite.c,v 1.16.2.1 2007/05/07 19:49:09 pavel Exp $");\r
-#endif\r
-#endif /* LIBC_SCCS and not lint */\r
 \r
 #include <assert.h>\r
 #include <errno.h>\r
@@ -68,6 +71,10 @@ __sfvwrite(FILE *fp, struct __suio *uio)
 \r
   _DIAGASSERT(fp != NULL);\r
   _DIAGASSERT(uio != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   if ((len = uio->uio_resid) == 0)\r
     return (0);\r
index b89b7a3811cc1a4672b5a16f83011a1d8f8ba3c1..4ba1423eb2addf4ec354b8d03cc186629af9ff4b 100644 (file)
@@ -1,6 +1,13 @@
-/* $NetBSD: fwide.c,v 1.3 2005/06/12 05:21:27 lukem Exp $ */\r
+/*\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-/*-\r
  * Copyright (c)2001 Citrus Project,\r
  * All rights reserved.\r
  *\r
  * SUCH DAMAGE.\r
  *\r
  * $Citrus$\r
- */\r
+\r
+    NetBSD: fwide.c,v 1.3 2005/06/12 05:21:27 lukem Exp\r
+*/\r
 #include  <LibConfig.h>\r
 #include <sys/EfiCdefs.h>\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-__RCSID("$NetBSD: fwide.c,v 1.3 2005/06/12 05:21:27 lukem Exp $");\r
-#endif /* LIBC_SCCS and not lint */\r
 \r
 #include <assert.h>\r
+#include  <errno.h>\r
 #include <stdio.h>\r
 #include <wchar.h>\r
 #include "reentrant.h"\r
@@ -45,6 +52,10 @@ fwide(FILE *fp, int mode)
   struct wchar_io_data *wcio;\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (0);\r
+  }\r
 \r
   /*\r
    * this implementation use only -1, 0, 1\r
index 9416e67aea1ddd99827eb7aaacc740c5df35ad85..c998e272b67979d281a85183191bfd83702d4606 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Implementation of fwrite as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -64,6 +64,11 @@ fwrite(const void *buf, size_t size, size_t count, FILE *fp)
   struct __siov iov;\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (0);\r
+  }\r
+\r
   /*\r
    * SUSv2 requires a return value of 0 for a count or a size of 0.\r
    */\r
index c0f367b892b27df6409f019a87b5b972d93d054b..755251eef721ca6d76f4a0e52fbc464194dad843 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Implementation of getc as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -63,6 +63,10 @@ getc(FILE *fp)
   int r;\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = ENOSTR;\r
+    return (EOF);\r
+  }\r
 \r
   FLOCKFILE(fp);\r
   r = __sgetc(fp);\r
@@ -75,6 +79,10 @@ getc_unlocked(FILE *fp)
 {\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = ENOSTR;\r
+    return EOF;\r
+  }\r
 \r
   return (__sgetc(fp));\r
 }\r
index 75c475c3a5ef7282302c04848c27f50907753556..4e69be127579cfad9e57566787b48e91589cc9a7 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Implementation of internal file buffer allocation functions.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -74,6 +74,7 @@ __smakebuf(FILE *fp)
 \r
   _DIAGASSERT(fp != NULL);\r
 \r
+  if (fp != NULL) {\r
   if (fp->_flags & __SNBF) {\r
     fp->_bf._base = fp->_p = fp->_nbuf;\r
     fp->_bf._size = 1;\r
@@ -93,6 +94,7 @@ __smakebuf(FILE *fp)
   if (couldbetty || isatty(fp->_file))\r
     flags |= __SLBF;\r
   fp->_flags |= flags;\r
+  }\r
 }\r
 \r
 /*\r
@@ -106,6 +108,9 @@ __swhatbuf(FILE *fp, size_t *bufsize, int *couldbetty)
   _DIAGASSERT(fp != NULL);\r
   _DIAGASSERT(bufsize != NULL);\r
   _DIAGASSERT(couldbetty != NULL);\r
+  if(fp == NULL) {\r
+    return (__SNPT);\r
+  }\r
 \r
   if (fp->_file < 0 || fstat(fp->_file, &st) < 0) {\r
     *couldbetty = 0;\r
index 891e747a566a9fb794f021f6b000d083608bdf94..25f49f86469f570d1dedd207e0481bddb5f33e5a 100644 (file)
@@ -2,11 +2,11 @@
     Implementation of a subroutine version of the macro putc,\r
     as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -64,6 +64,10 @@ putc(int c, FILE *fp)
   int r;\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   FLOCKFILE(fp);\r
   r = __sputc(c, fp);\r
@@ -75,6 +79,10 @@ int
 putc_unlocked(int c, FILE *fp)\r
 {\r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   return (__sputc(c, fp));\r
 }\r
index e2d162375bfbf14edc36bcfcc51fe43fd9f1788e..953e8f674a8f608edeb79ab0254fa1c6bd1e7e22 100644 (file)
@@ -1,6 +1,13 @@
-/*  $NetBSD: refill.c,v 1.13 2003/08/07 16:43:30 agc Exp $  */\r
+/*\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-/*-\r
  * Copyright (c) 1990, 1993\r
  *  The Regents of the University of California.  All rights reserved.\r
  *\r
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
  * SUCH DAMAGE.\r
- */\r
+\r
+    NetBSD: refill.c,v 1.13 2003/08/07 16:43:30 agc Exp\r
+    refill.c  8.1 (Berkeley) 6/4/93\r
+*/\r
 #include <Uefi.h>               // REMOVE, For DEBUG only\r
 #include <Library/UefiLib.h>    // REMOVE, For DEBUG only\r
 \r
 #include  <LibConfig.h>\r
 #include <sys/EfiCdefs.h>\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-#if 0\r
-static char sccsid[] = "@(#)refill.c  8.1 (Berkeley) 6/4/93";\r
-#else\r
-__RCSID("$NetBSD: refill.c,v 1.13 2003/08/07 16:43:30 agc Exp $");\r
-#endif\r
-#endif /* LIBC_SCCS and not lint */\r
 \r
 #include <assert.h>\r
 #include <errno.h>\r
@@ -61,7 +64,11 @@ static int
 lflush(FILE *fp)\r
 {\r
 \r
-  //_DIAGASSERT(fp != NULL);\r
+  _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR))\r
     return (__sflush(fp));\r
@@ -76,7 +83,11 @@ int
 __srefill(FILE *fp)\r
 {\r
 \r
-  //_DIAGASSERT(fp != NULL);\r
+  _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   /* make sure stdio is set up */\r
   if (!__sdidinit)\r
index 4f2ab041a20c5093bf546f09ba98c26ff945b086..5d1042152b0fc214636f019ef1cdd618c7d46f51 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Implementation of rewind as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -56,8 +56,10 @@ rewind(FILE *fp)
 {\r
   _DIAGASSERT(fp != NULL);\r
 \r
+  if(fp != NULL) {\r
   FLOCKFILE(fp);\r
   (void) fseek(fp, 0L, SEEK_SET);\r
   __sclearerr(fp);\r
   FUNLOCKFILE(fp);\r
+  }\r
 }\r
index ba97ac201b16a918decebb22bc4eb5c38d6398b8..74f73dcac4330f2e59c6d49706cdd13641dfbb0d 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Internal function to refill the buffer when getc() empties it.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -61,10 +61,12 @@ __srget(FILE *fp)
 {\r
   _DIAGASSERT(fp != NULL);\r
 \r
+  if(fp != NULL) {\r
   _SET_ORIENTATION(fp, -1);\r
   if (__srefill(fp) == 0) {\r
     fp->_r--;\r
     return (*fp->_p++);\r
+    }\r
   }\r
   return (EOF);\r
 }\r
index 3ea96ff6da6bcd7c6df3697039772a775f9b5e52..9e01ea9dc1f693b688799fca6a075cd3ea28dfb9 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Implementation of setvbuf as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -67,6 +67,10 @@ setvbuf(FILE *fp, char *buf, int mode, size_t size)
 \r
   _DIAGASSERT(fp != NULL);\r
   /* buf may be NULL */\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   /*\r
    * Verify arguments.  The `int' limit on `size' is due to this\r
index 005a4388df4129b5559db7b5847218d0dae106dd..de8963e57404f238463237c98f2510e8d2d8a5d4 100644 (file)
@@ -2,11 +2,11 @@
     Small standard I/O/seek/close functions.\r
     These maintain the `known seek offset' for seek optimisation.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -65,6 +65,10 @@ __sread(void *cookie, char *buf, int n)
 \r
   _DIAGASSERT(fp != NULL);\r
   _DIAGASSERT(buf != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   ret = (int)read(fp->_file, buf, (size_t)n);\r
   /* if the read succeeded, update the current offset */\r
@@ -82,6 +86,10 @@ __swrite(void *cookie, char const *buf, int n)
 \r
   _DIAGASSERT(cookie != NULL);\r
   _DIAGASSERT(buf != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   if (fp->_flags & __SAPP)\r
     (void) lseek(fp->_file, (off_t)0, SEEK_END);\r
@@ -96,6 +104,10 @@ __sseek(void *cookie, fpos_t offset, int whence)
   off_t ret;\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   ret = lseek(fp->_file, (off_t)offset, whence);\r
   if (ret == -1L)\r
@@ -112,6 +124,10 @@ __sclose(void *cookie)
 {\r
 \r
   _DIAGASSERT(cookie != NULL);\r
+  if(cookie == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   return (close(((FILE *)cookie)->_file));\r
 }\r
index bfcf77c49d5c6593b038df7e987a6e3c34cb9c7c..97040d58f210b82da2912aea1da931a62589e020 100644 (file)
@@ -68,8 +68,12 @@ tmpfile()
   //(void)sigprocmask(SIG_BLOCK, &set, &oset);\r
 \r
   fd = mkstemp(buf);\r
-  if (fd != -1)\r
-    (void)unlink(buf);\r
+  if (fd != -1) {\r
+    /*  Changed from unlink(buf) because of differences between the behavior\r
+        of Unix and UEFI file systems.\r
+    */\r
+    (void)DeleteOnClose(fd);\r
+  }\r
 \r
   //(void)sigprocmask(SIG_SETMASK, &oset, NULL);\r
 \r
index e9d3807fcb63e5d41c76a08583581267d87d0b39..d8e1f3afc61acef871bf3bd99280a95ea94b19fb 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Implementation of ungetc as declared in <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -67,6 +67,10 @@ __submore(FILE *fp)
   unsigned char *p;\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   if (_UB(fp)._base == fp->_ubuf) {\r
     /*\r
@@ -98,6 +102,10 @@ int
 ungetc(int c, FILE *fp)\r
 {\r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   if (c == EOF)\r
     return (EOF);\r
index 724fd2a7474b539f3a8140786c46638c8b18429e..861fb5330176cb8c5ff0afd9fc183fc4849b7418 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Implementation of scanf internals for <stdio.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available\r
     under the terms and conditions of the BSD License that accompanies this\r
     distribution.  The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
     FreeBSD: src/lib/libc/stdio/vfscanf.c,v 1.41 2007/01/09 00:28:07 imp Exp\r
     vfscanf.c 8.1 (Berkeley) 6/4/93\r
 **/\r
-//#include <Uefi.h>               // REMOVE, For DEBUG only\r
-//#include <Library/UefiLib.h>    // REMOVE, For DEBUG only\r
-\r
 #include  <LibConfig.h>\r
 \r
 #include "namespace.h"\r
 #include <assert.h>\r
 #include <ctype.h>\r
+#include  <errno.h>\r
 #include <inttypes.h>\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
@@ -142,6 +140,10 @@ __svfscanf(FILE *fp, char const *fmt0, va_list ap)
 {\r
   int ret;\r
 \r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
   FLOCKFILE(fp);\r
   ret = __svfscanf_unlocked(fp, fmt0, ap);\r
   FUNLOCKFILE(fp);\r
@@ -178,6 +180,10 @@ __svfscanf_unlocked(FILE *fp, const char *fmt0, va_list ap)
 \r
   _DIAGASSERT(fp != NULL);\r
   _DIAGASSERT(fmt0 != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   _SET_ORIENTATION(fp, -1);\r
 \r
@@ -837,12 +843,12 @@ literal:
         goto match_failure;\r
       if ((flags & SUPPRESS) == 0) {\r
         if (flags & LONGDBL) {\r
-/*dvm*/   long double **mp = (long double **)ap;\r
+          long double **mp = (long double **)ap;\r
           long double res = strtold(buf, &p);\r
 \r
-/*dvm*/   *(*mp) = res;\r
-/*dvm*/   ap += sizeof(long double *);\r
-/*dvm*/   //*va_arg(ap, long double *) = res;\r
+          *(*mp) = res;\r
+          ap += sizeof(long double *);\r
+/*???*/   //*va_arg(ap, long double *) = res;\r
         } else if (flags & LONG) {\r
           double res = strtod(buf, &p);\r
           *va_arg(ap, double *) = res;\r
@@ -989,6 +995,11 @@ parsefloat(FILE *fp, char *buf, char *end)
   char decpt = *localeconv()->decimal_point;\r
   _Bool gotmantdig = 0, ishex = 0;\r
 \r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
+\r
   /*\r
    * We set commit = p whenever the string we have read so far\r
    * constitutes a valid representation of a floating point\r
index bf31ddb664897ec4b4cac8c6138beda8d0b0d6af..3c5332ac4aab50d5c7cb68b498832b8c41a89654 100644 (file)
@@ -164,6 +164,10 @@ __sbprintf(FILE *fp, const CHAR_T *fmt, va_list ap)
 \r
   _DIAGASSERT(fp != NULL);\r
   _DIAGASSERT(fmt != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   _FILEEXT_SETUP(&fake, &fakeext);\r
 \r
@@ -229,6 +233,10 @@ __sprint(FILE *fp, struct __suio *uio)
 \r
   _DIAGASSERT(fp != NULL);\r
   _DIAGASSERT(uio != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   if (uio->uio_resid == 0) {\r
     uio->uio_iovcnt = 0;\r
@@ -544,6 +552,10 @@ WDECL(vf,printf)(FILE * __restrict fp, const CHAR_T * __restrict fmt0, va_list a
 {\r
   int ret;\r
 \r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
   FLOCKFILE(fp);\r
   ret = WDECL(__vf,printf_unlocked)(fp, fmt0, ap);\r
   FUNLOCKFILE(fp);\r
@@ -801,6 +813,10 @@ WDECL(__vf,printf_unlocked)(FILE *fp, const CHAR_T *fmt0, va_list ap)
 \r
   _DIAGASSERT(fp != NULL);\r
   _DIAGASSERT(fmt0 != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   _SET_ORIENTATION(fp, -1);\r
 \r
index b2a2f63a9124b6e023e017a2cbf181a5cbe8f3ce..23385ba0d8d3fde1c41378cd94fac06382564b1b 100644 (file)
@@ -54,11 +54,7 @@ __weak_alias(vsnprintf,_vsnprintf)
 #endif\r
 \r
 int\r
-vsnprintf(str, n, fmt, ap)\r
-  char *str;\r
-  size_t n;\r
-  const char *fmt;\r
-  _BSD_VA_LIST_ ap;\r
+vsnprintf(char *str, size_t n, const char *fmt, _BSD_VA_LIST_ ap)\r
 {\r
   int ret;\r
   FILE f;\r
@@ -81,7 +77,7 @@ vsnprintf(str, n, fmt, ap)
     f._bf._size = f._w = 0;\r
   } else {\r
     f._bf._base = f._p = (unsigned char *)str;\r
-    f._bf._size = f._w = n - 1;\r
+    f._bf._size = f._w = (int)(n - 1);\r
   }\r
   ret = __vfprintf_unlocked(&f, fmt, ap);\r
   *f._p = 0;\r
index 8482a18e878f344f21242577d6ad853dd0e5e983..888be1ea3bfdd07e58a27363c141e92936df65b5 100644 (file)
@@ -1,6 +1,13 @@
-/*  $NetBSD: wbuf.c,v 1.13 2003/08/07 16:43:35 agc Exp $  */\r
+/*\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-/*-\r
  * Copyright (c) 1990, 1993\r
  *  The Regents of the University of California.  All rights reserved.\r
  *\r
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
  * SUCH DAMAGE.\r
- */\r
+\r
+    NetBSD: wbuf.c,v 1.13 2003/08/07 16:43:35 agc Exp\r
+    wbuf.c  8.1 (Berkeley) 6/4/93\r
+*/\r
 #include  <LibConfig.h>\r
 #include <sys/EfiCdefs.h>\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-#if 0\r
-static char sccsid[] = "@(#)wbuf.c  8.1 (Berkeley) 6/4/93";\r
-#else\r
-__RCSID("$NetBSD: wbuf.c,v 1.13 2003/08/07 16:43:35 agc Exp $");\r
-#endif\r
-#endif /* LIBC_SCCS and not lint */\r
 \r
 #include <assert.h>\r
 #include <errno.h>\r
@@ -58,6 +61,10 @@ __swbuf(int c, FILE *fp)
   int n;\r
 \r
   //_DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (EOF);\r
+  }\r
 \r
   _SET_ORIENTATION(fp, -1);\r
 \r
index c1077bc9dfe906d4bc193cde0c41dbdf86dad105..b8fc06449ecac6778fc1238ed4aa512c9f01165d 100644 (file)
@@ -1,6 +1,13 @@
-/*  $NetBSD: wsetup.c,v 1.11 2003/08/07 16:43:35 agc Exp $  */\r
+/*\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available\r
+    under the terms and conditions of the BSD License that accompanies this\r
+    distribution.  The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-/*-\r
  * Copyright (c) 1990, 1993\r
  *  The Regents of the University of California.  All rights reserved.\r
  *\r
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
  * SUCH DAMAGE.\r
- */\r
+\r
+    NetBSD: wsetup.c,v 1.11 2003/08/07 16:43:35 agc Exp\r
+    wsetup.c  8.1 (Berkeley) 6/4/93\r
+*/\r
 #include  <LibConfig.h>\r
 #include <sys/EfiCdefs.h>\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-#if 0\r
-static char sccsid[] = "@(#)wsetup.c  8.1 (Berkeley) 6/4/93";\r
-#else\r
-__RCSID("$NetBSD: wsetup.c,v 1.11 2003/08/07 16:43:35 agc Exp $");\r
-#endif\r
-#endif /* LIBC_SCCS and not lint */\r
 \r
 #include <assert.h>\r
 #include <errno.h>\r
@@ -58,6 +61,10 @@ __swsetup(FILE *fp)
 {\r
 \r
   _DIAGASSERT(fp != NULL);\r
+  if(fp == NULL) {\r
+    errno = EINVAL;\r
+    return (-1);\r
+  }\r
 \r
   /* make sure stdio is set up */\r
   if (!__sdidinit)\r
index 2d5200e3c5e7e070a0718da0418707c56b2efbea..18498d6f8783c2efd9e075b99d45777de30b2d4c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
     Copying Functions for <string.h>.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available under\r
     the terms and conditions of the BSD License that accompanies this distribution.\r
     The full text of the license may be found at\r
@@ -10,8 +10,6 @@
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 **/\r
-//#include  <sys/EfiCdefs.h>\r
-\r
 #include  <Uefi.h>\r
 #include  <Library/BaseLib.h>\r
 #include  <Library/BaseMemoryLib.h>\r
 #include  <stdlib.h>\r
 #include  <string.h>\r
 \r
+/** Do not define memcpy for IPF+GCC builds.\r
+    For IPF, using a GCC compiler, the memcpy function is converted to\r
+    CopyMem by objcpy during build.\r
+**/\r
+#if  !(defined(MDE_CPU_IPF) && defined(__GNUC__))\r
 /** The memcpy function copies n characters from the object pointed to by s2\r
     into the object pointed to by s1.\r
 \r
@@ -33,6 +36,7 @@ memcpy(void * __restrict s1, const void * __restrict s2, size_t n)
 {\r
   return CopyMem( s1, s2, n);\r
 }\r
+#endif  /* !(defined(MDE_CPU_IPF) && defined(__GCC)) */\r
 \r
 /** The memmove function copies n characters from the object pointed to by s2\r
     into the object pointed to by s1. Copying takes place as if the n\r
index 1614b1cb11015178f8b13c15e8367a070883ca1d..b6ab66005199f056c5f7aae404c8142791cfdd2c 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 #  Standard C library: Miscelaneous implementations.\r
 #\r
-#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -32,6 +32,7 @@
   Comparison.c\r
   Searching.c\r
   ErrorList.c\r
+  strncasecmp.c\r
 \r
 [Packages]\r
   StdLib/StdLib.dec\r
diff --git a/StdLib/LibC/String/strncasecmp.c b/StdLib/LibC/String/strncasecmp.c
new file mode 100644 (file)
index 0000000..2519df9
--- /dev/null
@@ -0,0 +1,80 @@
+/** @file \r
+  strncasecmp implementation\r
+\r
+  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ * Copyright (c) 1987, 1993\r
+ *     The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+\r
+       $NetBSD: strncasecmp.c,v 1.2 2007/06/04 18:19:27 christos Exp $\r
+  strcasecmp.c 8.1 (Berkeley) 6/4/93\r
+**/\r
+\r
+#include <LibConfig.h>\r
+#include <sys/cdefs.h>\r
+\r
+#if !defined(_KERNEL) && !defined(_STANDALONE)\r
+#include "namespace.h"\r
+#include <assert.h>\r
+#include <ctype.h>\r
+#include <string.h>\r
+#ifdef __weak_alias\r
+__weak_alias(strcasecmp,_strcasecmp)\r
+__weak_alias(strncasecmp,_strncasecmp)\r
+#endif\r
+#else\r
+#include <lib/libkern/libkern.h>\r
+#include <machine/limits.h>\r
+#endif \r
+\r
+int\r
+strncasecmp(const char *s1, const char *s2, size_t n)\r
+{\r
+\r
+       _DIAGASSERT(s1 != NULL);\r
+       _DIAGASSERT(s2 != NULL);\r
+\r
+       if (n != 0) {\r
+               const unsigned char *us1 = (const unsigned char *)s1,\r
+                               *us2 = (const unsigned char *)s2;\r
+\r
+               do {\r
+                       if (tolower(*us1) != tolower(*us2++))\r
+                               return (tolower(*us1) - tolower(*--us2));\r
+                       if (*us1++ == '\0')\r
+                               break;\r
+               } while (--n != 0);\r
+       }\r
+       return (0);\r
+}\r
index 3192696f4a7f3a4762fd99a057ea4be22b2cf097..5cb93477526778a7ee395963fef841e7f75f5c0e 100644 (file)
@@ -1,7 +1,7 @@
 /**\r
   Definitions and Implementation for <time.h>.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials are licensed and made available under\r
   the terms and conditions of the BSD License that accompanies this distribution.\r
   The full text of the license may be found at\r
@@ -199,15 +199,15 @@ clock_t
 EFIAPI\r
 clock(void)\r
 {\r
+#ifndef NT32dvm\r
   clock_t   temp;\r
 \r
-#ifdef NT32dvm\r
-  temp = 0;\r
-#else\r
   temp = (clock_t)GetPerformanceCounter();\r
-#endif  /* NT32dvm */\r
 \r
   return temp - gMD->AppStartTime;\r
+#else\r
+  return (clock_t)-1;\r
+#endif  /* NT32dvm */\r
 }\r
 \r
 /**\r
index 8bbb248bd132a7bb82f0c88b853fb0323f055d2d..6de494f8d4c258e4816a45af8f9d4adf6dd18e28 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 #  Standard C library: Time implementations.\r
 #\r
-#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -29,7 +29,9 @@
   Time.c\r
   ZoneProc.c\r
   strftime.c\r
+  strptime.c\r
   TimeEfi.c\r
+  gettimeofday.c\r
 \r
 [Packages]\r
   StdLib/StdLib.dec\r
diff --git a/StdLib/LibC/Time/gettimeofday.c b/StdLib/LibC/Time/gettimeofday.c
new file mode 100644 (file)
index 0000000..1c379a6
--- /dev/null
@@ -0,0 +1,68 @@
+/** @file \r
+  gettimeofday implementation\r
+\r
+  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan\r
+ * (Royal Institute of Technology, Stockholm, Sweden).\r
+ * All rights reserved.\r
+ * \r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * \r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * \r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * \r
+ * 3. Neither the name of the Institute nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ * \r
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+\r
+  Heimdal: gettimeofday.c 14773 2005-04-12 11:29:18Z lha $\r
+  NetBSD: gettimeofday.c,v 1.2 2008/03/22 08:37:21 mlelstv Exp $\r
+**/\r
+\r
+#include <LibConfig.h>\r
+#include <sys/EfiCdefs.h>\r
+#include <sys/time.h>\r
+#include <time.h>\r
+#ifndef HAVE_GETTIMEOFDAY\r
+\r
+\r
+/*\r
+ * Simple gettimeofday that only returns seconds.\r
+ */\r
+int \r
+gettimeofday (struct timeval *tp, void *ignore)\r
+{\r
+  time_t t;\r
+\r
+  t = time(NULL);\r
+  tp->tv_sec  = t;\r
+  tp->tv_usec = 0;\r
+  return 0;\r
+}\r
+#endif\r
index a9da3e2f7d571dd6ca0cde7ec93990b2310cccfc..6a5e2a34af8c61210a508705a36fb8be5b57d500 100644 (file)
@@ -52,7 +52,7 @@
 #include "namespace.h"\r
 #include <time.h>\r
 #include "tzfile.h"\r
-#include  <TimeVals.h>\r
+#include  "TimeVals.h"\r
 #include "fcntl.h"\r
 #include "locale.h"\r
 \r
diff --git a/StdLib/LibC/Time/strptime.c b/StdLib/LibC/Time/strptime.c
new file mode 100644 (file)
index 0000000..98ca5c6
--- /dev/null
@@ -0,0 +1,400 @@
+/** @file \r
+  strptime implementation\r
+\r
+  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+ * Copyright (c) 1997, 1998, 2005, 2008 The NetBSD Foundation, Inc.\r
+ * All rights reserved.\r
+ *\r
+ * This code was contributed to The NetBSD Foundation by Klaus Klein.\r
+ * Heavily optimised by David Laight\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+\r
+  $NetBSD: strptime.c,v 1.28 2008/04/28 20:23:01 martin Exp $\r
+\r
+**/\r
+\r
+#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
+  #pragma warning ( disable : 4244 )\r
+  #pragma warning ( disable : 4018 )\r
+#endif\r
+\r
+#include <LibConfig.h>\r
+\r
+#include <sys/cdefs.h>\r
+\r
+#include "namespace.h"\r
+#include <time.h>\r
+#include "tzfile.h"\r
+#include <TimeVals.h>\r
+#include <fcntl.h>\r
+\r
+#include <sys/localedef.h>\r
+\r
+#include <ctype.h>\r
+#include <locale.h>\r
+#include <string.h>\r
+\r
+#ifdef __weak_alias\r
+__weak_alias(strptime,_strptime)\r
+#endif\r
+\r
+#define        _ctloc(x)               (_CurrentTimeLocale->x)\r
+\r
+/*\r
+ * We do not implement alternate representations. However, we always\r
+ * check whether a given modifier is allowed for a certain conversion.\r
+ */\r
+#define ALT_E                  0x01\r
+#define ALT_O                  0x02\r
+#define        LEGAL_ALT(x)            { if (alt_format & ~(x)) return NULL; }\r
+\r
+static const unsigned char *conv_num(const unsigned char *, int *, unsigned int, unsigned int);\r
+static const unsigned char *find_string(const unsigned char *, int *, const char * const *,\r
+       const char * const *, int);\r
+\r
+\r
+char *\r
+strptime(const char *buf, const char *fmt, struct tm *tm)\r
+{\r
+       unsigned char c;\r
+       const unsigned char *bp;\r
+       int alt_format, i, split_year = 0;\r
+       const char *new_fmt;\r
+\r
+       bp = (const unsigned char *)buf;\r
+\r
+       while (bp != NULL && (c = *fmt++) != '\0') {\r
+               /* Clear `alternate' modifier prior to new conversion. */\r
+               alt_format = 0;\r
+               i = 0;\r
+\r
+               /* Eat up white-space. */\r
+               if (isspace(c)) {\r
+                       while (isspace(*bp))\r
+                               bp++;\r
+                       continue;\r
+               }\r
+\r
+               if (c != '%')\r
+                       goto literal;\r
+\r
+\r
+again:         switch (c = *fmt++) {\r
+               case '%':       /* "%%" is converted to "%". */\r
+literal:\r
+                       if (c != *bp++)\r
+                               return NULL;\r
+                       LEGAL_ALT(0);\r
+                       continue;\r
+\r
+               /*\r
+                * "Alternative" modifiers. Just set the appropriate flag\r
+                * and start over again.\r
+                */\r
+               case 'E':       /* "%E?" alternative conversion modifier. */\r
+                       LEGAL_ALT(0);\r
+                       alt_format |= ALT_E;\r
+                       goto again;\r
+\r
+               case 'O':       /* "%O?" alternative conversion modifier. */\r
+                       LEGAL_ALT(0);\r
+                       alt_format |= ALT_O;\r
+                       goto again;\r
+\r
+               /*\r
+                * "Complex" conversion rules, implemented through recursion.\r
+                */\r
+               case 'c':       /* Date and time, using the locale's format. */\r
+                       new_fmt = _ctloc(d_t_fmt);\r
+                       goto recurse;\r
+\r
+               case 'D':       /* The date as "%m/%d/%y". */\r
+                       new_fmt = "%m/%d/%y";\r
+                       LEGAL_ALT(0);\r
+                       goto recurse;\r
+\r
+               case 'F':       /* The date as "%Y-%m-%d". */\r
+                       new_fmt = "%Y-%m-%d";\r
+                       LEGAL_ALT(0);\r
+                       goto recurse;\r
+\r
+               case 'R':       /* The time as "%H:%M". */\r
+                       new_fmt = "%H:%M";\r
+                       LEGAL_ALT(0);\r
+                       goto recurse;\r
+\r
+               case 'r':       /* The time in 12-hour clock representation. */\r
+                       new_fmt =_ctloc(t_fmt_ampm);\r
+                       LEGAL_ALT(0);\r
+                       goto recurse;\r
+\r
+               case 'T':       /* The time as "%H:%M:%S". */\r
+                       new_fmt = "%H:%M:%S";\r
+                       LEGAL_ALT(0);\r
+                       goto recurse;\r
+\r
+               case 'X':       /* The time, using the locale's format. */\r
+                       new_fmt =_ctloc(t_fmt);\r
+                       goto recurse;\r
+\r
+               case 'x':       /* The date, using the locale's format. */\r
+                       new_fmt =_ctloc(d_fmt);\r
+                   recurse:\r
+                       bp = (const unsigned char *)strptime((const char *)bp,\r
+                                                           new_fmt, tm);\r
+                       LEGAL_ALT(ALT_E);\r
+                       continue;\r
+\r
+               /*\r
+                * "Elementary" conversion rules.\r
+                */\r
+               case 'A':       /* The day of week, using the locale's form. */\r
+               case 'a':\r
+                       bp = find_string(bp, &tm->tm_wday, _ctloc(day),\r
+                                       _ctloc(abday), 7);\r
+                       LEGAL_ALT(0);\r
+                       continue;\r
+\r
+               case 'B':       /* The month, using the locale's form. */\r
+               case 'b':\r
+               case 'h':\r
+                       bp = find_string(bp, &tm->tm_mon, _ctloc(mon),\r
+                                       _ctloc(abmon), 12);\r
+                       LEGAL_ALT(0);\r
+                       continue;\r
+\r
+               case 'C':       /* The century number. */\r
+                       i = 20;\r
+                       bp = conv_num(bp, &i, 0, 99);\r
+\r
+                       i = i * 100 - TM_YEAR_BASE;\r
+                       if (split_year)\r
+                               i += tm->tm_year % 100;\r
+                       split_year = 1;\r
+                       tm->tm_year = i;\r
+                       LEGAL_ALT(ALT_E);\r
+                       continue;\r
+\r
+               case 'd':       /* The day of month. */\r
+               case 'e':\r
+                       bp = conv_num(bp, &tm->tm_mday, 1, 31);\r
+                       LEGAL_ALT(ALT_O);\r
+                       continue;\r
+\r
+               case 'k':       /* The hour (24-hour clock representation). */\r
+                       LEGAL_ALT(0);\r
+                       /* FALLTHROUGH */\r
+               case 'H':\r
+                       bp = conv_num(bp, &tm->tm_hour, 0, 23);\r
+                       LEGAL_ALT(ALT_O);\r
+                       continue;\r
+\r
+               case 'l':       /* The hour (12-hour clock representation). */\r
+                       LEGAL_ALT(0);\r
+                       /* FALLTHROUGH */\r
+               case 'I':\r
+                       bp = conv_num(bp, &tm->tm_hour, 1, 12);\r
+                       if (tm->tm_hour == 12)\r
+                               tm->tm_hour = 0;\r
+                       LEGAL_ALT(ALT_O);\r
+                       continue;\r
+\r
+               case 'j':       /* The day of year. */\r
+                       i = 1;\r
+                       bp = conv_num(bp, &i, 1, 366);\r
+                       tm->tm_yday = i - 1;\r
+                       LEGAL_ALT(0);\r
+                       continue;\r
+\r
+               case 'M':       /* The minute. */\r
+                       bp = conv_num(bp, &tm->tm_min, 0, 59);\r
+                       LEGAL_ALT(ALT_O);\r
+                       continue;\r
+\r
+               case 'm':       /* The month. */\r
+                       i = 1;\r
+                       bp = conv_num(bp, &i, 1, 12);\r
+                       tm->tm_mon = i - 1;\r
+                       LEGAL_ALT(ALT_O);\r
+                       continue;\r
+\r
+               case 'p':       /* The locale's equivalent of AM/PM. */\r
+                       bp = find_string(bp, &i, _ctloc(am_pm), NULL, 2);\r
+                       if (tm->tm_hour > 11)\r
+                               return NULL;\r
+                       tm->tm_hour += i * 12;\r
+                       LEGAL_ALT(0);\r
+                       continue;\r
+\r
+               case 'S':       /* The seconds. */\r
+                       bp = conv_num(bp, &tm->tm_sec, 0, 61);\r
+                       LEGAL_ALT(ALT_O);\r
+                       continue;\r
+\r
+               case 'U':       /* The week of year, beginning on sunday. */\r
+               case 'W':       /* The week of year, beginning on monday. */\r
+                       /*\r
+                        * XXX This is bogus, as we can not assume any valid\r
+                        * information present in the tm structure at this\r
+                        * point to calculate a real value, so just check the\r
+                        * range for now.\r
+                        */\r
+                        bp = conv_num(bp, &i, 0, 53);\r
+                        LEGAL_ALT(ALT_O);\r
+                        continue;\r
+\r
+               case 'w':       /* The day of week, beginning on sunday. */\r
+                       bp = conv_num(bp, &tm->tm_wday, 0, 6);\r
+                       LEGAL_ALT(ALT_O);\r
+                       continue;\r
+\r
+               case 'Y':       /* The year. */\r
+                       i = TM_YEAR_BASE;       /* just for data sanity... */\r
+                       bp = conv_num(bp, &i, 0, 9999);\r
+                       tm->tm_year = i - TM_YEAR_BASE;\r
+                       LEGAL_ALT(ALT_E);\r
+                       continue;\r
+\r
+               case 'y':       /* The year within 100 years of the epoch. */\r
+                       /* LEGAL_ALT(ALT_E | ALT_O); */\r
+                       bp = conv_num(bp, &i, 0, 99);\r
+\r
+                       if (split_year)\r
+                               /* preserve century */\r
+                               i += (tm->tm_year / 100) * 100;\r
+                       else {\r
+                               split_year = 1;\r
+                               if (i <= 68)\r
+                                       i = i + 2000 - TM_YEAR_BASE;\r
+                               else\r
+                                       i = i + 1900 - TM_YEAR_BASE;\r
+                       }\r
+                       tm->tm_year = i;\r
+                       continue;\r
+\r
+               case 'Z':\r
+                       tzset();\r
+                       if (strncmp((const char *)bp, gmt, 3) == 0) {\r
+                               tm->tm_isdst = 0;\r
+#ifdef TM_GMTOFF\r
+                               tm->TM_GMTOFF = 0;\r
+#endif\r
+#ifdef TM_ZONE\r
+                               tm->TM_ZONE = gmt;\r
+#endif\r
+                               bp += 3;\r
+                       } else {\r
+                               const unsigned char *ep;\r
+\r
+                               ep = find_string(bp, &i,\r
+                                                (const char * const *)tzname,\r
+                                                 NULL, 2);\r
+                               if (ep != NULL) {\r
+                                       tm->tm_isdst = i;\r
+#ifdef TM_GMTOFF\r
+                                       tm->TM_GMTOFF = -(timezone);\r
+#endif\r
+#ifdef TM_ZONE\r
+                                       tm->TM_ZONE = tzname[i];\r
+#endif\r
+                               }\r
+                               bp = ep;\r
+                       }\r
+                       continue;\r
+\r
+               /*\r
+                * Miscellaneous conversions.\r
+                */\r
+               case 'n':       /* Any kind of white-space. */\r
+               case 't':\r
+                       while (isspace(*bp))\r
+                               bp++;\r
+                       LEGAL_ALT(0);\r
+                       continue;\r
+\r
+\r
+               default:        /* Unknown/unsupported conversion. */\r
+                       return NULL;\r
+               }\r
+       }\r
+\r
+       return __UNCONST(bp);\r
+}\r
+\r
+\r
+static const unsigned char *\r
+conv_num(const unsigned char *buf, int *dest, unsigned int llim, unsigned int ulim)\r
+{\r
+       unsigned int result = 0;\r
+       unsigned char ch;\r
+\r
+       /* The limit also determines the number of valid digits. */\r
+       unsigned int rulim = ulim;\r
+\r
+       ch = *buf;\r
+       if (ch < '0' || ch > '9')\r
+               return NULL;\r
+\r
+       do {\r
+               result *= 10;\r
+               result += ch - '0';\r
+               rulim /= 10;\r
+               ch = *++buf;\r
+       } while ((result * 10 <= ulim) && rulim && ch >= '0' && ch <= '9');\r
+\r
+       if (result < llim || result > ulim)\r
+               return NULL;\r
+\r
+       *dest = result;\r
+       return buf;\r
+}\r
+\r
+static const unsigned char *\r
+find_string(const unsigned char *bp, int *tgt, const char * const *n1,\r
+               const char * const *n2, int c)\r
+{\r
+       int i;\r
+       size_t len;\r
+\r
+       /* check full name - then abbreviated ones */\r
+       for (; n1 != NULL; n1 = n2, n2 = NULL) {\r
+               for (i = 0; i < c; i++, n1++) {\r
+                       len = strlen(*n1);\r
+                       if (strncasecmp(*n1, (const char *)bp, len) == 0) {\r
+                               *tgt = i;\r
+                               return bp + len;\r
+                       }\r
+               }\r
+       }\r
+\r
+       /* Nothing matched */\r
+       return NULL;\r
+}\r
index 11c20ebd394c05842b6140b115966953597003b5..f50ab669d29b04545e21518ef0de906750844855 100644 (file)
@@ -1,11 +1,11 @@
 /** @file\r
     Time Zone processing, declarations and macros.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials are licensed and made available under\r
   the terms and conditions of the BSD License that accompanies this distribution.\r
   The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php.\r
+  http://opensource.org/licenses/bsd-license.\r
 \r
   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -131,29 +131,6 @@ struct tzhead {
 #define SECSPERDAY  ((LONG32)(SECSPERHOUR * HOURSPERDAY))\r
 #define MONSPERYEAR 12\r
 \r
-#define TM_SUNDAY 0\r
-#define TM_MONDAY 1\r
-#define TM_TUESDAY  2\r
-#define TM_WEDNESDAY  3\r
-#define TM_THURSDAY 4\r
-#define TM_FRIDAY 5\r
-#define TM_SATURDAY 6\r
-\r
-#define TM_JANUARY  0\r
-#define TM_FEBRUARY 1\r
-#define TM_MARCH  2\r
-#define TM_APRIL  3\r
-#define TM_MAY    4\r
-#define TM_JUNE   5\r
-#define TM_JULY   6\r
-#define TM_AUGUST 7\r
-#define TM_SEPTEMBER  8\r
-#define TM_OCTOBER  9\r
-#define TM_NOVEMBER 10\r
-#define TM_DECEMBER 11\r
-\r
-#define TM_YEAR_BASE  1900\r
-\r
 #define EPOCH_YEAR  1970\r
 #define EPOCH_WDAY  TM_THURSDAY   // Use this for 32-bit time_t\r
 //#define EPOCH_WDAY  TM_SUNDAY     // Use this for 64-bit time_t\r
diff --git a/StdLib/LibC/Uefi/Console.c b/StdLib/LibC/Uefi/Console.c
deleted file mode 100644 (file)
index 0c3a21c..0000000
+++ /dev/null
@@ -1,393 +0,0 @@
-/** @file\r
-  File abstractions of the console.\r
-\r
-  Manipulates EFI_FILE_PROTOCOL abstractions for stdin, stdout, stderr.\r
-\r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials are licensed and made available under\r
-  the terms and conditions of the BSD License that accompanies this distribution.\r
-  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-#include  <Uefi.h>\r
-#include  <Library/BaseLib.h>\r
-#include  <Library/BaseMemoryLib.h>\r
-#include  <Library/MemoryAllocationLib.h>\r
-#include  <Library/UefiBootServicesTableLib.h>\r
-\r
-#include  <LibConfig.h>\r
-#include  <sys/EfiCdefs.h>\r
-\r
-#include  <stdio.h>\r
-#include  <sys/fcntl.h>\r
-#include  <MainData.h>\r
-#include  <Efi/Console.h>\r
-\r
-static const CHAR16 * stdioNames[NUM_SPECIAL]   = {\r
-  L"stdin:", L"stdout:", L"stderr:"\r
-};\r
-static const int stdioFlags[NUM_SPECIAL] = {\r
-  O_RDONLY,             // stdin\r
-  O_WRONLY,             // stdout\r
-  O_WRONLY              // stderr\r
-};\r
-\r
-static const int  stdioMode[NUM_SPECIAL] = {\r
-  0444,   // stdin\r
-  0222,   // stdout\r
-  0222    // stderr\r
-};\r
-\r
-static\r
-EFI_STATUS\r
-EFIAPI\r
-ConClose(\r
-  IN EFI_FILE_PROTOCOL         *This\r
-  )\r
-{\r
-  ConInstance    *Stream;\r
-\r
-  Stream = BASE_CR(This, ConInstance, Abstraction);\r
-  // Quick check to see if Stream looks reasonable\r
-  if(Stream->Cookie != 0x62416F49) {    // Cookie == 'IoAb'\r
-    return RETURN_INVALID_PARAMETER;    // Looks like a bad This pointer\r
-  }\r
-  // Nothing to Flush.\r
-  // Mark the Stream as closed.\r
-  Stream->Dev = NULL;\r
-\r
-  return RETURN_SUCCESS;\r
-}\r
-\r
-static\r
-EFI_STATUS\r
-EFIAPI\r
-ConDelete(\r
-  IN EFI_FILE_PROTOCOL         *This\r
-  )\r
-{\r
-  return RETURN_UNSUPPORTED;\r
-}\r
-\r
-static\r
-EFI_STATUS\r
-EFIAPI\r
-ConRead(\r
-  IN EFI_FILE_PROTOCOL         *This,\r
-  IN OUT UINTN                 *BufferSize,\r
-  OUT VOID                     *Buffer\r
-  )\r
-{\r
-  EFI_SIMPLE_TEXT_INPUT_PROTOCOL   *Proto;\r
-  ConInstance    *Stream;\r
-  CHAR16         *OutPtr;\r
-  EFI_INPUT_KEY   Key;\r
-  UINTN           NumChar;\r
-  UINTN           Edex;\r
-  EFI_STATUS      Status;\r
-  UINTN           i;\r
-\r
-  Stream = BASE_CR(This, ConInstance, Abstraction);\r
-  // Quick check to see if Stream looks reasonable\r
-  if(Stream->Cookie != 0x62416F49) {    // Cookie == 'IoAb'\r
-    return RETURN_INVALID_PARAMETER;    // Looks like a bad This pointer\r
-  }\r
-  if(Stream->Dev == NULL) {\r
-    // Can't read from an unopened Stream\r
-    return RETURN_DEVICE_ERROR;\r
-  }\r
-  if(Stream != &gMD->StdIo[0]) {\r
-    // Read only valid for stdin\r
-    return RETURN_UNSUPPORTED;\r
-  }\r
-  // It looks like things are OK for trying to read\r
-  // We will accumulate *BufferSize characters or until we encounter\r
-  // an "activation" character.  Currently any control character.\r
-  Proto = (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Stream->Dev;\r
-  OutPtr = Buffer;\r
-  NumChar = (*BufferSize - 1) / sizeof(CHAR16);\r
-  i = 0;\r
-  do {\r
-    Status = gBS->WaitForEvent( 1, &Proto->WaitForKey, &Edex);\r
-    if(Status != EFI_SUCCESS) {\r
-      break;\r
-    }\r
-    Status = Proto->ReadKeyStroke(Proto, &Key);\r
-    if(Status != EFI_SUCCESS) {\r
-      break;\r
-    }\r
-    if(Key.ScanCode == SCAN_NULL) {\r
-      *OutPtr++ = Key.UnicodeChar;\r
-      ++i;\r
-    }\r
-    if(Key.UnicodeChar < 0x0020) {    // If a control character, or a scan code\r
-      break;\r
-    }\r
-  } while(i < NumChar);\r
-  *BufferSize = i * sizeof(CHAR16);\r
-  return Status;\r
-}\r
-\r
-/* Write a NULL terminated WCS to the EFI console.\r
-\r
-  @param[in,out]  BufferSize  Number of bytes in Buffer.  Set to zero if\r
-                              the string couldn't be displayed.\r
-  @parem[in]      Buffer      The WCS string to be displayed\r
-\r
-*/\r
-static\r
-EFI_STATUS\r
-EFIAPI\r
-ConWrite(\r
-  IN EFI_FILE_PROTOCOL         *This,\r
-  IN OUT UINTN                 *BufferSize,\r
-  IN VOID                      *Buffer\r
-  )\r
-{\r
-  EFI_STATUS      Status;\r
-  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *Proto;\r
-  ConInstance    *Stream;\r
-  CHAR16         *MyBuf;\r
-  UINTN           NumChar;\r
-\r
-  Stream = BASE_CR(This, ConInstance, Abstraction);\r
-  // Quick check to see if Stream looks reasonable\r
-  if(Stream->Cookie != 0x62416F49) {    // Cookie == 'IoAb'\r
-    return RETURN_INVALID_PARAMETER;    // Looks like a bad This pointer\r
-  }\r
-  if(Stream->Dev == NULL) {\r
-    // Can't write to an unopened Stream\r
-    return RETURN_DEVICE_ERROR;\r
-  }\r
-  if(Stream == &gMD->StdIo[0]) {\r
-    // Write is not valid for stdin\r
-    return RETURN_UNSUPPORTED;\r
-  }\r
-  // Everything is OK to do the write.\r
-  Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;\r
-  MyBuf = (CHAR16 *)Buffer;\r
-  NumChar = *BufferSize;\r
-\r
-  // Send MyBuf to the console\r
-  Status = Proto->OutputString( Proto, MyBuf);\r
-  // Depending on status, update BufferSize and return\r
-  if(Status != EFI_SUCCESS) {\r
-    *BufferSize = 0;    // We don't really know how many characters made it out\r
-  }\r
-  else {\r
-    *BufferSize = NumChar;\r
-    Stream->NumWritten += NumChar;\r
-  }\r
-  return Status;\r
-}\r
-\r
-static\r
-EFI_STATUS\r
-EFIAPI\r
-ConGetPosition(\r
-  IN EFI_FILE_PROTOCOL         *This,\r
-  OUT UINT64                   *Position\r
-  )\r
-{\r
-  ConInstance                       *Stream;\r
-  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *Proto;\r
-  XYoffset                           CursorPos;\r
-\r
-  Stream = BASE_CR(This, ConInstance, Abstraction);\r
-  // Quick check to see if Stream looks reasonable\r
-  if(Stream->Cookie != 0x62416F49) {    // Cookie == 'IoAb'\r
-    return RETURN_INVALID_PARAMETER;    // Looks like a bad This pointer\r
-  }\r
-  if(Stream == &gMD->StdIo[0]) {\r
-    // This is stdin\r
-    *Position = Stream->NumRead;\r
-  }\r
-  else {\r
-    Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;\r
-    CursorPos.XYpos.Column = (UINT32)Proto->Mode->CursorColumn;\r
-    CursorPos.XYpos.Row    = (UINT32)Proto->Mode->CursorRow;\r
-    *Position = CursorPos.Offset;\r
-  }\r
-  return RETURN_SUCCESS;\r
-}\r
-\r
-static\r
-EFI_STATUS\r
-EFIAPI\r
-ConSetPosition(\r
-  IN EFI_FILE_PROTOCOL         *This,\r
-  IN UINT64                     Position\r
-  )\r
-{\r
-  ConInstance                       *Stream;\r
-  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *Proto;\r
-  XYoffset                           CursorPos;\r
-\r
-  Stream = BASE_CR(This, ConInstance, Abstraction);\r
-  // Quick check to see if Stream looks reasonable\r
-  if(Stream->Cookie != 0x62416F49) {    // Cookie == 'IoAb'\r
-    return RETURN_INVALID_PARAMETER;    // Looks like a bad This pointer\r
-  }\r
-  if(Stream->Dev == NULL) {\r
-    // Can't write to an unopened Stream\r
-    return RETURN_DEVICE_ERROR;\r
-  }\r
-  if(Stream == &gMD->StdIo[0]) {\r
-    // Seek is not valid for stdin\r
-    return RETURN_UNSUPPORTED;\r
-  }\r
-  // Everything is OK to do the final verification and "seek".\r
-  Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;\r
-  CursorPos.Offset = Position;\r
-\r
-  return Proto->SetCursorPosition(Proto,\r
-                                  (INTN)CursorPos.XYpos.Column,\r
-                                  (INTN)CursorPos.XYpos.Row);\r
-}\r
-\r
-static\r
-EFI_STATUS\r
-EFIAPI\r
-ConGetInfo(\r
-  IN EFI_FILE_PROTOCOL         *This,\r
-  IN EFI_GUID                  *InformationType,\r
-  IN OUT UINTN                 *BufferSize,\r
-  OUT VOID                     *Buffer\r
-  )\r
-{\r
-  EFI_FILE_INFO       *InfoBuf;\r
-  ConInstance         *Stream;\r
-\r
-  Stream = BASE_CR(This, ConInstance, Abstraction);\r
-  // Quick check to see if Stream looks reasonable\r
-  if((Stream->Cookie != 0x62416F49) ||    // Cookie == 'IoAb'\r
-     (Buffer == NULL))\r
-  {\r
-    return RETURN_INVALID_PARAMETER;\r
-  }\r
-  if(*BufferSize < sizeof(EFI_FILE_INFO)) {\r
-    *BufferSize = sizeof(EFI_FILE_INFO);\r
-    return RETURN_BUFFER_TOO_SMALL;\r
-  }\r
-  // All of our parameters are correct, so fill in the information.\r
-  (void) ZeroMem(Buffer, sizeof(EFI_FILE_INFO));\r
-  InfoBuf = (EFI_FILE_INFO *)Buffer;\r
-  InfoBuf->Size = sizeof(EFI_FILE_INFO);\r
-  InfoBuf->FileSize = 1;\r
-  InfoBuf->PhysicalSize = 1;\r
-  *BufferSize = sizeof(EFI_FILE_INFO);\r
-\r
-  return RETURN_SUCCESS;\r
-}\r
-\r
-static\r
-EFI_STATUS\r
-EFIAPI\r
-ConSetInfo(\r
-  IN EFI_FILE_PROTOCOL         *This,\r
-  IN EFI_GUID                  *InformationType,\r
-  IN UINTN                      BufferSize,\r
-  IN VOID                      *Buffer\r
-  )\r
-{\r
-  return RETURN_UNSUPPORTED;\r
-}\r
-\r
-static\r
-EFI_STATUS\r
-EFIAPI\r
-ConFlush(\r
-  IN EFI_FILE_PROTOCOL         *This\r
-  )\r
-{\r
-  return RETURN_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-ConOpen(\r
-  IN  EFI_FILE_PROTOCOL        *This,\r
-  OUT EFI_FILE_PROTOCOL       **NewHandle,\r
-  IN  CHAR16                   *FileName,\r
-  IN  UINT64                    OpenMode,   // Ignored\r
-  IN  UINT64                    Attributes  // Ignored\r
-  )\r
-{\r
-  ConInstance                      *Stream;\r
-  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *Proto;\r
-  UINTN                             Columns;\r
-  UINTN                             Rows;\r
-  int                               i;\r
-\r
-  if((NewHandle == NULL)  ||\r
-     (FileName  == NULL))\r
-  {\r
-    return RETURN_INVALID_PARAMETER;\r
-  }\r
-  // Process FileName\r
-  for(i = 0; i < NUM_SPECIAL; ++i) {\r
-    if(StrCmp( stdioNames[i], FileName) == 0) {\r
-      break;\r
-    }\r
-  }\r
-  if(i >= NUM_SPECIAL) {\r
-    return RETURN_NO_MAPPING;\r
-  }\r
-  // Get pointer to instance.\r
-  Stream = &gMD->StdIo[i];\r
-  if(Stream->Dev == NULL) {\r
-    // If this stream has been closed, then\r
-    // Initialize instance.\r
-    Stream->Cookie      = 0x62416F49;\r
-    Stream->NumRead     = 0;\r
-    Stream->NumWritten  = 0;\r
-    switch(i) {\r
-      case 0:\r
-        Stream->Dev = gST->ConIn;\r
-        break;\r
-      case 1:\r
-        Stream->Dev = gST->ConOut;\r
-        break;\r
-      case 2:\r
-        if(gST->StdErr == NULL) {\r
-          Stream->Dev = gST->ConOut;\r
-        }\r
-        else {\r
-          Stream->Dev = gST->StdErr;\r
-        }\r
-        break;\r
-      default:\r
-        return RETURN_VOLUME_CORRUPTED;     // This is a "should never happen" case.\r
-    }\r
-    Stream->Abstraction.Revision      = 0x00010000;\r
-    Stream->Abstraction.Open          = &ConOpen;\r
-    Stream->Abstraction.Close         = &ConClose;\r
-    Stream->Abstraction.Delete        = &ConDelete;\r
-    Stream->Abstraction.Read          = &ConRead;\r
-    Stream->Abstraction.Write         = &ConWrite;\r
-    Stream->Abstraction.GetPosition   = &ConGetPosition;\r
-    Stream->Abstraction.SetPosition   = &ConSetPosition;\r
-    Stream->Abstraction.GetInfo       = &ConGetInfo;\r
-    Stream->Abstraction.SetInfo       = &ConSetInfo;\r
-    Stream->Abstraction.Flush         = &ConFlush;\r
-    // Get additional information if this is an Output stream\r
-    if(i != 0) {\r
-      Proto = Stream->Dev;\r
-      Stream->ConOutMode = Proto->Mode->Mode;\r
-      if( Proto->QueryMode(Proto, Stream->ConOutMode, &Columns, &Rows) != RETURN_SUCCESS) {\r
-        Stream->Dev = NULL;   // Mark this stream as closed\r
-        return RETURN_INVALID_PARAMETER;\r
-      }\r
-      Stream->MaxConXY.XYpos.Column = (UINT32)Columns;\r
-      Stream->MaxConXY.XYpos.Row    = (UINT32)Rows;\r
-    }\r
-  }\r
-  // Save NewHandle and return.\r
-  *NewHandle = &Stream->Abstraction;\r
-\r
-  return RETURN_SUCCESS;\r
-}\r
diff --git a/StdLib/LibC/Uefi/Devices/Console/daConsole.c b/StdLib/LibC/Uefi/Devices/Console/daConsole.c
new file mode 100644 (file)
index 0000000..c579959
--- /dev/null
@@ -0,0 +1,558 @@
+/** @file\r
+  Abstract device driver for the UEFI Console.\r
+\r
+  Manipulates abstractions for stdin, stdout, stderr.\r
+\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/BaseLib.h>\r
+#include  <Library/MemoryAllocationLib.h>\r
+#include  <Library/UefiBootServicesTableLib.h>\r
+#include  <Protocol/SimpleTextIn.h>\r
+#include  <Protocol/SimpleTextOut.h>\r
+\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiSysCall.h>\r
+\r
+#include  <errno.h>\r
+#include  <wctype.h>\r
+#include  <wchar.h>\r
+#include  <sys/fcntl.h>\r
+#include  <kfile.h>\r
+#include  <Device/Device.h>\r
+#include  <MainData.h>\r
+\r
+static const CHAR16* const\r
+stdioNames[NUM_SPECIAL]   = {\r
+  L"stdin:", L"stdout:", L"stderr:"\r
+};\r
+\r
+static const int stdioFlags[NUM_SPECIAL] = {\r
+  O_RDONLY,             // stdin\r
+  O_WRONLY,             // stdout\r
+  O_WRONLY              // stderr\r
+};\r
+\r
+static DeviceNode    *ConNode[NUM_SPECIAL];\r
+static ConInstance   *ConInstanceList;\r
+\r
+ssize_t\r
+WideTtyCvt( CHAR16 *dest, const char *buf, size_t n)\r
+{\r
+  UINTN   i;\r
+  wint_t  wc;\r
+\r
+  for(i = 0; i < n; ++i) {\r
+    wc = btowc(*buf++);\r
+    if( wc == 0) {\r
+      break;\r
+    };\r
+    if(wc < 0) {\r
+      wc = BLOCKELEMENT_LIGHT_SHADE;\r
+    }\r
+    if(wc == L'\n') {\r
+      *dest++ = L'\r';\r
+    }\r
+    *dest++ = (CHAR16)wc;\r
+  }\r
+  *dest = 0;\r
+  return (ssize_t)i;\r
+}\r
+\r
+static\r
+int\r
+EFIAPI\r
+da_ConClose(\r
+  IN      struct __filedes   *filp\r
+)\r
+{\r
+  ConInstance    *Stream;\r
+\r
+  Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);\r
+  // Quick check to see if Stream looks reasonable\r
+  if(Stream->Cookie != CON_COOKIE) {    // Cookie == 'IoAb'\r
+    EFIerrno = RETURN_INVALID_PARAMETER;\r
+    return -1;    // Looks like a bad File Descriptor pointer\r
+  }\r
+  gMD->StdIo[Stream->InstanceNum] = NULL;   // Mark the stream as closed\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+static\r
+off_t\r
+EFIAPI\r
+da_ConSeek(\r
+  struct __filedes   *filp,\r
+  off_t               Position,\r
+  int                 whence      ///< Ignored by Console\r
+)\r
+{\r
+  ConInstance                       *Stream;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *Proto;\r
+  XYoffset                           CursorPos;\r
+\r
+  Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);\r
+  // Quick check to see if Stream looks reasonable\r
+  if(Stream->Cookie != CON_COOKIE) {    // Cookie == 'IoAb'\r
+    EFIerrno = RETURN_INVALID_PARAMETER;\r
+    return -1;    // Looks like a bad This pointer\r
+  }\r
+  if(Stream->InstanceNum == STDIN_FILENO) {\r
+    // Seek is not valid for stdin\r
+    EFIerrno = RETURN_UNSUPPORTED;\r
+    return -1;\r
+  }\r
+  // Everything is OK to do the final verification and "seek".\r
+  Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;\r
+  CursorPos.Offset = Position;\r
+\r
+  EFIerrno = Proto->SetCursorPosition(Proto,\r
+                                      (INTN)CursorPos.XYpos.Column,\r
+                                      (INTN)CursorPos.XYpos.Row);\r
+\r
+  if(RETURN_ERROR(EFIerrno)) {\r
+    return -1;\r
+  }\r
+  else {\r
+    return Position;\r
+  }\r
+}\r
+\r
+static\r
+ssize_t\r
+EFIAPI\r
+da_ConRead(\r
+  IN OUT  struct __filedes   *filp,\r
+  IN OUT  off_t              *offset,         // Console ignores this\r
+  IN      size_t              BufferSize,\r
+     OUT  VOID               *Buffer\r
+)\r
+{\r
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL   *Proto;\r
+  ConInstance                      *Stream;\r
+  CHAR16                           *OutPtr;\r
+  EFI_INPUT_KEY                     Key;\r
+  UINTN                             NumChar;\r
+  UINTN                             Edex;\r
+  EFI_STATUS                        Status = RETURN_SUCCESS;\r
+  UINTN                             i;\r
+\r
+  Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);\r
+  // Quick check to see if Stream looks reasonable\r
+  if(Stream->Cookie != CON_COOKIE) {    // Cookie == 'IoAb'\r
+    EFIerrno = RETURN_INVALID_PARAMETER;\r
+    return -1;    // Looks like a bad This pointer\r
+  }\r
+  if(Stream->InstanceNum != STDIN_FILENO) {\r
+    // Read only valid for stdin\r
+    EFIerrno = RETURN_UNSUPPORTED;\r
+    return -1;\r
+  }\r
+  // It looks like things are OK for trying to read\r
+  // We will accumulate *BufferSize characters or until we encounter\r
+  // an "activation" character.  Currently any control character.\r
+  Proto = (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Stream->Dev;\r
+  OutPtr = Buffer;\r
+  NumChar = (BufferSize - 1) / sizeof(CHAR16);\r
+  i = 0;\r
+  do {\r
+    if((Stream->UnGetKey.UnicodeChar == CHAR_NULL) && (Stream->UnGetKey.ScanCode == SCAN_NULL)) {\r
+      Status = gBS->WaitForEvent( 1, &Proto->WaitForKey, &Edex);\r
+      if(Status != RETURN_SUCCESS) {\r
+        break;\r
+      }\r
+      Status = Proto->ReadKeyStroke(Proto, &Key);\r
+      if(Status != RETURN_SUCCESS) {\r
+        break;\r
+      }\r
+    }\r
+    else {\r
+      Key.ScanCode          = Stream->UnGetKey.ScanCode;\r
+      Key.UnicodeChar       = Stream->UnGetKey.UnicodeChar;\r
+      Stream->UnGetKey.ScanCode     = SCAN_NULL;\r
+      Stream->UnGetKey.UnicodeChar  = CHAR_NULL;\r
+    }\r
+    if(Key.ScanCode == SCAN_NULL) {\r
+      *OutPtr++ = Key.UnicodeChar;\r
+      ++i;\r
+    }\r
+    if(iswcntrl(Key.UnicodeChar)) {    // If a control character, or a scan code\r
+      break;\r
+    }\r
+  } while(i < NumChar);\r
+\r
+  *OutPtr = L'\0';    // Terminate the input buffer\r
+  EFIerrno = Status;\r
+  return (ssize_t)(i * sizeof(CHAR16));  // Will be 0 if we didn't get a key\r
+}\r
+\r
+/* Write a NULL terminated WCS to the EFI console.\r
+\r
+  @param[in,out]  BufferSize  Number of bytes in Buffer.  Set to zero if\r
+                              the string couldn't be displayed.\r
+  @param[in]      Buffer      The WCS string to be displayed\r
+\r
+  @return   The number of characters written.\r
+*/\r
+static\r
+ssize_t\r
+EFIAPI\r
+da_ConWrite(\r
+  IN  struct __filedes     *filp,\r
+  IN  off_t                *Position,\r
+  IN  size_t                BufferSize,\r
+  IN  const void           *Buffer\r
+  )\r
+{\r
+  EFI_STATUS                          Status;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *Proto;\r
+  ConInstance                        *Stream;\r
+  ssize_t                             NumChar;\r
+  //XYoffset                            CursorPos;\r
+\r
+  Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);\r
+  // Quick check to see if Stream looks reasonable\r
+  if(Stream->Cookie != CON_COOKIE) {    // Cookie == 'IoAb'\r
+    EFIerrno = RETURN_INVALID_PARAMETER;\r
+    return -1;    // Looks like a bad This pointer\r
+  }\r
+  if(Stream->InstanceNum == STDIN_FILENO) {\r
+    // Write is not valid for stdin\r
+    EFIerrno = RETURN_UNSUPPORTED;\r
+    return -1;\r
+  }\r
+  // Everything is OK to do the write.\r
+  Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;\r
+\r
+  // Convert string from MBCS to WCS and translate \n to \r\n.\r
+  NumChar = WideTtyCvt(gMD->UString, (const char *)Buffer, BufferSize);\r
+  //if(NumChar > 0) {\r
+  //  BufferSize = (size_t)(NumChar * sizeof(CHAR16));\r
+  //}\r
+  BufferSize = NumChar;\r
+\r
+  //if( Position != NULL) {\r
+  //  CursorPos.Offset = (UINT64)*Position;\r
+\r
+  //  Status = Proto->SetCursorPosition(Proto,\r
+  //                                    (INTN)CursorPos.XYpos.Column,\r
+  //                                    (INTN)CursorPos.XYpos.Row);\r
+  //  if(RETURN_ERROR(Status)) {\r
+  //    return -1;\r
+  //  }\r
+  //}\r
+\r
+  // Send the Unicode buffer to the console\r
+  Status = Proto->OutputString( Proto, gMD->UString);\r
+  // Depending on status, update BufferSize and return\r
+  if(RETURN_ERROR(Status)) {\r
+    BufferSize = 0;    // We don't really know how many characters made it out\r
+  }\r
+  else {\r
+    //BufferSize = NumChar;\r
+    Stream->NumWritten += NumChar;\r
+  }\r
+  EFIerrno = Status;\r
+  return BufferSize;\r
+}\r
+\r
+/** Console-specific helper function for the fstat() function.\r
+\r
+    st_size       Set to number of characters read for stdin and number written for stdout and stderr.\r
+    st_physsize   1 for stdin, 0 if QueryMode error, else max X and Y coordinates for the current mode.\r
+    st_curpos     0 for stdin, current X & Y coordinates for stdout and stderr\r
+    st_blksize    Set to 1 since this is a character device\r
+\r
+    All other members of the stat structure are left unchanged.\r
+**/\r
+static\r
+int\r
+EFIAPI\r
+da_ConStat(\r
+  struct __filedes   *filp,\r
+  struct stat        *Buffer,\r
+  void               *Something\r
+  )\r
+{\r
+  ConInstance                        *Stream;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *Proto;\r
+  XYoffset                            CursorPos;\r
+  INT32                               OutMode;\r
+  UINTN                               ModeCol;\r
+  UINTN                               ModeRow;\r
+\r
+// ConGetInfo\r
+  Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);\r
+  // Quick check to see if Stream looks reasonable\r
+  if ((Stream->Cookie != CON_COOKIE) ||    // Cookie == 'IoAb'\r
+      (Buffer == NULL))\r
+  {\r
+    EFIerrno = RETURN_INVALID_PARAMETER;\r
+    return -1;\r
+  }\r
+  // All of our parameters are correct, so fill in the information.\r
+  Buffer->st_blksize = 1;\r
+\r
+// ConGetPosition\r
+  if(Stream->InstanceNum == STDIN_FILENO) {\r
+    // This is stdin\r
+    Buffer->st_curpos    = 0;\r
+    Buffer->st_size      = (off_t)Stream->NumRead;\r
+    Buffer->st_physsize  = 1;\r
+  }\r
+  else {\r
+    Proto = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)Stream->Dev;\r
+    CursorPos.XYpos.Column  = (UINT32)Proto->Mode->CursorColumn;\r
+    CursorPos.XYpos.Row     = (UINT32)Proto->Mode->CursorRow;\r
+    Buffer->st_curpos       = (off_t)CursorPos.Offset;\r
+    Buffer->st_size         = (off_t)Stream->NumWritten;\r
+\r
+    OutMode  = Proto->Mode->Mode;\r
+    EFIerrno = Proto->QueryMode(Proto, (UINTN)OutMode, &ModeCol, &ModeRow);\r
+    if(RETURN_ERROR(EFIerrno)) {\r
+      Buffer->st_physsize = 0;\r
+    }\r
+    else {\r
+      CursorPos.XYpos.Column  = (UINT32)ModeCol;\r
+      CursorPos.XYpos.Row     = (UINT32)ModeRow;\r
+      Buffer->st_physsize     = (off_t)CursorPos.Offset;\r
+    }\r
+  }\r
+  return 0;\r
+}\r
+\r
+static\r
+int\r
+EFIAPI\r
+da_ConIoctl(\r
+  struct __filedes   *filp,\r
+  ULONGN              cmd,\r
+  void               *argp\r
+  )\r
+{\r
+  return -EPERM;\r
+}\r
+\r
+/** Open an abstract Console Device.\r
+**/\r
+int\r
+EFIAPI\r
+da_ConOpen(\r
+  struct __filedes   *filp,\r
+  void               *DevInstance,\r
+  wchar_t            *Path,           // Not used for console devices\r
+  wchar_t            *Flags           // Not used for console devices\r
+  )\r
+{\r
+  ConInstance                      *Stream;\r
+\r
+  if((filp == NULL)           ||\r
+     (DevInstance  == NULL))\r
+  {\r
+    EFIerrno = RETURN_INVALID_PARAMETER;\r
+    return -1;\r
+  }\r
+  Stream = (ConInstance *)DevInstance;\r
+  // Quick check to see if Stream looks reasonable\r
+  if(Stream->Cookie != CON_COOKIE) {    // Cookie == 'IoAb'\r
+    EFIerrno = RETURN_INVALID_PARAMETER;\r
+    return -1;    // Looks like a bad This pointer\r
+  }\r
+  gMD->StdIo[Stream->InstanceNum] = (ConInstance *)DevInstance;\r
+  filp->f_iflags |= (S_IFREG | _S_IFCHR | _S_ICONSOLE);\r
+  filp->f_offset = 0;\r
+  filp->f_ops = &Stream->Abstraction;\r
+\r
+  return 0;\r
+}\r
+\r
+#include  <sys/poll.h>\r
+/*  Returns a bit mask describing which operations could be completed immediately.\r
+\r
+    (POLLIN | POLLRDNORM)   A Unicode character is available to read\r
+    (POLLIN)                A ScanCode is ready.\r
+    (POLLOUT)               The device is ready for output - always set on stdout and stderr.\r
+\r
+*/\r
+static\r
+short\r
+EFIAPI\r
+da_ConPoll(\r
+  struct __filedes   *filp,\r
+  short              events\r
+  )\r
+{\r
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL   *Proto;\r
+  ConInstance                      *Stream;\r
+  EFI_STATUS                        Status = RETURN_SUCCESS;\r
+  short                             RdyMask = 0;\r
+\r
+  Stream = BASE_CR(filp->f_ops, ConInstance, Abstraction);\r
+  // Quick check to see if Stream looks reasonable\r
+  if(Stream->Cookie != CON_COOKIE) {    // Cookie == 'IoAb'\r
+    EFIerrno = RETURN_INVALID_PARAMETER;\r
+    return POLLNVAL;    // Looks like a bad filp pointer\r
+  }\r
+  if(Stream->InstanceNum == 0) {\r
+    // Only input is supported for this device\r
+    Proto = (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Stream->Dev;\r
+    if((Stream->UnGetKey.UnicodeChar == CHAR_NULL) && (Stream->UnGetKey.ScanCode == SCAN_NULL)) {\r
+      Status = Proto->ReadKeyStroke(Proto, &Stream->UnGetKey);\r
+      if(Status == RETURN_SUCCESS) {\r
+        RdyMask = POLLIN;\r
+        if(Stream->UnGetKey.UnicodeChar != CHAR_NULL) {\r
+          RdyMask |= POLLRDNORM;\r
+        }\r
+      }\r
+      else {\r
+        Stream->UnGetKey.ScanCode     = SCAN_NULL;\r
+        Stream->UnGetKey.UnicodeChar  = CHAR_NULL;\r
+      }\r
+    }\r
+  }\r
+  else if(Stream->InstanceNum < NUM_SPECIAL) {  // Not 0, is it 1 or 2?\r
+    // Only output is supported for this device\r
+    RdyMask = POLLOUT;\r
+  }\r
+  else {\r
+    RdyMask = POLLERR;    // Not one of the standard streams\r
+  }\r
+  EFIerrno = Status;\r
+\r
+  return (RdyMask & (events | POLL_RETONLY));\r
+}\r
+\r
+/** Construct the Console stream devices: stdin, stdout, stderr.\r
+\r
+    Allocate the instance structure and populate it with the information for\r
+    each stream device.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+__Cons_construct(\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+)\r
+{\r
+  ConInstance    *Stream;\r
+  RETURN_STATUS   Status = RETURN_SUCCESS;\r
+  int             i;\r
+\r
+  ConInstanceList = (ConInstance *)AllocateZeroPool(NUM_SPECIAL * sizeof(ConInstance));\r
+  if(ConInstanceList == NULL) {\r
+    return RETURN_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  for( i = 0; i < NUM_SPECIAL; ++i) {\r
+    // Get pointer to instance.\r
+    Stream = &ConInstanceList[i];\r
+\r
+    Stream->Cookie      = CON_COOKIE;\r
+    Stream->InstanceNum = i;\r
+\r
+    switch(i) {\r
+      case STDIN_FILENO:\r
+        Stream->Dev = SystemTable->ConIn;\r
+        break;\r
+      case STDOUT_FILENO:\r
+        Stream->Dev = SystemTable->ConOut;\r
+        break;\r
+      case STDERR_FILENO:\r
+        if(SystemTable->StdErr == NULL) {\r
+          Stream->Dev = SystemTable->ConOut;\r
+        }\r
+        else {\r
+          Stream->Dev = SystemTable->StdErr;\r
+        }\r
+        break;\r
+      default:\r
+        return RETURN_VOLUME_CORRUPTED;     // This is a "should never happen" case.\r
+    }\r
+\r
+    Stream->Abstraction.fo_close    = &da_ConClose;\r
+    Stream->Abstraction.fo_read     = &da_ConRead;\r
+    Stream->Abstraction.fo_write    = &da_ConWrite;\r
+    Stream->Abstraction.fo_stat     = &da_ConStat;\r
+    Stream->Abstraction.fo_lseek    = &da_ConSeek;\r
+    Stream->Abstraction.fo_fcntl    = &fnullop_fcntl;\r
+    Stream->Abstraction.fo_ioctl    = &da_ConIoctl;\r
+    Stream->Abstraction.fo_poll     = &da_ConPoll;\r
+    Stream->Abstraction.fo_flush    = &fnullop_flush;\r
+    Stream->Abstraction.fo_delete   = &fbadop_delete;\r
+    Stream->Abstraction.fo_mkdir    = &fbadop_mkdir;\r
+    Stream->Abstraction.fo_rmdir    = &fbadop_rmdir;\r
+    Stream->Abstraction.fo_rename   = &fbadop_rename;\r
+\r
+    Stream->NumRead     = 0;\r
+    Stream->NumWritten  = 0;\r
+    Stream->UnGetKey.ScanCode     = SCAN_NULL;\r
+    Stream->UnGetKey.UnicodeChar  = CHAR_NULL;\r
+\r
+    if(Stream->Dev == NULL) {\r
+      continue;                 // No device for this stream.\r
+    }\r
+    ConNode[i] = __DevRegister(stdioNames[i], NULL, &da_ConOpen, Stream, 1, sizeof(ConInstance), stdioFlags[i]);\r
+    if(ConNode[i] == NULL) {\r
+      Status = EFIerrno;\r
+      break;\r
+    }\r
+    Stream->Parent = ConNode[i];\r
+  }\r
+  return  Status;\r
+}\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+__Cons_deconstruct(\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+)\r
+{\r
+  int   i;\r
+\r
+  for(i = 0; i < NUM_SPECIAL; ++i) {\r
+    if(ConNode[i] != NULL) {\r
+      FreePool(ConNode[i]);\r
+    }\r
+  }\r
+  if(ConInstanceList != NULL) {\r
+    FreePool(ConInstanceList);\r
+  }\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
+\r
+/* ######################################################################### */\r
+#if 0 /* Not implemented for Console */\r
+\r
+static\r
+int\r
+EFIAPI\r
+da_ConCntl(\r
+  struct __filedes *filp,\r
+  UINT32,\r
+  void *,\r
+  void *\r
+  )\r
+{\r
+}\r
+\r
+static\r
+int\r
+EFIAPI\r
+da_ConFlush(\r
+  struct __filedes *filp\r
+  )\r
+{\r
+  return 0;\r
+}\r
+#endif  /* Not implemented for Console */\r
diff --git a/StdLib/LibC/Uefi/Devices/UefiShell/daShell.c b/StdLib/LibC/Uefi/Devices/UefiShell/daShell.c
new file mode 100644 (file)
index 0000000..37870e8
--- /dev/null
@@ -0,0 +1,650 @@
+/** @file\r
+  Abstract device driver for the UEFI Shell-hosted environment.\r
+\r
+  In a Shell-hosted environment, this is the driver that is called\r
+  when no other driver matches.\r
+\r
+  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/BaseLib.h>\r
+#include  <Library/MemoryAllocationLib.h>\r
+#include  <Library/UefiBootServicesTableLib.h>\r
+#include  <Library/ShellLib.h>\r
+\r
+#include  <LibConfig.h>\r
+#include  <sys/EfiSysCall.h>\r
+\r
+#include  <errno.h>\r
+#include  <string.h>\r
+#include  <stdlib.h>\r
+#include  <wctype.h>\r
+#include  <wchar.h>\r
+#include  <sys/fcntl.h>\r
+#include  <kfile.h>\r
+#include  <Device/Device.h>\r
+#include  <MainData.h>\r
+#include  <Efi/SysEfi.h>\r
+\r
+static\r
+int\r
+EFIAPI\r
+da_ShellClose(\r
+  IN      struct __filedes   *Fp\r
+)\r
+{\r
+  EFIerrno = ShellCloseFile( (SHELL_FILE_HANDLE *)&Fp->devdata);\r
+  if(RETURN_ERROR(EFIerrno)) {\r
+    return -1;\r
+  }\r
+  return 0;\r
+}\r
+\r
+static\r
+int\r
+EFIAPI\r
+da_ShellDelete(\r
+  struct __filedes   *filp\r
+  )\r
+{\r
+  RETURN_STATUS         Status;\r
+\r
+  Status = ShellDeleteFile( (SHELL_FILE_HANDLE *)&filp->devdata);\r
+  if(Status != RETURN_SUCCESS) {\r
+    errno = EFI2errno(Status);\r
+    EFIerrno = Status;\r
+    return -1;\r
+  }\r
+  return 0;\r
+}\r
+\r
+static\r
+off_t\r
+EFIAPI\r
+da_ShellSeek(\r
+  struct __filedes   *filp,\r
+  off_t               offset,\r
+  int                 whence\r
+)\r
+{\r
+  __off_t             CurPos = -1;\r
+  RETURN_STATUS       Status = RETURN_SUCCESS;\r
+  SHELL_FILE_HANDLE   FileHandle;\r
+\r
+  FileHandle = (SHELL_FILE_HANDLE)filp->devdata;\r
+\r
+  if(whence != SEEK_SET) {\r
+    // We are doing a relative seek\r
+    if(whence == SEEK_END) {\r
+      // seeking relative to EOF, so position there first.\r
+      Status = ShellSetFilePosition( FileHandle, 0xFFFFFFFFFFFFFFFFULL);\r
+    }\r
+    if(Status == RETURN_SUCCESS) {\r
+      // Now, determine our current position.\r
+      Status = ShellGetFilePosition( FileHandle, (UINT64 *)&CurPos);\r
+    }\r
+  }\r
+  else {\r
+    CurPos = 0;   // offset is an absolute position for SEEK_SET\r
+    if(offset < 0) {\r
+      Status = RETURN_INVALID_PARAMETER;\r
+    }\r
+  }\r
+  if(Status == RETURN_SUCCESS) {\r
+    /* CurPos now indicates the point we are seeking from, so seek... */\r
+    Status = ShellSetFilePosition( FileHandle, (UINT64)(CurPos + offset));\r
+    if(Status == RETURN_SUCCESS) {\r
+      // Now, determine our final position.\r
+      Status = ShellGetFilePosition( FileHandle, (UINT64 *)&CurPos);\r
+    }\r
+  }\r
+  if(Status != RETURN_SUCCESS) {\r
+    if(Status == EFI_UNSUPPORTED) {\r
+      errno = EISDIR;\r
+    }\r
+    else {\r
+      errno = EFI2errno(Status);\r
+    }\r
+    EFIerrno = Status;\r
+    CurPos = EOF;\r
+  }\r
+  return CurPos;\r
+}\r
+\r
+/** The directory path is created with the access permissions specified by\r
+    perms.\r
+\r
+    The directory is closed after it is created.\r
+\r
+    @retval   0   The directory was created successfully.\r
+    @retval  -1   An error occurred and an error code is stored in errno.\r
+**/\r
+static\r
+int\r
+EFIAPI\r
+da_ShellMkdir(\r
+  const char   *path,\r
+  __mode_t      perms\r
+  )\r
+{\r
+  SHELL_FILE_HANDLE FileHandle;\r
+  RETURN_STATUS     Status;\r
+  EFI_FILE_INFO    *FileInfo;\r
+  wchar_t          *NewPath;\r
+  int               retval = -1;\r
+\r
+  // Convert name from MBCS to WCS and change '/' to '\\'\r
+  NewPath = NormalizePath( path);\r
+\r
+  if(NewPath != NULL) {\r
+    Status = ShellCreateDirectory( NewPath, &FileHandle);\r
+    if(Status == RETURN_SUCCESS) {\r
+      FileInfo = ShellGetFileInfo( FileHandle);\r
+      Status = RETURN_ABORTED;  // In case ShellGetFileInfo() failed\r
+      if(FileInfo != NULL) {\r
+        FileInfo->Attribute = Omode2EFI(perms);\r
+        Status = ShellSetFileInfo( FileHandle, FileInfo);\r
+        FreePool(FileInfo);\r
+        if(Status == RETURN_SUCCESS) {\r
+          (void)ShellCloseFile(&FileHandle);\r
+          retval = 0;\r
+        }\r
+      }\r
+    }\r
+    errno = EFI2errno(Status);\r
+    EFIerrno = Status;\r
+    free(NewPath);\r
+  }\r
+  return retval;\r
+}\r
+\r
+static\r
+ssize_t\r
+EFIAPI\r
+da_ShellRead(\r
+  IN OUT  struct __filedes   *filp,\r
+  IN OUT  off_t              *offset,\r
+  IN      size_t              BufferSize,\r
+     OUT  VOID               *Buffer\r
+)\r
+{\r
+  ssize_t           BufSize;\r
+  SHELL_FILE_HANDLE FileHandle;\r
+  RETURN_STATUS     Status;\r
+\r
+  if(offset != NULL) {\r
+    BufSize = (ssize_t)da_ShellSeek(filp, *offset, SEEK_SET);\r
+    if(BufSize >= 0) {\r
+      filp->f_offset = BufSize;\r
+    }\r
+  }\r
+\r
+  BufSize = (ssize_t)BufferSize;\r
+  FileHandle = (SHELL_FILE_HANDLE)filp->devdata;\r
+\r
+  Status = ShellReadFile( FileHandle, (UINTN *)&BufSize, Buffer);\r
+  if(Status != RETURN_SUCCESS) {\r
+    EFIerrno = Status;\r
+    errno = EFI2errno(Status);\r
+    if(Status == RETURN_BUFFER_TOO_SMALL) {\r
+      BufSize = -BufSize;\r
+    }\r
+    else {\r
+      BufSize = -1;\r
+    }\r
+  }\r
+  else {\r
+    filp->f_offset += BufSize;  // Advance to where we want to read next.\r
+  }\r
+  return BufSize;\r
+}\r
+\r
+static\r
+ssize_t\r
+EFIAPI\r
+da_ShellWrite(\r
+  IN  struct __filedes     *filp,\r
+  IN  off_t                *offset,\r
+  IN  size_t                BufferSize,\r
+  IN  const void           *Buffer\r
+  )\r
+{\r
+  ssize_t           BufSize;\r
+  SHELL_FILE_HANDLE FileHandle;\r
+  RETURN_STATUS     Status;\r
+  off_t             Position  = 0;\r
+  int               How       = SEEK_SET;\r
+\r
+\r
+  if((offset != NULL) || (filp->Oflags & O_APPEND)) {\r
+    if(filp->Oflags & O_APPEND) {\r
+      Position  = 0;\r
+      How       = SEEK_END;\r
+    }\r
+    else {\r
+      Position  = *offset;\r
+      How       = SEEK_SET;\r
+    }\r
+    BufSize = (ssize_t)da_ShellSeek(filp, Position, How);\r
+    if(BufSize >= 0) {\r
+      filp->f_offset = BufSize;\r
+    }\r
+  }\r
+\r
+  BufSize = (ssize_t)BufferSize;\r
+  FileHandle = (SHELL_FILE_HANDLE)filp->devdata;\r
+\r
+  Status = ShellWriteFile( FileHandle, (UINTN *)&BufSize, (void *)Buffer);\r
+\r
+  if(Status != RETURN_SUCCESS) {\r
+    EFIerrno = Status;\r
+    errno = EFI2errno(Status);\r
+    if(Status == EFI_UNSUPPORTED) {\r
+      errno = EISDIR;\r
+    }\r
+    BufSize = -1;\r
+  }\r
+  else {\r
+    filp->f_offset += BufSize;  // Advance to where we want to write next.\r
+  }\r
+\r
+  return BufSize;\r
+}\r
+\r
+static\r
+int\r
+EFIAPI\r
+da_ShellStat(\r
+  struct __filedes   *filp,\r
+  struct stat        *statbuf,\r
+  void               *Something\r
+  )\r
+{\r
+  SHELL_FILE_HANDLE FileHandle;\r
+  EFI_FILE_INFO    *FileInfo      = NULL;\r
+  UINT64            Attributes;\r
+  RETURN_STATUS     Status;\r
+  mode_t            newmode;\r
+\r
+  FileHandle = (SHELL_FILE_HANDLE)filp->devdata;\r
+\r
+  FileInfo = ShellGetFileInfo( FileHandle);\r
+\r
+  if(FileInfo != NULL) {\r
+    // Got the info, now populate statbuf with it\r
+    statbuf->st_blksize   = S_BLKSIZE;\r
+    statbuf->st_size      = FileInfo->FileSize;\r
+    statbuf->st_physsize  = FileInfo->PhysicalSize;\r
+    statbuf->st_birthtime = Efi2Time( &FileInfo->CreateTime);\r
+    statbuf->st_atime     = Efi2Time( &FileInfo->LastAccessTime);\r
+    statbuf->st_mtime     = Efi2Time( &FileInfo->ModificationTime);\r
+    Attributes = FileInfo->Attribute;\r
+    newmode               = (mode_t)(Attributes << S_EFISHIFT) | S_ACC_READ;\r
+    if((Attributes & EFI_FILE_DIRECTORY) == 0) {\r
+      newmode |= _S_IFREG;\r
+      if((Attributes & EFI_FILE_READ_ONLY) == 0) {\r
+        newmode |= S_ACC_WRITE;\r
+      }\r
+    }\r
+    else {\r
+      newmode |= _S_IFDIR;\r
+    }\r
+    statbuf->st_mode = newmode;\r
+    Status = RETURN_SUCCESS;\r
+  }\r
+  else {\r
+    Status = RETURN_DEVICE_ERROR;\r
+  }\r
+  errno     = EFI2errno(Status);\r
+  EFIerrno  = Status;\r
+\r
+  if(FileInfo != NULL) {\r
+    FreePool(FileInfo);     // Release the buffer allocated by the GetInfo function\r
+  }\r
+  return errno? -1 : 0;\r
+}\r
+\r
+static\r
+int\r
+EFIAPI\r
+da_ShellIoctl(\r
+  struct __filedes   *filp,\r
+  ULONGN              cmd,\r
+  void               *argp       ///< May be a pointer or a value\r
+  )\r
+{\r
+  return 0;\r
+}\r
+\r
+/** Open an abstract Shell File.\r
+**/\r
+int\r
+EFIAPI\r
+da_ShellOpen(\r
+  struct __filedes   *filp,\r
+  void               *DevInstance,\r
+  wchar_t            *Path,\r
+  wchar_t            *Flags\r
+  )\r
+{\r
+  UINT64                OpenMode;\r
+  UINT64                Attributes;\r
+  SHELL_FILE_HANDLE     FileHandle;\r
+  GenericInstance      *Gip;\r
+  char                 *NPath;\r
+  RETURN_STATUS         Status;\r
+  int                   oflags;\r
+\r
+  EFIerrno = RETURN_SUCCESS;\r
+\r
+  //Attributes = Omode2EFI(mode);\r
+  Attributes = 0;\r
+\r
+  // Convert oflags to Attributes\r
+  oflags = filp->Oflags;\r
+  OpenMode = Oflags2EFI(oflags);\r
+  if(OpenMode == 0) {\r
+    errno = EINVAL;\r
+    return -1;\r
+  }\r
+\r
+  /* Do we care if the file already exists?\r
+     If O_TRUNC, then delete the file.  It will be created anew subsequently.\r
+     If O_EXCL, then error if the file exists and O_CREAT is set.\r
+\r
+  !!!!!!!!! Change this to use ShellSetFileInfo() to actually truncate the file\r
+  !!!!!!!!! instead of deleting and re-creating it.\r
+  */\r
+  if((oflags & O_TRUNC) || ((oflags & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT))) {\r
+    Status = ShellIsFile( Path );\r
+    if(Status == RETURN_SUCCESS) {\r
+      // The file exists\r
+      if(oflags & O_TRUNC) {\r
+        NPath = AllocateZeroPool(1024);\r
+        if(NPath == NULL) {\r
+          errno = ENOMEM;\r
+          EFIerrno = RETURN_OUT_OF_RESOURCES;\r
+          return -1;\r
+        }\r
+        wcstombs(NPath, Path, 1024);\r
+        // We do a truncate by deleting the existing file and creating a new one.\r
+        if(unlink(NPath) != 0) {\r
+          filp->f_iflags = 0;    // Release our reservation on this FD\r
+          FreePool(NPath);\r
+          return -1;  // errno and EFIerrno are already set.\r
+        }\r
+        FreePool(NPath);\r
+      }\r
+      else if((oflags & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT)) {\r
+        errno = EEXIST;\r
+        EFIerrno = RETURN_ACCESS_DENIED;\r
+        filp->f_iflags = 0;    // Release our reservation on this FD\r
+        return -1;\r
+      }\r
+    }\r
+  }\r
+\r
+  // Call the EFI Shell's Open function\r
+  Status = ShellOpenFileByName( Path, &FileHandle, OpenMode, Attributes);\r
+  if(RETURN_ERROR(Status)) {\r
+    filp->f_iflags = 0;    // Release our reservation on this FD\r
+    // Set errno based upon Status\r
+    errno = EFI2errno(Status);\r
+    EFIerrno = Status;\r
+    return -1;\r
+  }\r
+  // Successfully got a regular File\r
+  filp->f_iflags |= S_IFREG;\r
+\r
+  // Update the info in the fd\r
+  filp->devdata = (void *)FileHandle;\r
+\r
+  Gip = (GenericInstance *)DevInstance;\r
+  filp->f_offset = 0;\r
+  filp->f_ops = &Gip->Abstraction;\r
+//  filp->devdata = FileHandle;\r
+\r
+  return 0;\r
+}\r
+\r
+#include  <sys/poll.h>\r
+/*  Returns a bit mask describing which operations could be completed immediately.\r
+\r
+    For now, assume the file system, via the shell, is always ready.\r
+\r
+    (POLLIN | POLLRDNORM)   The file system is ready to be read.\r
+    (POLLOUT)               The file system is ready for output.\r
+\r
+*/\r
+static\r
+short\r
+EFIAPI\r
+da_ShellPoll(\r
+  struct __filedes   *filp,\r
+  short               events\r
+  )\r
+{\r
+  UINT32      RdyMask;\r
+  short       retval = 0;\r
+\r
+  RdyMask = (UINT32)filp->Oflags;\r
+\r
+  switch(RdyMask & O_ACCMODE) {\r
+    case O_RDONLY:\r
+      retval = (POLLIN | POLLRDNORM);\r
+      break;\r
+\r
+    case O_WRONLY:\r
+      retval = POLLOUT;\r
+      break;\r
+\r
+    case O_RDWR:\r
+      retval = (POLLIN | POLLRDNORM | POLLOUT);\r
+      break;\r
+\r
+    default:\r
+      retval = POLLERR;\r
+      break;\r
+  }\r
+  return (retval & (events | POLL_RETONLY));\r
+}\r
+\r
+static\r
+int\r
+EFIAPI\r
+da_ShellRename(\r
+  const char   *from,\r
+  const char   *to\r
+  )\r
+{\r
+  RETURN_STATUS       Status;\r
+  EFI_FILE_INFO      *NewFileInfo;\r
+  EFI_FILE_INFO      *OldFileInfo;\r
+  char               *NewFn;\r
+  int                 OldFd;\r
+  SHELL_FILE_HANDLE   FileHandle;\r
+\r
+  // Open old file\r
+  OldFd = open(from, O_RDWR, 0);\r
+  if(OldFd >= 0) {\r
+    FileHandle = (SHELL_FILE_HANDLE)gMD->fdarray[OldFd].devdata;\r
+\r
+    NewFileInfo = malloc(sizeof(EFI_FILE_INFO) + PATH_MAX);\r
+    if(NewFileInfo != NULL) {\r
+      OldFileInfo = ShellGetFileInfo( FileHandle);\r
+      if(OldFileInfo != NULL) {\r
+        // Copy the Old file info into our new buffer, and free the old.\r
+        memcpy(OldFileInfo, NewFileInfo, sizeof(EFI_FILE_INFO));\r
+        FreePool(OldFileInfo);\r
+        // Strip off all but the file name portion of new\r
+        NewFn = strrchr(to, '/');\r
+        if(NewFn == NULL) {\r
+          NewFn = strrchr(to, '\\');\r
+          if(NewFn == NULL) {\r
+            NewFn = (char *)to;\r
+          }\r
+        }\r
+        // Convert new name from MBCS to WCS\r
+        (void)AsciiStrToUnicodeStr( NewFn, gMD->UString);\r
+        // Copy the new file name into our new file info buffer\r
+        wcsncpy(NewFileInfo->FileName, gMD->UString, wcslen(gMD->UString)+1);\r
+        // Apply the new file name\r
+        Status = ShellSetFileInfo(FileHandle, NewFileInfo);\r
+        free(NewFileInfo);\r
+        if(Status == EFI_SUCCESS) {\r
+          // File has been successfully renamed.  We are DONE!\r
+          return 0;\r
+        }\r
+        errno = EFI2errno( Status );\r
+        EFIerrno = Status;\r
+      }\r
+      else {\r
+        errno = EIO;\r
+      }\r
+    }\r
+    else {\r
+      errno = ENOMEM;\r
+    }\r
+  }\r
+  return -1;\r
+}\r
+\r
+static\r
+int\r
+EFIAPI\r
+da_ShellRmdir(\r
+  struct __filedes   *filp\r
+  )\r
+{\r
+  SHELL_FILE_HANDLE FileHandle;\r
+  RETURN_STATUS     Status = RETURN_SUCCESS;\r
+  EFI_FILE_INFO     *FileInfo = NULL;\r
+  int               Count = 0;\r
+  BOOLEAN           NoFile = FALSE;\r
+\r
+  errno = 0;    // Make it easier to see if we have an error later\r
+\r
+  FileHandle = (SHELL_FILE_HANDLE)filp->devdata;\r
+\r
+  FileInfo = ShellGetFileInfo(FileHandle);\r
+  if(FileInfo != NULL) {\r
+    if((FileInfo->Attribute & EFI_FILE_DIRECTORY) == 0) {\r
+      errno = ENOTDIR;\r
+    }\r
+    else {\r
+      // See if the directory has any entries other than ".." and ".".\r
+      FreePool(FileInfo);  // Free up the buffer from ShellGetFileInfo()\r
+      Status = ShellFindFirstFile( FileHandle, &FileInfo);\r
+      if(Status == RETURN_SUCCESS) {\r
+        ++Count;\r
+        while(Count < 3) {\r
+          Status = ShellFindNextFile( FileHandle, FileInfo, &NoFile);\r
+          if(Status == RETURN_SUCCESS) {\r
+            if(NoFile) {\r
+              break;\r
+            }\r
+            ++Count;\r
+          }\r
+          else {\r
+            Count = 99;\r
+          }\r
+        }\r
+        FreePool(FileInfo);   // Free buffer from ShellFindFirstFile()\r
+        if(Count < 3) {\r
+          // Directory is empty\r
+          Status = ShellDeleteFile( &FileHandle);\r
+          if(Status == RETURN_SUCCESS) {\r
+            EFIerrno = RETURN_SUCCESS;\r
+            return 0;\r
+            /* ######## SUCCESSFUL RETURN ######## */\r
+          }\r
+        }\r
+        else {\r
+          if(Count == 99) {\r
+            errno = EIO;\r
+          }\r
+          else {\r
+            errno = ENOTEMPTY;\r
+          }\r
+        }\r
+      }\r
+    }\r
+  }\r
+  else {\r
+    errno = EIO;\r
+  }\r
+  EFIerrno = Status;\r
+  if(errno == 0) {\r
+    errno = EFI2errno( Status );\r
+  }\r
+  return -1;\r
+}\r
+\r
+/** Construct an instance of the abstract Shell device.\r
+\r
+    Allocate the instance structure and populate it with the information for\r
+    the device.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+__ctor_DevShell(\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+)\r
+{\r
+  GenericInstance    *Stream;\r
+  DeviceNode     *Node;\r
+  RETURN_STATUS   Status;\r
+\r
+  Stream = (GenericInstance *)AllocateZeroPool(sizeof(GenericInstance));\r
+  if(Stream == NULL) {\r
+    return RETURN_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Stream->Cookie      = CON_COOKIE;\r
+  Stream->InstanceNum = 1;\r
+  Stream->Dev = NULL;\r
+  Stream->Abstraction.fo_close    = &da_ShellClose;\r
+  Stream->Abstraction.fo_read     = &da_ShellRead;\r
+  Stream->Abstraction.fo_write    = &da_ShellWrite;\r
+  Stream->Abstraction.fo_fcntl    = &fnullop_fcntl;\r
+  Stream->Abstraction.fo_poll     = &da_ShellPoll;\r
+  Stream->Abstraction.fo_flush    = &fnullop_flush;\r
+  Stream->Abstraction.fo_stat     = &da_ShellStat;\r
+  Stream->Abstraction.fo_ioctl    = &fbadop_ioctl;\r
+  Stream->Abstraction.fo_delete   = &da_ShellDelete;\r
+  Stream->Abstraction.fo_rmdir    = &da_ShellRmdir;\r
+  Stream->Abstraction.fo_mkdir    = &da_ShellMkdir;\r
+  Stream->Abstraction.fo_rename   = &da_ShellRename;\r
+  Stream->Abstraction.fo_lseek    = &da_ShellSeek;\r
+\r
+  Node = __DevRegister(NULL, NULL, &da_ShellOpen, Stream, 1, sizeof(GenericInstance), O_RDWR);\r
+  Status = EFIerrno;\r
+  Stream->Parent = Node;\r
+\r
+  return  Status;\r
+}\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+__dtor_DevShell(\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+)\r
+{\r
+  if(daDefaultDevice != NULL) {\r
+    if(daDefaultDevice->InstanceList != NULL) {\r
+      FreePool(daDefaultDevice->InstanceList);\r
+    }\r
+    FreePool(daDefaultDevice);\r
+  }\r
+  return RETURN_SUCCESS;\r
+}\r
diff --git a/StdLib/LibC/Uefi/Devices/Utility/DevGenisis.c b/StdLib/LibC/Uefi/Devices/Utility/DevGenisis.c
new file mode 100644 (file)
index 0000000..2bdb33a
--- /dev/null
@@ -0,0 +1,139 @@
+/** @file\r
+    Device Abstraction: device creation utility functions.\r
+\r
+    Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/BaseLib.h>\r
+#include  <Library/MemoryAllocationLib.h>\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include  <errno.h>\r
+#include  <sys/poll.h>\r
+#include  <kfile.h>\r
+#include  <Device/Device.h>\r
+#include  <MainData.h>\r
+\r
+LIST_ENTRY    daDeviceList    = INITIALIZE_LIST_HEAD_VARIABLE(daDeviceList);\r
+DeviceNode   *daDefaultDevice = NULL;     ///< Device to use if nothing else found\r
+DeviceNode   *daRootDevice    = NULL;     ///< Device containing the root file system\r
+DeviceNode   *daCurrentDevice = NULL;     ///< Device currently being accessed\r
+\r
+/* Commonly used fileops\r
+      fnullop_*   Does nothing and returns success.\r
+      fbadop_*    Does nothing and returns EPERM\r
+*/\r
+int     fnullop_fcntl (struct __filedes *filp, UINT32 Cmd, void *p3, void *p4)\r
+{ return 0; }\r
+\r
+short  fnullop_poll  (struct __filedes *filp, short Events)\r
+{\r
+  return ((POLLIN | POLLRDNORM | POLLOUT) & Events);\r
+}\r
+\r
+int     fnullop_flush (struct __filedes *filp)\r
+{ return 0; }\r
+\r
+int     fbadop_stat   (struct __filedes *filp, struct stat *StatBuf, void *Buf)\r
+{ return -EPERM;  }\r
+\r
+int     fbadop_ioctl  (struct __filedes *filp, ULONGN Cmd, void *argp)\r
+{ return -EPERM;  }\r
+\r
+int     fbadop_delete (struct __filedes *filp)\r
+{ return -EPERM;  }\r
+\r
+int     fbadop_mkdir  (const char *path, __mode_t perms)\r
+{ return -EPERM;  }\r
+\r
+int     fbadop_rename   (const char *from, const char *to)\r
+{ return -EPERM;  }\r
+\r
+int     fbadop_rmdir    (struct __filedes *filp)\r
+{ return -EPERM;  }\r
+\r
+/** Add a new device to the device list.\r
+    If both DevName and DevProto are NULL, register this as the Default device.\r
+\r
+    @param  DevName       Name of the device to add.\r
+    @param  DevProto      Pointer to the GUID identifying the protocol associated with this device.\r
+                          If DevProto is NULL, startup code will not try to find instances\r
+                          of this device.\r
+    @param  OpenFunc      Pointer to the device's Open function.\r
+    @param  InstanceList  Optional pointer to the device's initialized instance list.\r
+                          If InstanceList is NULL, the application startup code will\r
+                          scan for instances of the protocol identified by DevProto and\r
+                          populate the InstanceList in the order those protocols are found.\r
+    @param  NumInstance   Number of instances in InstanceList.\r
+    @param  Modes         Bit-mapped flags indicating operations (R, W, RW, ...) permitted to this device.\r
+\r
+**/\r
+DeviceNode *\r
+EFIAPI\r
+__DevRegister(\r
+  IN const CHAR16          *DevName,\r
+  IN GUID                  *DevProto,\r
+  IN FO_OPEN                OpenFunc,\r
+  IN void                  *InstanceList,\r
+  IN int                    NumInstance,\r
+  IN UINT32                 InstanceSize,\r
+  IN UINT32                 Modes\r
+  )\r
+{\r
+  DeviceNode         *Node;\r
+  GenericInstance    *GIp;\r
+  char               *GenPtr;\r
+  int                 i;\r
+\r
+  /* Validate parameters */\r
+  if(((DevName == NULL) && (DevProto != NULL)) ||\r
+      (OpenFunc == NULL)) {\r
+    EFIerrno = RETURN_INVALID_PARAMETER;\r
+    return NULL;\r
+  }\r
+  Node = (DeviceNode *)AllocateZeroPool(sizeof(DeviceNode));\r
+  if(Node == NULL) {\r
+    EFIerrno = RETURN_OUT_OF_RESOURCES;\r
+    return NULL;\r
+  }\r
+\r
+  Node->DevName       = DevName;\r
+  Node->DevProto      = DevProto;\r
+  Node->InstanceList  = InstanceList;\r
+  Node->OpenFunc      = OpenFunc;\r
+  Node->InstanceSize  = InstanceSize;\r
+  Node->NumInstances  = NumInstance;\r
+  Node->OpModes       = Modes;\r
+\r
+  /* Update the Parent member of each element of the InstanceList */\r
+  if(InstanceList != NULL) {\r
+    GenPtr = InstanceList;\r
+\r
+    for(i = 0; i < NumInstance; ++i) {    // Iterate through each element of InstanceList\r
+      GIp = (GenericInstance *)GenPtr;\r
+      GIp->Parent = Node;                     // Initializing the Parent member & InstanceNum\r
+      //GIp->InstanceNum = i;\r
+      GenPtr += InstanceSize;\r
+    }\r
+  }\r
+  if(DevName == NULL) {\r
+    if(daDefaultDevice != NULL) {\r
+      EFIerrno = RETURN_INVALID_PARAMETER;\r
+      return NULL;\r
+    }\r
+    daDefaultDevice = Node;\r
+  }\r
+  else {\r
+    (void) InsertTailList(&daDeviceList, &Node->DevList);\r
+  }\r
+  EFIerrno = RETURN_SUCCESS;\r
+  return Node;\r
+}\r
diff --git a/StdLib/LibC/Uefi/Devices/Utility/DevSearch.c b/StdLib/LibC/Uefi/Devices/Utility/DevSearch.c
new file mode 100644 (file)
index 0000000..b0fc7ba
--- /dev/null
@@ -0,0 +1,112 @@
+/** @file\r
+    Device Abstraction: Search device list for a matching device.\r
+\r
+    Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <Uefi.h>\r
+#include  <Library/BaseLib.h>\r
+#include  <Library/BaseMemoryLib.h>\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include  <errno.h>\r
+#include  <kfile.h>\r
+#include  <Device/Device.h>\r
+#include  <MainData.h>\r
+\r
+/** Find a DeviceNode matching DevName or DevProto, or both.\r
+\r
+    If DevName is NULL, then the device name is not used in the search.\r
+    If DevProto is NULL, then the protocol GUID is not used in the search.\r
+    If both are NULL, then INVALID_PARAMETER is returned.\r
+    If both DevName and DevProto are specified, then both must match.\r
+    If both are specified but only one matches, then DEVICE_ERROR is returned.\r
+\r
+    @param  DevName     Name of the Device Abstraction to find.\r
+    @param  DevProto    GUID of the Protocol associated with the Device Abstraction.\r
+    @param  Node        Pointer to the pointer to receive the found Device Node's address.\r
+\r
+    @retval RETURN_SUCCESS              The desired Device Node was found.\r
+    @retval RETURN_INVALID_PARAMETER    Both DevName and DevProto are NULL or Node is NULL.\r
+    @retval RETURN_DEVICE_ERROR         DevName matched but DevProto did not.\r
+    @retval RETURN_NOT_FOUND            The desired device was not found.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+__DevSearch(\r
+  IN     CHAR16        *DevName,\r
+  IN     GUID          *DevProto,\r
+     OUT DeviceNode   **Node\r
+  )\r
+{\r
+  RETURN_STATUS     Status = RETURN_NOT_FOUND;\r
+  DeviceNode       *WorkNode;\r
+  INT32             DevMatched;\r
+\r
+  if(((DevName == NULL) && (DevProto == NULL)) || (Node == NULL)) {\r
+    Status = RETURN_INVALID_PARAMETER;\r
+  }\r
+  else {\r
+    if(IsListEmpty((LIST_ENTRY *)&daDeviceList)) {\r
+      Status = RETURN_NOT_FOUND;\r
+    }\r
+    else {\r
+      /* Traverse the list of Device Nodes hunting for a match */\r
+      WorkNode = (DeviceNode *)GetFirstNode((LIST_ENTRY *)&daDeviceList);\r
+      do {\r
+        /* Use DevMatched to keep track of the three match conditions. */\r
+        DevMatched = 0;\r
+        if(DevName != NULL) {\r
+          ++DevMatched;\r
+          if(wcsncmp(DevName, WorkNode->DevName, wcslen(WorkNode->DevName)) == 0) {\r
+            ++DevMatched;\r
+          }\r
+        }\r
+        /* At this point, DevMatched has one of the following values:\r
+              0   DevName == NULL, no name comparison\r
+              1   DevName did not match WorkNode's name\r
+              2   DevName MATCHED\r
+        */\r
+        if((DevMatched != 1) && (DevProto != NULL) && (WorkNode->DevProto != NULL)) {\r
+          /*  Only bother with the GUID comparison if:\r
+                * There was NOT a name mismatch\r
+                * DevProto is NOT NULL -- there is a GUID to compare\r
+                * WorkNode->DevProto is NOT NULL\r
+          */\r
+          if(CompareGuid(DevProto, WorkNode->DevProto)) {\r
+            // GUIDs matched, we found it\r
+            Status = RETURN_SUCCESS;\r
+            *Node = WorkNode;\r
+            break;\r
+          }\r
+          else {\r
+            // GUIDs did not match\r
+            if(DevMatched == 2) {\r
+              // Name matched, GUID did not!\r
+              Status = RETURN_DEVICE_ERROR;\r
+              break;    // Don't try any more, we have an internal problem\r
+            }\r
+          }\r
+        }\r
+        else {\r
+          if(DevMatched == 2) {\r
+            // Device Name matched, GUIDs skipped\r
+            Status = RETURN_SUCCESS;\r
+            *Node = WorkNode;\r
+            break;\r
+          }\r
+        }\r
+        // Check the next device in the list\r
+        WorkNode = (DeviceNode *)GetNextNode(&daDeviceList, (LIST_ENTRY *)WorkNode);\r
+      } while(&daDeviceList != (LIST_ENTRY *)WorkNode);\r
+    }\r
+  }\r
+  return Status;\r
+}\r
diff --git a/StdLib/LibC/Uefi/Devices/Utility/Path.c b/StdLib/LibC/Uefi/Devices/Utility/Path.c
new file mode 100644 (file)
index 0000000..92bb1a2
--- /dev/null
@@ -0,0 +1,382 @@
+/** @file\r
+    Device Abstraction: Path manipulation utilities.\r
+\r
+    Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+    This program and the accompanying materials are licensed and made available under\r
+    the terms and conditions of the BSD License that accompanies this distribution.\r
+    The full text of the license may be found at\r
+    http://opensource.org/licenses/bsd-license.php.\r
+\r
+    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+#include  <Library/BaseLib.h>\r
+\r
+#include  <LibConfig.h>\r
+\r
+#include  <errno.h>\r
+#include  <stdlib.h>\r
+#include  <wchar.h>\r
+#include  <wctype.h>\r
+#include  <kfile.h>\r
+#include  <Device/Device.h>\r
+#include  <MainData.h>\r
+\r
+/** Identify the type of path pointed to by Path.\r
+\r
+    Paths are classified based upon their initial character sequences.\r
+      ^\\       Absolute Path\r
+      ^\.       Relative Path\r
+      ^[^:\\]:  Mapping Path\r
+      .*        Relative Path\r
+\r
+    Mapping paths are broken into two parts at the ':'.  The part to the left of the ':'\r
+    is the Map Name, pointed to by Path, and the part to the right of the ':' is pointed\r
+    to by NewPath.\r
+\r
+    If Path was not a Mapping Path, then NewPath is set to Path.\r
+\r
+    @param[in]    Path      Pointer to the path to be classified.\r
+    @param[out]   NewPath   Pointer to the path portion of a mapping path.\r
+    @param[out]   Length    Length of the Map Name portion of the path.\r
+\r
+    @retval PathAbsolute  Path is an absolute path. NewPath points to the first '\'.\r
+    @retval PathRelative  Path is a relative path. NewPath = Path.\r
+    @retval PathMapping   Path is a mapping path.  NewPath points to the character following ':'.\r
+    @retval PathError     Path is NULL.\r
+**/\r
+PATH_CLASS\r
+EFIAPI\r
+ClassifyPath(\r
+  IN  wchar_t    *        Path,\r
+  OUT wchar_t   **        NewPath,\r
+  OUT int        * const  Length\r
+  )\r
+{\r
+  size_t    MapLen;\r
+\r
+  if(Path == NULL) {\r
+    return PathError;   // Bad parameter\r
+  }\r
+  if(NewPath != NULL) {\r
+    *NewPath = Path;    // Setup default condition\r
+  }\r
+  if((*Path == L'\\') || (*Path == L'\0')) {\r
+    return PathAbsolute;\r
+  }\r
+  if(*Path == L'.') {\r
+    return PathRelative;\r
+  }\r
+  /* The easy stuff has been done, now see if this is a mapping path.\r
+      See if there is a ':' in Path that isn't the first character and is before\r
+      any '\\' characters.\r
+  */\r
+  MapLen = wcscspn(Path, L"\\:");\r
+  if(Length != NULL) {\r
+    *Length = (int)MapLen;\r
+  }\r
+  /*  MapLen == 0       means that the first character is a ':'\r
+             == PathLen means that there are no '\\' or ':'\r
+      Otherwise, Path[MapLen] == ':'  for a mapping path\r
+                              or '\\' for a relative path.\r
+  */\r
+  if(MapLen == 0) {\r
+    return PathError;\r
+  }\r
+  if(Path[MapLen] == L':') {\r
+    if(NewPath != NULL) {\r
+      *NewPath = &Path[MapLen + 1];   // Point to character after then ':'.  Might be '\0'.\r
+    }\r
+    return PathMapping;\r
+  }\r
+  return PathRelative;\r
+}\r
+\r
+/*  Normalize a narrow-character path and produce a wide-character path\r
+    that has forward slashes replaced with backslashes.\r
+    Backslashes are directory separators in UEFI File Paths.\r
+\r
+    It is the caller's responsibility to eventually free() the returned buffer.\r
+\r
+    @param[in]    path    A pointer to the narrow-character path to be normalized.\r
+\r
+    @return     A pointer to a buffer containing the normalized, wide-character, path.\r
+*/\r
+wchar_t *\r
+NormalizePath( const char *path)\r
+{\r
+  wchar_t  *temp;\r
+  wchar_t  *OldPath;\r
+  wchar_t  *NewPath;\r
+  size_t    Length;\r
+\r
+  OldPath = AsciiStrToUnicodeStr(path, gMD->UString);\r
+  Length  = wcslen(OldPath) + 1;\r
+\r
+  NewPath = calloc(Length, sizeof(wchar_t));\r
+  if(NewPath != NULL) {\r
+    temp = NewPath;\r
+    for( ; *OldPath; ++OldPath) {\r
+      if(*OldPath == L'/') {\r
+        *temp = L'\\';\r
+      }\r
+      else {\r
+        *temp = *OldPath;\r
+      }\r
+      ++temp;\r
+    }\r
+  }\r
+  else {\r
+    errno     = ENOMEM;\r
+    EFIerrno  = RETURN_OUT_OF_RESOURCES;\r
+  }\r
+  return NewPath;\r
+}\r
+\r
+/** Process a wide character string representing a Mapping Path and extract the instance number.\r
+\r
+    The instance number is the sequence of decimal digits immediately to the left\r
+    of the ":" in the Map Name portion of a Mapping Path.\r
+\r
+    This function is called with a pointer to beginning of the Map Name.\r
+    Thus Path[Length] must be a ':' and Path[Length - 1] must be a decimal digit.\r
+    If either of these are not true, an instance value of 0 is returned.\r
+\r
+    If Path is NULL, an instance value of 0 is returned.\r
+\r
+    @param[in]  Path    Points to the beginning of a Mapping Path\r
+    @param[in]  Length  Number of valid characters to the left of the ':'\r
+\r
+    @return   Returns either 0 or the value of the contiguous digits to the left of the ':'.\r
+**/\r
+int\r
+EFIAPI\r
+PathInstance(\r
+  const wchar_t  *Path,\r
+        int       Length\r
+  )\r
+{\r
+  wchar_t    *temp;\r
+  int         instance    = 0;\r
+\r
+  if((Path != NULL) && (Path[Length] == L':') && (Length > 0)) {\r
+    for(temp = __UNCONST(&Path[Length - 1]); Length > 0; --Length) {\r
+      if(!iswdigit(*temp)) {\r
+        break;\r
+      }\r
+      --temp;\r
+    }\r
+    instance = (int)wcstol(temp+1, NULL, 10);\r
+  }\r
+  return instance;\r
+}\r
+\r
+/** Transform a relative path into an absolute path.\r
+\r
+    If Path is NULL, return NULL.\r
+    Otherwise, pre-pend the CWD to Path then process the resulting path to:\r
+      - Replace "/./" with "/"\r
+      - Replace "/<dirname>/../" with "/"\r
+      - Do not allow one to back up past the root, "/"\r
+\r
+    Also sets the Current Working Device to the Root Device.\r
+\r
+    Path must be a previously allocated buffer.  PathAdjust will\r
+    allocate a new buffer to hold the results of the transformation\r
+    and free Path.  A pointer to the newly allocated buffer is returned.\r
+\r
+    @param[in]  Path    A pointer to the path to be transformed.  This buffer\r
+                        will always be freed.\r
+\r
+    @return   A pointer to a buffer containing the transformed path.\r
+**/\r
+wchar_t *\r
+EFIAPI\r
+PathAdjust(\r
+  wchar_t *Path\r
+  )\r
+{\r
+  wchar_t    *NewPath;\r
+\r
+  NewPath = calloc(PATH_MAX, sizeof(wchar_t));\r
+  if(NewPath != NULL) {\r
+    wmemcpy(NewPath, Path, PATH_MAX);\r
+  }\r
+  else {\r
+    errno = ENOMEM;\r
+  }\r
+  free(Path);\r
+  return NewPath;\r
+}\r
+\r
+/** Replace the leading portion of Path with any aliases.\r
+\r
+    Aliases are read from /etc/fstab.  If there is an associated device, the\r
+    Current Working Device is set to that device.\r
+\r
+    Path must be a previously allocated buffer.  PathAlias will\r
+    allocate a new buffer to hold the results of the transformation\r
+    then free Path.  A pointer to the newly allocated buffer is returned.\r
+\r
+    @param[in]    Path    A pointer to the original, unaliased, path.  This\r
+                          buffer is always freed.\r
+    @param[out]   Node    Filled in with a pointer to the Device Node describing\r
+                          the device abstraction associated with this path.\r
+\r
+    @return     A pointer to a buffer containing the aliased path.\r
+**/\r
+wchar_t *\r
+EFIAPI\r
+PathAlias(\r
+  wchar_t      *Path,\r
+  DeviceNode  **Node\r
+  )\r
+{\r
+  wchar_t    *NewPath;\r
+\r
+  NewPath = calloc(PATH_MAX, sizeof(wchar_t));\r
+  if(NewPath != NULL) {\r
+    wmemcpy(NewPath, Path, PATH_MAX);\r
+  }\r
+  else {\r
+    errno = ENOMEM;\r
+  }\r
+  free(Path);\r
+  *Node = NULL;\r
+  return NewPath;\r
+}\r
+\r
+/** Parse a path producing the target device, device instance, and file path.\r
+\r
+    @param[in]    path\r
+    @param[out]   FullPath\r
+    @param[out]   DevNode\r
+    @param[out]   Which\r
+\r
+    @retval   RETURN_SUCCESS              The path was parsed successfully.\r
+    @retval   RETURN_NOT_FOUND            The path does not map to a valid device.\r
+    @retval   RETURN_OUT_OF_RESOURCES     Insufficient memory to calloc a MapName buffer.\r
+                                          The errno variable is set to ENOMEM.\r
+    @retval   RETURN_INVALID_PARAMETER    The path parameter is not valid.\r
+                                          The errno variable is set to EINVAL.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+ParsePath(\r
+  IN    const char   *path,\r
+  OUT   wchar_t     **FullPath,\r
+  OUT   DeviceNode  **DevNode,\r
+  OUT   int          *Which\r
+  )\r
+{\r
+  int                 MapLen;\r
+  PATH_CLASS          PathClass;\r
+  wchar_t            *NewPath;\r
+  wchar_t            *WPath     = NULL;\r
+  wchar_t            *MPath     = NULL;\r
+  DeviceNode         *Node      = NULL;\r
+  RETURN_STATUS       Status    = RETURN_NOT_FOUND;\r
+  int                 Instance  = 0;\r
+  BOOLEAN             ReMapped;\r
+\r
+  ReMapped  = FALSE;\r
+\r
+  // Convert name from MBCS to WCS and change '/' to '\\'\r
+  WPath = NormalizePath( path);\r
+  PathClass = ClassifyPath(WPath, &NewPath, &MapLen);\r
+\r
+reclassify:\r
+  switch(PathClass) {\r
+    case PathMapping:\r
+      if(!ReMapped) {\r
+        if((NewPath == NULL) || (*NewPath == L'\0')) { /* Nothing after the ':' */\r
+          PathClass = PathAbsolute;\r
+        }\r
+        else {\r
+          Instance = PathInstance(WPath, MapLen);\r
+          PathClass = ClassifyPath(NewPath, NULL, NULL);\r
+        }\r
+        ReMapped = TRUE;\r
+        if(WPath[MapLen] == L':') {\r
+          // Get the Map Name, including the trailing ':'. */\r
+          MPath = calloc(MapLen+2, sizeof(wchar_t));\r
+          if(MPath != NULL) {\r
+            wmemcpy(MPath, WPath, MapLen+2);\r
+          }\r
+          else {\r
+            errno = ENOMEM;\r
+            Status = RETURN_OUT_OF_RESOURCES;\r
+            break;    // Exit the switch(PathClass) statement.\r
+          }\r
+        }\r
+        if(WPath != NewPath) {\r
+          /* Shift the RHS of the path down to the start of the buffer. */\r
+          wmemmove(WPath, NewPath, wcslen(NewPath)+1);\r
+          NewPath = WPath;\r
+        }\r
+        goto reclassify;\r
+      }\r
+      /*  Fall through to PathError if Remapped.\r
+          This means that the path looked like "foo:bar:something".\r
+      */\r
+\r
+    case PathError:\r
+      errno = EINVAL;\r
+      Status = RETURN_INVALID_PARAMETER;\r
+      break;\r
+\r
+    case PathRelative:\r
+      /*  Transform a relative path into an Absolute path.\r
+          Prepends CWD and handles ./ and ../ entries.\r
+          It is the caller's responsibility to free the space\r
+          allocated to WPath.\r
+      */\r
+      WPath = PathAdjust(NewPath);    // WPath was malloc()ed by PathAdjust\r
+\r
+    case PathAbsolute:\r
+      /*  Perform any path aliasing.  For example: /dev/foo -> { node.foo, "" }\r
+          The current volume and directory are updated in the path as needed.\r
+          It is the caller's responsibility to free the space\r
+          allocated to WPath.\r
+      */\r
+    Status = RETURN_SUCCESS;\r
+      WPath = PathAlias(WPath, &Node);       // PathAlias frees its argument and malloc()s a new one.\r
+      break;\r
+  }\r
+  if(!RETURN_ERROR(Status)) {\r
+    *FullPath = WPath;\r
+    *Which    = Instance;\r
+\r
+    /*  At this point, WPath is an absolute path,\r
+        MPath is either NULL or points to the Map Name,\r
+        and Instance is the instance number.\r
+    */\r
+    if(MPath == NULL) {\r
+      /* This is NOT a mapped path. */\r
+      if(Node == NULL) {\r
+        Node = daDefaultDevice;\r
+      }\r
+      if(Node != NULL) {\r
+        Status = RETURN_SUCCESS;\r
+      }\r
+    }\r
+    else {\r
+      /* This is a mapped path. */\r
+      Status = __DevSearch( MPath, NULL, &Node);\r
+      if(Status == RETURN_NOT_FOUND) {\r
+        Node = daDefaultDevice;\r
+\r
+        if(Node != NULL) {\r
+          Status = RETURN_SUCCESS;\r
+        }\r
+      }\r
+    }\r
+    if(DevNode != NULL) {\r
+      *DevNode = Node;\r
+    }\r
+  }\r
+  if(MPath != NULL) {\r
+    free(MPath);    // We don't need this any more.\r
+  }\r
+  return Status;\r
+}\r
diff --git a/StdLib/LibC/Uefi/Devices/daConsole.inf b/StdLib/LibC/Uefi/Devices/daConsole.inf
new file mode 100644 (file)
index 0000000..17865e4
--- /dev/null
@@ -0,0 +1,63 @@
+## @file\r
+#  Standard C library: Console Device Abstraction.\r
+#\r
+#  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+#  This program and the accompanying materials are licensed and made available\r
+#  under the terms and conditions of the BSD License which accompanies this\r
+#  distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php.\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                   = 0x00010005\r
+  BASE_NAME                     = DevConsole\r
+  FILE_GUID                     = 42c078ef-14a8-4e30-9329-6f12d796e54a\r
+  MODULE_TYPE                   = UEFI_APPLICATION\r
+  VERSION_STRING                = 1.0\r
+  LIBRARY_CLASS                 = DevConsole\r
+  CONSTRUCTOR                   = __Cons_construct\r
+  DESTRUCTOR                    = __Cons_deconstruct\r
+\r
+#\r
+#  VALID_ARCHITECTURES          = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+  Console/daConsole.c\r
+\r
+[Packages]\r
+  StdLib/StdLib.dec\r
+  StdLibPrivateInternalFiles/DoNotUse.dec\r
+  MdePkg/MdePkg.dec\r
+  ShellPkg/ShellPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  BaseMemoryLib\r
+  MemoryAllocationLib\r
+  UefiBootServicesTableLib\r
+  LibC\r
+  LibWchar\r
+  LibUefi\r
+  DevUtility\r
+\r
+[Protocols]\r
+  gEfiSimpleTextInProtocolGuid\r
+  gEfiSimpleTextOutProtocolGuid\r
+\r
+################################################################\r
+#\r
+# The Build Options, below, are only used when building the C library.\r
+# DO NOT use them when building your application!\r
+# Nasty things could happen if you do.\r
+#\r
+# /Oi is required for Microsoft VC++ to allow "intrinsic" functions to be\r
+# defined in this library.\r
+#\r
+#[BuildOptions]\r
+#  MSFT:*_*_*_CC_FLAGS     = /Oi-\r
diff --git a/StdLib/LibC/Uefi/Devices/daShell.inf b/StdLib/LibC/Uefi/Devices/daShell.inf
new file mode 100644 (file)
index 0000000..7b56f37
--- /dev/null
@@ -0,0 +1,63 @@
+## @file\r
+#  Standard C library: Shell-Hosted Device Abstraction.\r
+#\r
+#   When this library is included in an application, it creates the default device.\r
+#   This allows every device type not recognized to be passed to the shell for processing.\r
+#\r
+#  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+#  This program and the accompanying materials are licensed and made available\r
+#  under the terms and conditions of the BSD License which accompanies this\r
+#  distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php.\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                   = 0x00010005\r
+  BASE_NAME                     = DevShell\r
+  FILE_GUID                     = 42c078ef-14a8-4e30-9329-6f12d796e54a\r
+  MODULE_TYPE                   = UEFI_APPLICATION\r
+  VERSION_STRING                = 1.0\r
+  LIBRARY_CLASS                 = DevShell\r
+  CONSTRUCTOR                   = __ctor_DevShell\r
+  DESTRUCTOR                    = __dtor_DevShell\r
+\r
+#\r
+#  VALID_ARCHITECTURES          = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+  UefiShell/daShell.c\r
+\r
+[Packages]\r
+  StdLib/StdLib.dec\r
+  StdLibPrivateInternalFiles/DoNotUse.dec\r
+  MdePkg/MdePkg.dec\r
+  ShellPkg/ShellPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  MemoryAllocationLib\r
+  UefiBootServicesTableLib\r
+  LibC\r
+  LibString\r
+  LibStdLib\r
+  LibWchar\r
+  LibUefi\r
+  DevUtility\r
+\r
+################################################################\r
+#\r
+# The Build Options, below, are only used when building the C library.\r
+# DO NOT use them when building your application!\r
+# Nasty things could happen if you do.\r
+#\r
+# /Oi is required for Microsoft VC++ to allow "intrinsic" functions to be\r
+# defined in this library.\r
+#\r
+#[BuildOptions]\r
+#  MSFT:*_*_*_CC_FLAGS     = /Oi-\r
diff --git a/StdLib/LibC/Uefi/Devices/daUtility.inf b/StdLib/LibC/Uefi/Devices/daUtility.inf
new file mode 100644 (file)
index 0000000..53daad2
--- /dev/null
@@ -0,0 +1,56 @@
+## @file\r
+#  Standard C library: Console Device Abstraction.\r
+#\r
+#  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+#  This program and the accompanying materials are licensed and made available\r
+#  under the terms and conditions of the BSD License which accompanies this\r
+#  distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php.\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                   = 0x00010005\r
+  BASE_NAME                     = DevUtility\r
+  FILE_GUID                     = 42c078ef-14a8-4e30-9329-6f12d796e54a\r
+  MODULE_TYPE                   = UEFI_APPLICATION\r
+  VERSION_STRING                = 1.0\r
+  LIBRARY_CLASS                 = DevUtility\r
+\r
+#\r
+#  VALID_ARCHITECTURES          = IA32 X64 IPF\r
+#\r
+\r
+[Sources]\r
+  Utility/DevGenisis.c\r
+  Utility/DevSearch.c\r
+  Utility/Path.c\r
+\r
+[Packages]\r
+  StdLib/StdLib.dec\r
+  StdLibPrivateInternalFiles/DoNotUse.dec\r
+  MdePkg/MdePkg.dec\r
+  ShellPkg/ShellPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  BaseMemoryLib\r
+  MemoryAllocationLib\r
+  LibC\r
+  LibWchar\r
+  LibUefi\r
+\r
+################################################################\r
+#\r
+# The Build Options, below, are only used when building the C library.\r
+# DO NOT use them when building your application!\r
+# Nasty things could happen if you do.\r
+#\r
+# /Oi- is required for Microsoft VC++ to allow "intrinsic" functions to be\r
+# defined in this library.\r
+#\r
+#[BuildOptions]\r
+#  MSFT:*_*_*_CC_FLAGS     = /Oi-\r
index 624d45878e166e78aa218cf545c01f244125b18b..b3ca5b89b4993ad958e525f76b37da1099d13b45 100644 (file)
@@ -13,6 +13,7 @@
 **/\r
 #include  <Uefi.h>\r
 #include  <Library/UefiLib.h>\r
+#include  <Library/UefiBootServicesTableLib.h>\r
 #include  <Library/BaseLib.h>\r
 #include  <Library/MemoryAllocationLib.h>\r
 #include  <Library/ShellLib.h>\r
 #include  <sys/ansi.h>\r
 #include  <errno.h>\r
 #include  <stdarg.h>\r
+#include  <stdlib.h>\r
 #include  <string.h>\r
 #include  <wchar.h>\r
+#include  <sys/poll.h>\r
 #include  <sys/fcntl.h>\r
 #include  <sys/stat.h>\r
 #include  <sys/syslimits.h>\r
-#include  "SysEfi.h"\r
+#include  <Efi/SysEfi.h>\r
+#include  <kfile.h>\r
+#include  <Device/Device.h>\r
 #include  <MainData.h>\r
 #include  <extern.h>      // Library/include/extern.h: Private to implementation\r
-#include  <Efi/Console.h>\r
-\r
-/* Macros only used in this file. */\r
-// Parameters for the ValidateFD function.\r
-#define VALID_OPEN         1\r
-#define VALID_CLOSED       0\r
-#define VALID_DONT_CARE   -1\r
-\r
+#include  <sys/EfiSysCall.h>\r
 \r
 /* EFI versions of BSD system calls used in stdio */\r
 \r
-/* Normalize path so that forward slashes are replaced with backslashes.\r
-    Backslashes are required for UEFI.\r
-*/\r
-static void\r
-NormalizePath( const CHAR16 *path)\r
-{\r
-  CHAR16  *temp;\r
-\r
-  for( temp = (CHAR16 *)path; *temp; ++temp) {\r
-    if(*temp == L'/') {\r
-      *temp = L'\\';\r
-    }\r
-  }\r
-}\r
-\r
 /*  Validate that fd refers to a valid file descriptor.\r
     IsOpen is interpreted as follows:\r
       - Positive  fd must be OPEN\r
@@ -66,15 +49,18 @@ NormalizePath( const CHAR16 *path)
     @retval TRUE  fd is VALID\r
     @retval FALSE fd is INVALID\r
 */\r
-static BOOLEAN\r
+BOOLEAN\r
 ValidateFD( int fd, int IsOpen)\r
 {\r
+  struct __filedes    *filp;\r
   BOOLEAN   retval = FALSE;\r
 \r
   if((fd >= 0) && (fd < OPEN_MAX)) {\r
+    filp = &gMD->fdarray[fd];\r
     retval = TRUE;\r
     if(IsOpen >= 0) {\r
-      retval = (BOOLEAN)(gMD->fdarray[fd].State != 0);   // TRUE if OPEN\r
+      retval = (BOOLEAN)((filp->f_iflags != 0)  &&    // TRUE if OPEN\r
+                         FILE_IS_USABLE(filp));         // and Usable (not Larval or Closing)\r
       if(IsOpen == VALID_CLOSED) {\r
         retval = (BOOLEAN)!retval;                      // We want TRUE if CLOSED\r
       }\r
@@ -91,7 +77,7 @@ ValidateFD( int fd, int IsOpen)
   @return   Returns -1 if there are no free FDs.  Otherwise returns the\r
             found fd.\r
 */\r
-static int\r
+int\r
 FindFreeFD( int MinFd )\r
 {\r
   struct __filedes    *Mfd;\r
@@ -102,8 +88,8 @@ FindFreeFD( int MinFd )
 \r
   // Get an available fd\r
   for(i=MinFd; i < OPEN_MAX; ++i) {\r
-    if(Mfd[i].State == 0) {\r
-      Mfd[i].State = S_ISYSTEM; // Temporarily mark this fd as reserved\r
+    if(Mfd[i].f_iflags == 0) {\r
+      Mfd[i].f_iflags = FIF_LARVAL; // Temporarily mark this fd as reserved\r
       fd = i;\r
       break;\r
     }\r
@@ -111,6 +97,22 @@ FindFreeFD( int MinFd )
   return fd;\r
 }\r
 \r
+/* Mark that an open file is to be deleted when closed. */\r
+int\r
+DeleteOnClose(int fd)\r
+{\r
+  int   retval = 0;\r
+\r
+  if(ValidateFD( fd, VALID_OPEN)) {\r
+    gMD->fdarray[fd].f_iflags |= FIF_DELCLOSE;\r
+  }\r
+  else {\r
+    errno = EBADF;\r
+    retval = -1;\r
+  }\r
+  return retval;\r
+}\r
+\r
 /** The isatty() function tests whether fildes, an open file descriptor,\r
     is associated with a terminal device.\r
 \r
@@ -119,15 +121,14 @@ FindFreeFD( int MinFd )
                   EBADF if fildes is not a valid open FD.\r
 **/\r
 int\r
-isatty  (int fildes)\r
+isatty  (int fd)\r
 {\r
   int   retval = 0;\r
-  EFI_FILE_HANDLE   FileHandle;\r
+  struct __filedes *Fp;\r
 \r
-  if(ValidateFD( fildes, VALID_OPEN)) {\r
-    FileHandle = gMD->fdarray[fildes].FileHandle;\r
-    retval =  (FileHandle >= &gMD->StdIo[0].Abstraction) &&\r
-              (FileHandle <= &gMD->StdIo[2].Abstraction);\r
+  if(ValidateFD( fd, VALID_OPEN)) {\r
+    Fp = &gMD->fdarray[fd];\r
+    retval =  Fp->f_iflags & _S_ITTY;\r
   }\r
   else {\r
     errno = EBADF;\r
@@ -138,16 +139,19 @@ isatty  (int fildes)
 static BOOLEAN\r
 IsDupFd( int fd)\r
 {\r
-  EFI_FILE_HANDLE       FileHandle;\r
+  void * DevData;\r
+  const struct fileops   *FileOps;\r
   int                   i;\r
   BOOLEAN               Ret = FALSE;\r
 \r
   if(ValidateFD( fd, VALID_OPEN )) {\r
-    FileHandle = gMD->fdarray[fd].FileHandle;\r
+    FileOps = gMD->fdarray[fd].f_ops;\r
+    DevData = gMD->fdarray[fd].devdata;\r
     for(i=0; i < OPEN_MAX; ++i) {\r
       if(i == fd)   continue;\r
-      if(gMD->fdarray[i].State != 0) {   // TRUE if fd is OPEN\r
-        if(gMD->fdarray[i].FileHandle == FileHandle) {\r
+      if(ValidateFD( i, VALID_OPEN )) {   // TRUE if fd is valid and OPEN\r
+        if((gMD->fdarray[i].f_ops == FileOps)\r
+          &&(gMD->fdarray[i].devdata == DevData )) {\r
           Ret = TRUE;\r
           break;\r
         }\r
@@ -160,36 +164,37 @@ IsDupFd( int fd)
 static int\r
 _closeX  (int fd, int NewState)\r
 {\r
-  struct __filedes     *Mfd;\r
-  RETURN_STATUS         Status;\r
+  struct __filedes     *Fp;\r
   int                   retval = 0;\r
 \r
-  Status = EFIerrno = RETURN_SUCCESS;  // In case of error before the EFI call.\r
-\r
   // Verify my pointers and get my FD.\r
   if(ValidateFD( fd, VALID_OPEN )) {\r
-    Mfd = &gMD->fdarray[fd];\r
-    // Check if there are duplicates using this FileHandle\r
+    Fp = &gMD->fdarray[fd];\r
+    // Check if there are other users of this FileHandle\r
+    if(Fp->RefCount == 1) { // There should be no other users\r
     if(! IsDupFd(fd)) {\r
       // Only do the close if no one else is using the FileHandle\r
-      if(isatty(fd)) {\r
-        Status = Mfd->FileHandle->Close( Mfd->FileHandle);\r
+        if(Fp->f_iflags & FIF_DELCLOSE) {\r
+          /* Handle files marked "Delete on Close". */\r
+          if(Fp->f_ops->fo_delete != NULL) {\r
+            retval = Fp->f_ops->fo_delete(Fp);\r
+          }\r
       }\r
       else {\r
-        Status = ShellCloseFile( (SHELL_FILE_HANDLE *)&Mfd->FileHandle);\r
+          retval = Fp->f_ops->fo_close( Fp);\r
       }\r
     }\r
-    Mfd->State = NewState;   // Close this FD or reserve it\r
-    if(Status != RETURN_SUCCESS) {\r
-      errno = EFI2errno(Status);\r
-      EFIerrno = Status;\r
-      retval = -1;\r
+      Fp->f_iflags = NewState;    // Close this FD or reserve it\r
+      Fp->RefCount = 0;           // No one using this FD\r
+    }\r
+    else {\r
+      --Fp->RefCount;   /* One less user of this FD */\r
     }\r
   }\r
   else {\r
     // Bad FD\r
-    errno = EBADF;\r
     retval = -1;\r
+    errno = EBADF;\r
   }\r
   return retval;\r
 }\r
@@ -210,41 +215,28 @@ close  (int fd)
   return _closeX(fd, 0);\r
 }\r
 \r
-/* Wide character version of unlink */\r
+/**\r
+**/\r
 int\r
-Uunlink (const wchar_t *Path)\r
+unlink (const char *path)\r
 {\r
-  EFI_FILE_HANDLE       FileHandle;\r
-  RETURN_STATUS         Status;\r
+  struct __filedes     *Fp;\r
+  int                   fd;\r
+  int                   retval = -1;\r
 \r
   EFIerrno = RETURN_SUCCESS;\r
 \r
-  NormalizePath( Path);\r
-  // We can only delete open files.\r
-  Status = ShellOpenFileByName( Path, (SHELL_FILE_HANDLE *)&FileHandle, 3, 0);\r
-  if(Status != RETURN_SUCCESS) {\r
-    errno = EFI2errno(Status);\r
-    EFIerrno = Status;\r
-    return -1;\r
+  fd = open(path, O_WRONLY, 0);\r
+  if(fd >= 0) {\r
+    Fp = &gMD->fdarray[fd];\r
+\r
+    if(Fp->f_ops->fo_delete != NULL) {\r
+      retval = Fp->f_ops->fo_delete(Fp);\r
   }\r
-  Status = ShellDeleteFile( (SHELL_FILE_HANDLE *)&FileHandle);\r
-  if(Status != RETURN_SUCCESS) {\r
-    errno = EFI2errno(Status);\r
-    EFIerrno = Status;\r
-    return -1;\r
+    Fp->f_iflags = 0;    // Close this FD\r
+    Fp->RefCount = 0;    // No one using this FD\r
   }\r
-  return 0;\r
-}\r
-\r
-/**\r
-**/\r
-int\r
-unlink (const char *path)\r
-{\r
-  // Convert path from MBCS to WCS\r
-  (void)AsciiStrToUnicodeStr( path, gMD->UString);\r
-\r
-  return Uunlink(gMD->UString);\r
+  return retval;\r
 }\r
 \r
 /** The fcntl() function shall perform the operations described below on open\r
@@ -366,23 +358,23 @@ fcntl     (int fildes, int cmd, ...)
         break;\r
       //case F_SETFL:\r
       case F_SETFD:\r
-        retval = MyFd->State;\r
-        break;\r
-      case F_SETOWN:\r
-        retval = MyFd->SocProc;\r
-        MyFd->SocProc = va_arg(p3, int);\r
+        retval = MyFd->f_iflags;\r
         break;\r
+      //case F_SETOWN:\r
+      //  retval = MyFd->SocProc;\r
+      //  MyFd->SocProc = va_arg(p3, int);\r
+      //  break;\r
       case F_GETFD:\r
         //retval = MyFd->Oflags;\r
-        retval = MyFd->State;\r
+        retval = MyFd->f_iflags;\r
         break;\r
       case F_GETFL:\r
-        //retval = MyFd->State;\r
+        //retval = MyFd->f_iflags;\r
         retval = MyFd->Oflags;\r
         break;\r
-      case F_GETOWN:\r
-        retval = MyFd->SocProc;\r
-        break;\r
+      //case F_GETOWN:\r
+      //  retval = MyFd->SocProc;\r
+      //  break;\r
       default:\r
         errno  = EINVAL;\r
         break;\r
@@ -441,9 +433,10 @@ dup2    (int fildes, int fildes2)
     retval = fildes2;\r
     if( fildes != fildes2) {\r
       if(ValidateFD( fildes2, VALID_DONT_CARE)) {\r
-        gMD->fdarray[fildes2].State = S_ISYSTEM;  // Mark the file closed, but reserved\r
+        gMD->fdarray[fildes2].f_iflags = FIF_LARVAL;  // Mark the file closed, but reserved\r
         (void)memcpy(&gMD->fdarray[fildes2],      // Duplicate fildes into fildes2\r
                      &gMD->fdarray[fildes], sizeof(struct __filedes));\r
+        gMD->fdarray[fildes2].MyFD = (UINT16)fildes2;\r
       }\r
       else {\r
         errno = EBADF;\r
@@ -486,53 +479,21 @@ dup2    (int fildes, int fildes2)
               indicate the error.\r
 **/\r
 __off_t\r
-lseek (int fildes, __off_t offset, int how)\r
+lseek (int fd, __off_t offset, int how)\r
 {\r
   __off_t             CurPos = -1;\r
-  RETURN_STATUS       Status = RETURN_SUCCESS;\r
-  EFI_FILE_HANDLE     FileHandle;\r
+//  RETURN_STATUS       Status = RETURN_SUCCESS;\r
+  struct __filedes   *filp;\r
 \r
   EFIerrno = RETURN_SUCCESS;    // In case of error without an EFI call\r
 \r
   if( how == SEEK_SET || how == SEEK_CUR  || how == SEEK_END) {\r
-    if(ValidateFD( fildes, VALID_OPEN)) {\r
+    if(ValidateFD( fd, VALID_OPEN)) {\r
+      filp = &gMD->fdarray[fd];\r
       // Both of our parameters have been verified as valid\r
-      FileHandle = gMD->fdarray[fildes].FileHandle;\r
-      CurPos = 0;\r
-      if(isatty(fildes)) {\r
-        Status = FileHandle->SetPosition( FileHandle, offset);\r
-        CurPos = offset;\r
-      }\r
-      else {\r
-        if(how != SEEK_SET) {\r
-          // We are doing a relative seek\r
-          if(how == SEEK_END) {\r
-            // seeking relative to EOF, so position there first.\r
-            Status = ShellSetFilePosition( (SHELL_FILE_HANDLE)FileHandle, 0xFFFFFFFFFFFFFFFFULL);\r
-          }\r
-          if(Status == RETURN_SUCCESS) {\r
-            // Now, determine our current position.\r
-            Status = ShellGetFilePosition( (SHELL_FILE_HANDLE)FileHandle, (UINT64 *)&CurPos);\r
-          }\r
-        }\r
-        if(Status == RETURN_SUCCESS) {\r
-          /* CurPos now indicates the point we are seeking from, so seek... */\r
-          Status = ShellSetFilePosition( (SHELL_FILE_HANDLE)FileHandle, (UINT64)(CurPos + offset));\r
-          if(Status == RETURN_SUCCESS) {\r
-            // Now, determine our final position.\r
-            Status = ShellGetFilePosition( (SHELL_FILE_HANDLE)FileHandle, (UINT64 *)&CurPos);\r
-          }\r
-        }\r
-        if(Status != RETURN_SUCCESS) {\r
-          EFIerrno = Status;\r
-          CurPos = -1;\r
-          if(Status == EFI_UNSUPPORTED) {\r
-            errno = EISDIR;\r
-          }\r
-          else {\r
-            errno = EFI2errno(Status);\r
-          }\r
-        }\r
+      CurPos = filp->f_ops->fo_lseek( filp, offset, how);\r
+      if(CurPos >= 0) {\r
+        filp->f_offset = CurPos;\r
       }\r
     }\r
     else {\r
@@ -551,37 +512,35 @@ lseek (int fildes, __off_t offset, int how)
     The directory is closed after it is created.\r
 \r
     @retval   0   The directory was created successfully.\r
-    @retval  -1   An error occurred and an error code is stored in errno.\r
+    @retval  -1   An error occurred and error codes are stored in errno and EFIerrno.\r
 **/\r
 int\r
 mkdir (const char *path, __mode_t perms)\r
 {\r
-  EFI_FILE_HANDLE   FileHandle;\r
+  wchar_t            *NewPath;\r
+  DeviceNode         *Node;\r
+  char               *GenI;\r
   RETURN_STATUS     Status;\r
-  EFI_FILE_INFO     *FileInfo;\r
-\r
-  // Convert name from MBCS to WCS\r
-  (void)AsciiStrToUnicodeStr( path, gMD->UString);\r
-  NormalizePath( gMD->UString);\r
+  int                 Instance  = 0;\r
+  int                 retval = 0;\r
 \r
-//Print(L"%a( \"%s\", 0x%8X)\n", __func__, gMD->UString, perms);\r
-  Status = ShellCreateDirectory( gMD->UString, (SHELL_FILE_HANDLE *)&FileHandle);\r
+  Status = ParsePath(path, &NewPath, &Node, &Instance);\r
   if(Status == RETURN_SUCCESS) {\r
-    FileInfo = ShellGetFileInfo( FileHandle);\r
-    if(FileInfo != NULL) {\r
-      FileInfo->Attribute = Omode2EFI(perms);\r
-      Status = ShellSetFileInfo( FileHandle, FileInfo);\r
-      FreePool(FileInfo);\r
-      if(Status == RETURN_SUCCESS) {\r
-        (void)ShellCloseFile((SHELL_FILE_HANDLE *)&FileHandle);\r
-        return 0;\r
+    GenI = Node->InstanceList;\r
+    if(GenI == NULL) {\r
+      errno   = EPERM;\r
+      retval  = -1;\r
       }\r
+    else {\r
+      GenI += (Instance * Node->InstanceSize);\r
+      retval = ((GenericInstance *)GenI)->Abstraction.fo_mkdir( path, perms);\r
+      }\r
+    free(NewPath);\r
     }\r
+  else {\r
+    retval = -1;\r
   }\r
-  errno = EFI2errno(Status);\r
-  EFIerrno = Status;\r
-\r
-  return -1;\r
+  return retval;\r
 }\r
 \r
 /** Open a file.\r
@@ -608,112 +567,215 @@ mkdir (const char *path, __mode_t perms)
     O_EXCL        -- if O_CREAT is also set, open will fail if the file already exists.\r
 **/\r
 int\r
-open   (const char *name, int oflags, int mode)\r
+open   (const char *path, int oflags, int mode)\r
 {\r
-  EFI_FILE_HANDLE       FileHandle;\r
-  struct __filedes     *Mfd;\r
+  wchar_t              *NewPath;\r
+  DeviceNode           *Node;\r
+  char                 *GenI = NULL;\r
+  struct __filedes     *filp;\r
+  int                   Instance  = 0;\r
   RETURN_STATUS         Status;\r
   UINT64                OpenMode;\r
-  UINT64                Attributes;\r
   int                   fd = -1;\r
-  UINT32                NewState;\r
+  int                   doresult;\r
 \r
-  EFIerrno = RETURN_SUCCESS;\r
-  Mfd = gMD->fdarray;\r
-\r
-  // Convert name from MBCS to WCS\r
-  (void)AsciiStrToUnicodeStr( name, gMD->UString);\r
-  NormalizePath( gMD->UString);\r
-\r
-  // Convert oflags to Attributes\r
-  OpenMode = Oflags2EFI(oflags);\r
-  if(OpenMode == 0) {\r
-    errno = EINVAL;\r
-    return -1;\r
+  Status = ParsePath(path, &NewPath, &Node, &Instance);\r
+  if(Status == RETURN_SUCCESS) {\r
+    if((Node != NULL)                       &&\r
+       ((GenI = Node->InstanceList) == NULL)) {\r
+      errno   = EPERM;\r
   }\r
-\r
-  //Attributes = Omode2EFI(mode);\r
-  Attributes = 0;\r
-\r
+    else {\r
   // Could add a test to see if the file name begins with a period.\r
   // If it does, then add the HIDDEN flag to Attributes.\r
 \r
   // Get an available fd\r
-  fd = FindFreeFD( 0 );\r
+      fd = FindFreeFD( VALID_CLOSED );\r
 \r
   if( fd < 0 ) {\r
     // All available FDs are in use\r
     errno = EMFILE;\r
     return -1;\r
   }\r
+      filp = &gMD->fdarray[fd];\r
+      // Save the flags and mode in the File Descriptor\r
+      filp->Oflags = oflags;\r
+      filp->Omode = mode;\r
+\r
+      GenI += (Instance * Node->InstanceSize);\r
+      doresult = Node->OpenFunc(filp, GenI, NewPath, NULL);\r
+      if(doresult < 0) {\r
+        filp->f_iflags = 0;   // Release this FD\r
+        fd = -1;              // Indicate an error\r
+      }\r
+      else {\r
+        // Re-use OpenMode in order to build our final f_iflags value\r
+        OpenMode  = ( mode & S_ACC_READ )  ? S_ACC_READ : 0;\r
+        OpenMode |= ( mode & S_ACC_WRITE ) ? S_ACC_WRITE : 0;\r
 \r
-  Status = ConOpen( NULL, &FileHandle, gMD->UString, OpenMode, Attributes);\r
-  if(Status == RETURN_NO_MAPPING) {\r
-    // Not a console device, how about a regular file device?\r
-\r
-    /* Do we care if the file already exists?\r
-       If O_TRUNC, then delete the file.  It will be created anew subsequently.\r
-       If O_EXCL, then error if the file exists and O_CREAT is set.\r
-\r
-    !!!!!!!!! Change this to use ShellSetFileInfo() to actually truncate the file\r
-    !!!!!!!!! instead of deleting and re-creating it.\r
-    */\r
-    if((oflags & O_TRUNC) || ((oflags & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT))) {\r
-      Status = ShellIsFile( gMD->UString );\r
-      if(Status == RETURN_SUCCESS) {\r
-        // The file exists\r
-        if(oflags & O_TRUNC) {\r
-          // We do a truncate by deleting the existing file and creating a new one.\r
-          if(Uunlink(gMD->UString) != 0) {\r
-            Mfd[fd].State = 0;    // Release our reservation on this FD\r
-            return -1;  // errno and EFIerrno are already set.\r
+        filp->f_iflags |= (UINT32)OpenMode;\r
+        ++filp->RefCount;\r
+        FILE_SET_MATURE(filp);\r
+      }\r
           }\r
+    free(NewPath);\r
         }\r
-        else if(oflags & (O_EXCL | O_CREAT)) {\r
-          errno = EEXIST;\r
-          EFIerrno = Status;\r
-          Mfd[fd].State = 0;    // Release our reservation on this FD\r
+  // return the fd of our now open file\r
+  return fd;\r
+}\r
+\r
+\r
+/**\r
+  Poll a list of file descriptors.\r
+\r
+  The ::poll routine waits for up to timeout milliseconds for an event\r
+  to occur on one or more of the file descriptors listed.  The event\r
+  types of interested are specified for each file descriptor in the events\r
+  field.  The actual event detected is returned in the revents field of\r
+  the array.  The\r
+  <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html">POSIX</a>\r
+  documentation is available online.\r
+\r
+  @param [in] pfd       Address of an array of pollfd structures.\r
+\r
+  @param [in] nfds      Number of elements in the array of pollfd structures.\r
+\r
+  @param [in] timeout   Length of time in milliseconds to wait for the event\r
+\r
+  @returns    The number of file descriptors with detected events.  Zero\r
+              indicates that the call timed out and -1 indicates an error.\r
+\r
+ **/\r
+int\r
+poll (\r
+  struct pollfd * pfd,\r
+  nfds_t nfds,\r
+  int timeout\r
+  )\r
+{\r
+  struct __filedes * pDescriptor;\r
+  struct pollfd * pEnd;\r
+  struct pollfd * pPollFD;\r
+  int SelectedFDs;\r
+  EFI_STATUS Status;\r
+  EFI_EVENT Timer;\r
+  UINT64 TimerTicks;\r
+\r
+  //\r
+  //  Create the timer for the timeout\r
+  //\r
+  Timer = NULL;\r
+  Status = EFI_SUCCESS;\r
+  if ( INFTIM != timeout ) {\r
+    Status = gBS->CreateEvent ( EVT_TIMER,\r
+                                TPL_NOTIFY,\r
+                                NULL,\r
+                                NULL,\r
+                                &Timer );\r
+    if ( !EFI_ERROR ( Status )) {\r
+      //\r
+      //  Start the timeout timer\r
+      //\r
+      TimerTicks = timeout;\r
+      TimerTicks *= 1000 * 10;\r
+      Status = gBS->SetTimer ( Timer,\r
+                               TimerRelative,\r
+                               TimerTicks );\r
+    }\r
+    else {\r
+      SelectedFDs = -1;\r
+      errno = ENOMEM;\r
+    }\r
+  }\r
+  if ( !EFI_ERROR ( Status )) {\r
+    //\r
+    //  Poll until an event is detected or the timer fires\r
+    //\r
+    SelectedFDs = 0;\r
+    errno = 0;\r
+    do {\r
+      //\r
+      //  Poll the list of file descriptors\r
+      //\r
+      pPollFD = pfd;\r
+      pEnd = &pPollFD [ nfds ];\r
+      while ( pEnd > pPollFD ) {\r
+        //\r
+        //  Validate the file descriptor\r
+        //\r
+        if ( !ValidateFD ( pPollFD->fd, VALID_OPEN )) {\r
+          errno = EINVAL;\r
           return -1;\r
         }\r
+\r
+        //\r
+        //  Poll the device or file\r
+        //\r
+        pDescriptor = &gMD->fdarray [ pPollFD->fd ];\r
+        pPollFD->revents = pDescriptor->f_ops->fo_poll ( pDescriptor,\r
+                                                         pPollFD->events );\r
+\r
+        //\r
+        //  Determine if this file descriptor detected an event\r
+        //\r
+        if ( 0 != pPollFD->revents ) {\r
+          //\r
+          //  Select this descriptor\r
+          //\r
+          SelectedFDs += 1;\r
+        }\r
+\r
+        //\r
+        //  Set the next file descriptor\r
+        //\r
+        pPollFD += 1;\r
       }\r
+\r
+      //\r
+      //  Check for timeout\r
+      //\r
+      if ( NULL != Timer ) {\r
+        Status = gBS->CheckEvent ( Timer );\r
+        if ( EFI_SUCCESS == Status ) {\r
+          //\r
+          //  Timeout\r
+          //\r
+          break;\r
+        }\r
+        else if ( EFI_NOT_READY == Status ) {\r
+          Status = EFI_SUCCESS;\r
     }\r
-    // Call the EFI Shell's Open function\r
-    Status = ShellOpenFileByName( gMD->UString, (SHELL_FILE_HANDLE *)&FileHandle, OpenMode, Attributes);\r
-    if(RETURN_ERROR(Status)) {\r
-      Mfd[fd].State = 0;    // Release our reservation on this FD\r
-      // Set errno based upon Status\r
-      errno = EFI2errno(Status);\r
-      EFIerrno = Status;\r
-      return -1;\r
     }\r
-    // Successfully got a regular File\r
-    NewState = S_IFREG;\r
+    } while (( 0 == SelectedFDs )\r
+        && ( EFI_SUCCESS == Status ));\r
+    //\r
+    //  Stop the timer\r
+    //\r
+    if ( NULL != Timer ) {\r
+      gBS->SetTimer ( Timer,\r
+                      TimerCancel,\r
+                      0 );\r
   }\r
-  else if(Status != RETURN_SUCCESS) {\r
-    // Set errno based upon Status\r
-    errno = EFI2errno(Status);\r
-    EFIerrno = Status;\r
-    return -1;\r
   }\r
   else {\r
-    // Succesfully got a Console stream\r
-    NewState = S_IFREG | _S_ITTY | _S_IFCHR;\r
+    SelectedFDs = -1;\r
+    errno = EAGAIN;\r
   }\r
 \r
-  // Update the info in the fd\r
-  Mfd[fd].FileHandle = FileHandle;\r
-  Mfd[fd].Oflags = oflags;\r
-  Mfd[fd].Omode = mode;\r
+  //\r
+  //  Release the timer\r
+  //\r
+  if ( NULL != Timer ) {\r
+    gBS->CloseEvent ( Timer );\r
+  }\r
 \r
-  // Re-use OpenMode in order to build our final State value\r
-  OpenMode  = ( mode & S_ACC_READ )  ? S_ACC_READ : 0;\r
-  OpenMode |= ( mode & S_ACC_WRITE ) ? S_ACC_WRITE : 0;\r
+  //\r
+  //  Return the number of selected file system descriptors\r
+  //\r
+  return SelectedFDs;\r
+}\r
 \r
-  Mfd[fd].State = NewState | (UINT32)OpenMode;\r
 \r
-  // return the fd of our now open file\r
-  return fd;\r
-}\r
 \r
 /** The rename() function changes the name of a file.\r
     The old argument points to the pathname of the file to be renamed. The new\r
@@ -745,168 +807,54 @@ open   (const char *name, int oflags, int mode)
               shall be changed or created.\r
 **/\r
 int\r
-rename    (const char *old, const char *new)\r
-{\r
- // UINT64            InfoSize;\r
- // RETURN_STATUS     Status;\r
- // EFI_FILE_INFO     *NewFileInfo = NULL;\r
- // EFI_FILE_INFO     *OldFileInfo;\r
- // char              *Newfn;\r
- // int                OldFd;\r
-\r
- //// Open old file\r
- // OldFd = open(old, O_RDONLY, 0);\r
- // if(OldFd >= 0) {\r
- //   NewFileInfo = malloc(sizeof(EFI_FILE_INFO) + PATH_MAX);\r
- //   if(NewFileInfo != NULL) {\r
- //     OldFileInfo = ShellGetFileInfo( FileHandle);\r
- //     if(OldFileInfo != NULL) {\r
- //       // Copy the Old file info into our new buffer, and free the old.\r
- //       memcpy(OldFileInfo, NewFileInfo, sizeof(EFI_FILE_INFO));\r
- //       FreePool(OldFileInfo);\r
- //       // Strip off all but the file name portion of new\r
- //       NewFn = strrchr(new, '/');\r
- //       if(NewFn == NULL) {\r
- //         NewFn = strrchr(new '\\');\r
- //         if(NewFn == NULL) {\r
- //           NewFn = new;\r
- //         }\r
- //       }\r
- //       // Convert new name from MBCS to WCS\r
- //       (void)AsciiStrToUnicodeStr( NewFn, gMD->UString);\r
- //       // Copy the new file name into our new file info buffer\r
- //       wcsncpy(NewFileInfo->FileName, gMD->UString, wcslen(gMD->UString)+1);\r
- //       // Apply the new file name\r
- //       Status = ShellSetFileInfo(FileHandle);\r
- //       if(Status == EFI_SUCCESS) {\r
- //         // File has been successfully renamed.  We are DONE!\r
- //         return 0;\r
- //       }\r
- //       errno = EFI2errno( Status );\r
- //       EFIerrno = Status;\r
- //     }\r
- //     else {\r
- //       errno = EIO;\r
- //     }\r
- //   }\r
- //   else {\r
- //     errno = ENOMEM;\r
- //   }\r
- // }\r
-  return -1;\r
-}\r
-\r
-/**\r
-**/\r
-int\r
-rmdir     (const char *path)\r
+EFIAPI\r
+rename(\r
+  const char *from,\r
+  const char *to\r
+  )\r
 {\r
-  EFI_FILE_HANDLE   FileHandle;\r
-  RETURN_STATUS     Status;\r
-  EFI_FILE_INFO     *FileInfo = NULL;\r
-  int               Count = 0;\r
-  BOOLEAN           NoFile = FALSE;\r
-\r
-  errno = 0;    // Make it easier to see if we have an error later\r
-\r
-  // Convert name from MBCS to WCS\r
-  (void)AsciiStrToUnicodeStr( path, gMD->UString);\r
-  NormalizePath( gMD->UString);\r
-\r
-//Print(L"%a( \"%s\")\n", __func__, gMD->UString);\r
-  Status = ShellOpenFileByName( gMD->UString, (SHELL_FILE_HANDLE *)&FileHandle,\r
-                               (EFI_FILE_MODE_READ || EFI_FILE_MODE_WRITE), 0);\r
+  wchar_t            *FromPath;\r
+  DeviceNode         *FromNode;\r
+  char               *GenI;\r
+  int                 Instance    = 0;\r
+  RETURN_STATUS       Status;\r
+  int                 retval      = -1;\r
+\r
+  Status = ParsePath(from, &FromPath, &FromNode, &Instance);\r
   if(Status == RETURN_SUCCESS) {\r
-    FileInfo = ShellGetFileInfo( (SHELL_FILE_HANDLE)FileHandle);\r
-    if(FileInfo != NULL) {\r
-      if((FileInfo->Attribute & EFI_FILE_DIRECTORY) == 0) {\r
-        errno = ENOTDIR;\r
+    GenI = FromNode->InstanceList;\r
+    if(GenI == NULL) {\r
+      errno   = EPERM;\r
+      retval  = -1;\r
       }\r
       else {\r
-        // See if the directory has any entries other than ".." and ".".\r
-        FreePool(FileInfo);  // Free up the buffer from ShellGetFileInfo()\r
-        Status = ShellFindFirstFile( (SHELL_FILE_HANDLE)FileHandle, &FileInfo);\r
-        if(Status == RETURN_SUCCESS) {\r
-          ++Count;\r
-          while(Count < 3) {\r
-            Status = ShellFindNextFile( (SHELL_FILE_HANDLE)FileHandle, FileInfo, &NoFile);\r
-            if(Status == RETURN_SUCCESS) {\r
-              if(NoFile) {\r
-                break;\r
+      GenI += (Instance * FromNode->InstanceSize);\r
+      retval = ((GenericInstance *)GenI)->Abstraction.fo_rename( from, to);\r
               }\r
-              ++Count;\r
-            }\r
-            else {\r
-              Count = 99;\r
+    free(FromPath);\r
             }\r
-          }\r
-          FreePool(FileInfo);   // Free buffer from ShellFindFirstFile()\r
-          if(Count < 3) {\r
-            // Directory is empty\r
-            Status = ShellDeleteFile( (SHELL_FILE_HANDLE *)&FileHandle);\r
-            if(Status == RETURN_SUCCESS) {\r
-              EFIerrno = RETURN_SUCCESS;\r
-              return 0;\r
-              /* ######## SUCCESSFUL RETURN ######## */\r
-            }\r
-          }\r
-          else {\r
-            if(Count == 99) {\r
-              errno = EIO;\r
-            }\r
-            else {\r
-              errno = ENOTEMPTY;\r
-            }\r
-          }\r
-        }\r
-      }\r
-    }\r
-    else {\r
-      errno = EIO;\r
-    }\r
-  }\r
-  EFIerrno = Status;\r
-  if(errno == 0) {\r
-    errno = EFI2errno( Status );\r
-  }\r
-  return -1;\r
+  return retval;\r
 }\r
 \r
-/* Internal File Info. worker function for stat and fstat. */\r
-static\r
-EFI_STATUS\r
-_EFI_FileInfo( EFI_FILE_INFO *FileInfo, struct stat *statbuf)\r
+/**\r
+**/\r
+int\r
+EFIAPI\r
+rmdir(\r
+  const char *path\r
+  )\r
 {\r
-  UINT64            Attributes;\r
-  RETURN_STATUS     Status;\r
-  mode_t            newmode;\r
-\r
-  if(FileInfo != NULL) {\r
-    // Got the info, now populate statbuf with it\r
-    statbuf->st_blksize   = S_BLKSIZE;\r
-    statbuf->st_size      = FileInfo->Size;\r
-    statbuf->st_physsize  = FileInfo->PhysicalSize;\r
-    statbuf->st_birthtime = Efi2Time( &FileInfo->CreateTime);\r
-    statbuf->st_atime     = Efi2Time( &FileInfo->LastAccessTime);\r
-    statbuf->st_mtime     = Efi2Time( &FileInfo->ModificationTime);\r
-    Attributes = FileInfo->Attribute;\r
-    newmode               = (mode_t)(Attributes << S_EFISHIFT) | S_ACC_READ;\r
-    if((Attributes & EFI_FILE_DIRECTORY) == 0) {\r
-      newmode |= _S_IFREG;\r
-      if((Attributes & EFI_FILE_READ_ONLY) == 0) {\r
-        statbuf->st_mode |= S_ACC_WRITE;\r
+  struct __filedes   *filp;\r
+  int                 fd;\r
+  int                 retval = -1;\r
+\r
+  fd = open(path, O_RDWR, 0);\r
+  if(fd >= 0) {\r
+    filp = &gMD->fdarray[fd];\r
+\r
+    retval = filp->f_ops->fo_rmdir(filp);\r
       }\r
-    }\r
-    else {\r
-      newmode |= _S_IFDIR;\r
-    }\r
-    statbuf->st_mode      = newmode;\r
-    Status = RETURN_SUCCESS;\r
-  }\r
-  else {\r
-    Status = RETURN_DEVICE_ERROR;\r
-  }\r
-  return Status;\r
+  return retval;\r
 }\r
 \r
 /** The fstat() function obtains information about an open file associated\r
@@ -935,7 +883,7 @@ _EFI_FileInfo( EFI_FILE_INFO *FileInfo, struct stat *statbuf)
       - st_gid      Set to zero.\r
       - st_nlink    Set to one.\r
 \r
-    @param[in]    fildes    File descriptor as returned from open().\r
+    @param[in]    fd        File descriptor as returned from open().\r
     @param[out]   statbuf   Buffer in which the file status is put.\r
 \r
     @retval    0  Successful Completion.\r
@@ -943,37 +891,19 @@ _EFI_FileInfo( EFI_FILE_INFO *FileInfo, struct stat *statbuf)
                   identify the error.\r
 **/\r
 int\r
-fstat (int fildes, struct stat *statbuf)\r
+fstat (int fd, struct stat *statbuf)\r
 {\r
-  EFI_FILE_HANDLE   FileHandle;\r
-  RETURN_STATUS     Status = RETURN_SUCCESS;\r
-  EFI_FILE_INFO     *FileInfo = NULL;\r
-  UINTN             FinfoSize = sizeof(EFI_FILE_INFO);\r
+  int                 retval = -1;\r
+  struct __filedes   *filp;\r
 \r
-  if(ValidateFD( fildes, VALID_OPEN)) {\r
-    FileHandle = gMD->fdarray[fildes].FileHandle;\r
-    if(isatty(fildes)) {\r
-      FileInfo = AllocateZeroPool(FinfoSize);\r
-      if(FileInfo != NULL) {\r
-        Status = FileHandle->GetInfo( FileHandle, 0, &FinfoSize, FileInfo);\r
+  if(ValidateFD( fd, VALID_OPEN)) {\r
+    filp = &gMD->fdarray[fd];\r
+    retval = filp->f_ops->fo_stat(filp, statbuf, NULL);\r
       }\r
       else {\r
-        Status = RETURN_OUT_OF_RESOURCES;\r
+    errno   =  EBADF;\r
       }\r
-    }\r
-    else {\r
-      FileInfo = ShellGetFileInfo( FileHandle);\r
-    }\r
-    Status = _EFI_FileInfo( FileInfo, statbuf);\r
-  }\r
-  errno     = EFI2errno(Status);\r
-  EFIerrno  = Status;\r
-\r
-  if(FileInfo != NULL) {\r
-    FreePool(FileInfo);     // Release the buffer allocated by the GetInfo function\r
-  }\r
-\r
-  return errno? -1 : 0;\r
+  return retval;\r
 }\r
 \r
 /** Obtains information about the file pointed to by path.\r
@@ -988,26 +918,17 @@ fstat (int fildes, struct stat *statbuf)
 int\r
 stat   (const char *path, void *statbuf)\r
 {\r
-  EFI_FILE_HANDLE   FileHandle;\r
-  RETURN_STATUS     Status;\r
-  EFI_FILE_INFO     *FileInfo;\r
-\r
-  errno = 0;    // Make it easier to see if we have an error later\r
-\r
-  // Convert name from MBCS to WCS\r
-  (void)AsciiStrToUnicodeStr( path, gMD->UString);\r
-  NormalizePath( gMD->UString);\r
-\r
-  Status = ShellOpenFileByName( gMD->UString, (SHELL_FILE_HANDLE *)&FileHandle, EFI_FILE_MODE_READ, 0ULL);\r
-  if(Status == RETURN_SUCCESS) {\r
-    FileInfo = ShellGetFileInfo( FileHandle);\r
-    Status = _EFI_FileInfo( FileInfo, (struct stat *)statbuf);\r
-    (void)ShellCloseFile( (SHELL_FILE_HANDLE *)&FileHandle);\r
+  int                 fd;\r
+  int                 retval  = -1;\r
+  struct __filedes   *filp;\r
+\r
+  fd = open(path, O_RDONLY, 0);\r
+  if(fd >= 0) {\r
+    filp = &gMD->fdarray[fd];\r
+    retval = filp->f_ops->fo_stat( filp, statbuf, NULL);\r
+    close(fd);\r
   }\r
-  errno     = EFI2errno(Status);\r
-  EFIerrno  = Status;\r
-\r
-  return errno? -1 : 0;\r
+  return retval;\r
 }\r
 \r
 /**  Same as stat since EFI doesn't have symbolic links.  **/\r
@@ -1017,6 +938,33 @@ lstat (const char *path, struct stat *statbuf)
   return stat(path, statbuf);\r
 }\r
 \r
+/** Control a device.\r
+**/\r
+int\r
+ioctl(\r
+  int             fd,\r
+  unsigned long   request,\r
+  ...\r
+  )\r
+{\r
+  int                 retval = -1;\r
+  struct __filedes   *filp;\r
+  va_list             argp;\r
+\r
+  va_start(argp, request);\r
+\r
+  if(ValidateFD( fd, VALID_OPEN)) {\r
+    filp = &gMD->fdarray[fd];\r
+    retval = filp->f_ops->fo_ioctl(filp, request, argp);\r
+  }\r
+  else {\r
+    errno   =  EBADF;\r
+  }\r
+  va_end(argp);\r
+\r
+  return retval;\r
+}\r
+\r
 /** Read from a file.\r
 \r
     The read() function shall attempt to read nbyte bytes from the file\r
@@ -1083,59 +1031,22 @@ lstat (const char *path, struct stat *statbuf)
 ssize_t\r
 read   (int fildes, void *buf, size_t nbyte)\r
 {\r
+  struct __filedes *filp;\r
   ssize_t           BufSize;\r
-  EFI_FILE_HANDLE   FileHandle;\r
-  RETURN_STATUS     Status;\r
 \r
   BufSize = (ssize_t)nbyte;\r
   if(ValidateFD( fildes, VALID_OPEN)) {\r
-    FileHandle = gMD->fdarray[fildes].FileHandle;\r
-    if(isatty(fildes)) {\r
-      Status = FileHandle->Read( FileHandle, (UINTN *)&BufSize, buf);\r
-    }\r
-    else {\r
-      Status = ShellReadFile( FileHandle, (UINTN *)&BufSize, buf);\r
-    }\r
-    if(Status != RETURN_SUCCESS) {\r
-      EFIerrno = Status;\r
-      errno = EFI2errno(Status);\r
-      if(Status == RETURN_BUFFER_TOO_SMALL) {\r
-        BufSize = -BufSize;\r
-      }\r
-      else {\r
-      BufSize = -1;\r
-      }\r
-    }\r
+    filp = &gMD->fdarray[fildes];\r
+\r
+    BufSize = filp->f_ops->fo_read(filp, &filp->f_offset, nbyte, buf);\r
   }\r
   else {\r
     errno = EBADF;\r
+    BufSize = -EBADF;\r
   }\r
   return BufSize;\r
 }\r
 \r
-ssize_t\r
-WideTtyCvt( CHAR16 *dest, const char *buf, size_t n)\r
-{\r
-  UINTN   i;\r
-  wint_t  wc;\r
-\r
-  for(i = 0; i < n; ++i) {\r
-    wc = btowc(*buf++);\r
-    if( wc == 0) {\r
-      break;\r
-    };\r
-    if(wc < 0) {\r
-      wc = BLOCKELEMENT_LIGHT_SHADE;\r
-    }\r
-    if(wc == L'\n') {\r
-      *dest++ = L'\r';\r
-    }\r
-    *dest++ = (CHAR16)wc;\r
-  }\r
-  *dest = 0;\r
-  return (ssize_t)i;\r
-}\r
-\r
 /** Write data to a file.\r
 \r
   This function writes the specified number of bytes to the file at the current\r
@@ -1159,40 +1070,62 @@ WideTtyCvt( CHAR16 *dest, const char *buf, size_t n)
   QUESTION:  Should writes to stdout or stderr always succeed?\r
 **/\r
 ssize_t\r
-write  (int fildes, const void *buf, size_t n)\r
+write  (int fd, const void *buf, size_t nbyte)\r
 {\r
+  struct __filedes *filp;\r
   ssize_t           BufSize;\r
-  EFI_FILE_HANDLE   FileHandle;\r
-  RETURN_STATUS     Status = RETURN_SUCCESS;\r
-  ssize_t           UniBufSz;\r
+//  EFI_FILE_HANDLE   FileHandle;\r
+//  RETURN_STATUS     Status = RETURN_SUCCESS;\r
+\r
+  BufSize = (ssize_t)nbyte;\r
 \r
-  BufSize = (ssize_t)n;\r
+  if(ValidateFD( fd, VALID_OPEN)) {\r
+    filp = &gMD->fdarray[fd];\r
 \r
-  if(ValidateFD( fildes, VALID_OPEN)) {\r
-    FileHandle = gMD->fdarray[fildes].FileHandle;\r
-    if(isatty(fildes)) {\r
-      // Convert string from MBCS to WCS and translate \n to \r\n.\r
-      UniBufSz = WideTtyCvt(gMD->UString, (const char *)buf, n);\r
-      if(UniBufSz > 0) {\r
-        BufSize = (ssize_t)(UniBufSz * sizeof(CHAR16));\r
-        Status = FileHandle->Write( FileHandle, (UINTN *)&BufSize, (void *)gMD->UString);\r
-        BufSize = (ssize_t)n;   // Always pretend all was output\r
-      }\r
+    BufSize = filp->f_ops->fo_write(filp, &filp->f_offset, nbyte, buf);\r
     }\r
     else {\r
-      Status = ShellWriteFile( FileHandle, (UINTN *)&BufSize, (void *)buf);\r
-    }\r
-    if(Status != RETURN_SUCCESS) {\r
-      EFIerrno = Status;\r
-      errno = EFI2errno(Status);\r
-      if(Status == EFI_UNSUPPORTED) {\r
-        errno = EISDIR;\r
+    errno = EBADF;\r
+    BufSize = -EBADF;\r
       }\r
-      BufSize = -1;\r
+  return BufSize;\r
+}\r
+\r
+/** Gets the current working directory.\r
+\r
+  The getcwd() function shall place an absolute pathname of the current \r
+  working directory in the array pointed to by buf, and return buf. The \r
+  pathname copied to the array shall contain no components that are \r
+  symbolic links. The size argument is the size in bytes of the character \r
+  array pointed to by the buf argument. \r
+  \r
+  @param[in,out] buf    The buffer to fill.\r
+  @param[in]     size   The number of bytes in buffer.\r
+\r
+  @retval NULL          The function failed.\r
+  @retval NULL          Buf was NULL.\r
+  @retval NULL          Size was 0.\r
+  @return buf           The function completed successfully. See errno for info.\r
+**/\r
+char     \r
+*getcwd (char *buf, size_t size) \r
+{\r
+  CONST CHAR16 *Cwd;\r
+\r
+  if (size == 0 || buf == NULL) {\r
+    errno = EINVAL;\r
+    return NULL;\r
     }\r
+\r
+  Cwd = ShellGetCurrentDir(NULL);\r
+  if (Cwd == NULL) {\r
+    errno = EACCES;\r
+    return NULL;\r
   }\r
-  else {\r
-    errno = EBADF;\r
+  if (size < ((StrLen (Cwd) + 1) * sizeof (CHAR8))) {\r
+    errno = ERANGE;\r
+    return (NULL);\r
   }\r
-  return BufSize;\r
+  \r
+  return (UnicodeStrToAsciiStr(Cwd, buf));\r
 }\r
diff --git a/StdLib/LibC/Uefi/SysEfi.h b/StdLib/LibC/Uefi/SysEfi.h
deleted file mode 100644 (file)
index fa9dc38..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/** @file\r
-  Declarations local to the Uefi SysCalls module of the Standard C Library.\r
-\r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials are licensed and made available under\r
-  the terms and conditions of the BSD License that accompanies this distribution.\r
-  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-#ifndef _SYSEFI_H\r
-#define _SYSEFI_H\r
-#include  <Protocol/SimpleFileSystem.h>\r
-\r
-#define EFI_FILE_MODE_MASK    ( EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE )\r
-#define OMODE_MASK            0xFFFF00UL\r
-#define OMODE_SHIFT           8\r
-\r
-#define S_ACC_READ            ( S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH )\r
-#define S_ACC_WRITE           ( S_IWUSR | S_IWGRP | S_IWOTH )\r
-#define S_ACC_MASK            ( S_IRWXU | S_IRWXG | S_IRWXO )\r
-\r
-UINT64\r
-Oflags2EFI( int oflags);\r
-\r
-UINT64\r
-Omode2EFI( int mode);\r
-\r
-/* Converts the first several EFI status values into the appropriate errno value.\r
-*/\r
-int\r
-EFI2errno( RETURN_STATUS Status);\r
-\r
-#endif  /* _SYSEFI_H */\r
index ca6437abe0f8c08f708ab5796bf0a71aeb8f582b..084d6c4fc3dddc5b0870d29cf02370d0f7242a3e 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 #  Standard C library: UEFI "system calls".\r
 #\r
-#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -28,7 +28,6 @@
 [Sources]\r
   SysCalls.c\r
   Xform.c\r
-  Console.c\r
 \r
 [Packages]\r
   StdLib/StdLib.dec\r
@@ -47,3 +46,4 @@
   LibLocale\r
   LibString\r
   LibTime\r
+  DevUtility\r
index 21eff6fb9d09a6b19954b481e8eb467f6c3f9427..6b15da356318117159993a688c9147898e58164b 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Value transformations between stdio and the UEFI environment.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials are licensed and made available under\r
   the terms and conditions of the BSD License that accompanies this distribution.\r
   The full text of the license may be found at\r
@@ -18,7 +18,7 @@
 \r
 #include  <errno.h>\r
 #include  <fcntl.h>\r
-#include  "SysEfi.h"\r
+#include  <Efi/SysEfi.h>\r
 \r
 /** Translate the Open flags into a Uefi Open Modes value.\r
 \r
@@ -44,6 +44,10 @@ Oflags2EFI( int oflags )
 \r
   // Build the Open Modes\r
   flags = (UINT64)((oflags & O_ACCMODE) + 1);   // Handle the Read/Write flags\r
+  if(flags & EFI_FILE_MODE_WRITE) {  // Asking for write only?\r
+    // EFI says the only two RW modes are read-only and read+write.\r
+    flags = EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE;\r
+  }\r
   if(oflags & (O_CREAT | O_TRUNC)) {            // Now add the Create flag.\r
     // Also added if O_TRUNC set since we will need to create a new file.\r
     // We just set the flags here since the only valid EFI mode with create\r
index ab139405fcaf730a3150371ea7ff370b2a0e892b..534d3e3b08cea02becbd2c6cee62e26374081aee 100644 (file)
@@ -5,19 +5,17 @@
     two wide characters the same way as two integers of the underlying integer\r
     type designated by wchar_t.\r
 \r
-    Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials are licensed and made available under\r
     the terms and conditions of the BSD License that accompanies this distribution.\r
     The full text of the license may be found at\r
-    http://opensource.org/licenses/bsd-license.php.\r
+    http://opensource.org/licenses/bsd-license.\r
 \r
     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 **/\r
 #include  <Uefi.h>\r
-#include  <Library/BaseLib.h>\r
-#include  <Library/BaseMemoryLib.h>\r
-#include  <Library/MemoryAllocationLib.h>\r
+#include  <Library/DebugLib.h>\r
 \r
 #include  <LibConfig.h>\r
 \r
@@ -36,11 +34,17 @@ __wchar_construct(
   IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
+  EFI_STATUS  Status;\r
+\r
   if( __wchar_bitmap == NULL) {\r
     __wchar_bitmap_size = (WCHAR_MAX + 8) / 8U;\r
-    __wchar_bitmap = AllocatePool(__wchar_bitmap_size);\r
-    if( __wchar_bitmap == NULL) {\r
-      EFIerrno = RETURN_OUT_OF_RESOURCES;\r
+\r
+    Status  = SystemTable->BootServices->AllocatePool(\r
+                EfiBootServicesData, __wchar_bitmap_size, (VOID **)&__wchar_bitmap);\r
+    ASSERT(__wchar_bitmap != NULL);\r
+    if (EFI_ERROR (Status)) {\r
+      __wchar_bitmap = NULL;\r
+      EFIerrno = Status;\r
       errno = ENOMEM;\r
       return EFIerrno;\r
     }\r
@@ -56,9 +60,12 @@ __wchar_deconstruct(
   IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
+  EFI_STATUS    Status  = RETURN_SUCCESS;\r
+\r
   if( __wchar_bitmap != NULL) {\r
-    FreePool( __wchar_bitmap);\r
+    Status = SystemTable->BootServices->FreePool( __wchar_bitmap);\r
+    ASSERT_EFI_ERROR (Status);\r
     __wchar_bitmap = NULL;\r
   }\r
-  return RETURN_SUCCESS;\r
+  return Status;\r
 }\r
index c345dfe8380e244be9dc81292ee4f3c159773647..12556bd7572bb00b7c0285f5254270497b170ac9 100644 (file)
@@ -5,7 +5,7 @@
   two wide characters the same way as two integers of the underlying integer\r
   type designated by wchar_t.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials are licensed and made available under\r
   the terms and conditions of the BSD License that accompanies this distribution.\r
   The full text of the license may be found at\r
@@ -86,12 +86,14 @@ size_t wcscspn(const wchar_t *s1, const wchar_t *s2)
   const wchar_t *str;\r
   UINT8 bit;\r
   int index;\r
+  size_t s1len;\r
 \r
   if(*s1 == 0)   return 0;\r
+  s1len = wcslen(s1);\r
 \r
   BuildBitmap( __wchar_bitmap, s2, __wchar_bitmap_size);\r
 \r
-  for(str = s1; ; str++) {\r
+  for(str = s1; str < &s1[s1len] ; str++) {\r
     index = WHICH8(*str);\r
     bit = WHICH_BIT(*str);\r
     if ((__wchar_bitmap[index] & bit) != 0)\r
index 427d615742b30e5ccf44cd89612c8c8ad6e0e98b..5a88233600080771aa09a8dea6199aca4c15b3b4 100644 (file)
@@ -52,7 +52,7 @@
 # DO NOT use them when building your application!\r
 # Nasty things could happen if you do.\r
 #\r
-# /Oi is required for Microsoft VC++ to allow "intrinsic" functions to be\r
+# /Oi- is required for Microsoft VC++ to allow "intrinsic" functions to be\r
 # defined in this library.\r
 #\r
 [BuildOptions]\r
index 3024b02a2042d0e9b8c08d4f11bb9cb996ad6104..3f71d41e30c8af5a9facfbb2ca1a405a0bb4867e 100644 (file)
   LibSignal|StdLib/LibC/Signal/Signal.inf\r
   LibNetUtil|StdLib/LibC/NetUtil/NetUtil.inf\r
 \r
+  # Libraries for device abstractions within the Standard C Library\r
+  # Applications should not directly access any functions defined in these libraries.\r
+  DevUtility|StdLib/LibC/Uefi/Devices/daUtility.inf\r
+  DevConsole|StdLib/LibC/Uefi/Devices/daConsole.inf\r
+  DevShell|StdLib/LibC/Uefi/Devices/daShell.inf\r
+\r
 [LibraryClasses.IA32]\r
   TimerLib|PerformancePkg/Library/DxeTscTimerLib/DxeTscTimerLib.inf\r
   ## Comment out the above line and un-comment the line below for running under Nt32 emulation.\r
   StdLib/LibC/Signal/Signal.inf\r
   StdLib/LibC/NetUtil/NetUtil.inf\r
 \r
+# Device Abstractions within the Standard C Library\r
+# Applications should not directly access any functions defined in these libraries.\r
+  StdLib/LibC/Uefi/Devices/daUtility.inf\r
+  StdLib/LibC/Uefi/Devices/daConsole.inf\r
+  StdLib/LibC/Uefi/Devices/daShell.inf\r
 \r
 ################################################################\r
 #\r