diff options
Diffstat (limited to 'StdLib')
40 files changed, 1019 insertions, 423 deletions
diff --git a/StdLib/Include/ctype.h b/StdLib/Include/ctype.h index fb0e2fd7d3..d35367f520 100644 --- a/StdLib/Include/ctype.h +++ b/StdLib/Include/ctype.h @@ -171,6 +171,20 @@ int isxdigit(int c); **/
int isascii(int c);
+/** Test whether a character is one of the characters used as a separator
+ between directory elements in a path.
+
+ Characters are '/', '\\'
+
+ This non-standard function is unique to this implementation.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int isDirSep(int c);
+
/** The tolower function converts an uppercase letter to a corresponding
lowercase letter.
@@ -218,6 +232,7 @@ __END_DECLS #define isspace(c) (__isCClass( (int)c, (_CW)))
#define isupper(c) (__isCClass( (int)c, (_CU)))
#define isxdigit(c) (__isCClass( (int)c, (_CD | _CX)))
+ #define isDirSep(c) (__isCClass( (int)c, (_C0)))
#define tolower(c) (__toLower((int)c))
#define toupper(c) (__toUpper((int)c))
#endif /* NO_CTYPE_MACROS */
diff --git a/StdLib/Include/sys/EfiSysCall.h b/StdLib/Include/sys/EfiSysCall.h index 1d01328609..cbaf1d1397 100644 --- a/StdLib/Include/sys/EfiSysCall.h +++ b/StdLib/Include/sys/EfiSysCall.h @@ -6,10 +6,6 @@ STDIN_FILENO 0 standard input file descriptor
STDOUT_FILENO 1 standard output file descriptor
STDERR_FILENO 2 standard error file descriptor
- F_OK 0 test for existence of file
- X_OK 0x01 test for execute or search permission
- W_OK 0x02 test for write permission
- R_OK 0x04 test for read permission
SEEK_SET 0 set file offset to offset
SEEK_CUR 1 set file offset to current plus offset
SEEK_END 2 set file offset to EOF plus offset
@@ -55,10 +51,6 @@ int DeleteOnClose (int fd); Mark an open file to be deleted when closed.
int FindFreeFD (int MinFd);
BOOLEAN ValidateFD (int fd, int IsOpen);
-
- ############### Functions added for compatibility.
- char *getcwd (char *, size_t);
- int chdir (const char *);
@endverbatim
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
@@ -82,12 +74,6 @@ struct stat; /* Structure declared in <sys/stat.h> */ #define STDOUT_FILENO 1 /**< standard output file descriptor */
#define STDERR_FILENO 2 /**< standard error file descriptor */
-/* access function */
-#define F_OK 0 /**< test for existence of file */
-#define X_OK 0x01 /**< test for execute or search permission */
-#define W_OK 0x02 /**< test for write permission */
-#define R_OK 0x04 /**< test for read permission */
-
/* whence values for lseek(2)
Always ensure that these are consistent with <stdio.h> and <unistd.h>!
*/
@@ -238,115 +224,100 @@ __BEGIN_DECLS - stdout: Standard Output (from the System Table)
- stderr: Standard Error Output (from the System Table)
- @param[in] name
- @param[in] oflags
- @param[in] mode
+ @param[in] name Name of file to open.
+ @param[in] oflags Flags as defined in fcntl.h.
+ @param[in] mode Access mode to use if creating the file.
- @return
+ @return Returns -1 on failure, otherwise the file descriptor for the open file.
**/
int open (const char *name, int oflags, int mode);
- /**
- @param[in]
+ /** Create a new file or rewrite an existing one.
+
+ The creat() function behaves as if it is implemented as follows:
- @return
+ int creat(const char *path, mode_t mode)
+ {
+ return open(path, O_WRONLY|O_CREAT|O_TRUNC, mode);
+ }
+
+ @param[in] Path The name of the file to create.
+ @param[in] Mode Access mode (permissions) for the new file.
+
+ @return Returns -1 on failure, otherwise the file descriptor for the open file.
**/
- int creat (const char *, mode_t);
+ int creat (const char *Path, mode_t Mode);
+
+ /** File control
- /**
- @param[in]
+ This function performs the operations described below and defined in <fcntl.h>.
- @return
+ - F_DUPFD: Return the lowest numbered file descriptor available that is >= the third argument.
+ The new file descriptor refers to the same open file as Fd.
+
+ - F_SETFD: Set the file descriptor flags to the value specified by the third argument.
+ - F_GETFD: Get the file descriptor flags associated with Fd.
+ - F_SETFL: Set the file status flags based upon the value of the third argument.
+ - F_GETFL: Get the file status flags and access modes for file Fd.
+
+ @param[in] Fd File descriptor associated with the file to be controlled.
+ @param[in] Cmd Command to execute.
+ @param[in] ... Additional arguments, as needed by Cmd.
+
+ @return A -1 is returned to indicate failure, otherwise the value
+ returned is positive and depends upon Cmd as follows:
+ - F_DUPFD: A new file descriptor.
+ - F_SETFD: files previous file descriptor flags.
+ - F_GETFD: The files file descriptor flags.
+ - F_SETFL: The old status flags and access mode of the file.
+ - F_GETFL: The status flags and access mode of the file.
**/
- int fcntl (int, int, ...);
+ int fcntl (int Fd, int Cmd, ...);
#endif // __FCNTL_SYSCALLS_DECLARED
/* These system calls are also declared in stat.h */
#ifndef __STAT_SYSCALLS_DECLARED
#define __STAT_SYSCALLS_DECLARED
- /**
- @param[in]
-
- @return
- **/
int mkdir (const char *, mode_t);
-
- /**
- @param[in]
-
- @return
- **/
int fstat (int, struct stat *);
-
- /**
- @param[in]
-
- @return
- **/
int lstat (const char *, struct stat *);
-
- /**
- @param[in]
-
- @return
- **/
int stat (const char *, struct stat *);
-
- /**
- @param[in]
-
- @return
- **/
int chmod (const char *, mode_t);
+ mode_t umask (mode_t cmask);
+
#endif // __STAT_SYSCALLS_DECLARED
// These are also declared in sys/types.h
#ifndef __OFF_T_SYSCALLS_DECLARED
#define __OFF_T_SYSCALLS_DECLARED
-
- /**
- @param[in]
-
- @return
- **/
off_t lseek (int, off_t, int);
-
- /**
- @param[in]
-
- @return
- **/
int truncate (const char *, off_t);
-
- /**
- @param[in]
-
- @return
- **/
int ftruncate (int, off_t); // IEEE Std 1003.1b-93
#endif /* __OFF_T_SYSCALLS_DECLARED */
/* EFI-specific Functions. */
- /**
- @param[in]
+ /** Mark an open file to be deleted when it is closed.
+
+ @param[in] fd File descriptor for the open file.
- @return
+ @retval 0 The flag was set successfully.
+ @retval -1 An invalid fd was specified.
**/
- int DeleteOnClose(int fd); /* Mark an open file to be deleted when closed. */
+ int DeleteOnClose(int fd);
-/* Find and reserve a free File Descriptor.
+ /** Find and reserve a free File Descriptor.
Returns the first free File Descriptor greater than or equal to the,
already validated, fd specified by Minfd.
@return Returns -1 if there are no free FDs. Otherwise returns the
found fd.
-*/
+ */
int FindFreeFD (int MinFd);
-/* Validate that fd refers to a valid file descriptor.
+ /** Validate that fd refers to a valid file descriptor.
IsOpen is interpreted as follows:
- Positive fd must be OPEN
- Zero fd must be CLOSED
@@ -354,26 +325,11 @@ __BEGIN_DECLS @retval TRUE fd is VALID
@retval FALSE fd is INVALID
-*/
+ */
BOOLEAN ValidateFD (int fd, int IsOpen);
- /**
- @param[in]
-
- @return
- **/
- char *getcwd (char *, size_t);
-
- /**
- @param[in]
-
- @return
- **/
- int chdir (const char *);
-
/* These system calls don't YET have EFI implementations. */
- int access (const char *path, int amode);
int reboot (int, char *);
__END_DECLS
diff --git a/StdLib/Include/sys/_ctype.h b/StdLib/Include/sys/_ctype.h index 6c2b327411..cb06ec09dd 100644 --- a/StdLib/Include/sys/_ctype.h +++ b/StdLib/Include/sys/_ctype.h @@ -26,8 +26,8 @@ extern int __isCClass( int _c, unsigned int mask); ///< Internal character c __END_DECLS
-/** Character Class bit masks.
-@{
+/** @{
+Character Class bit masks.
**/
#define _CC 0x0001U ///< Control Characters
#define _CW 0x0002U ///< White Space
@@ -36,7 +36,7 @@ __END_DECLS #define _CU 0x0010U ///< Uppercase Letter [A-Z]
#define _CL 0x0020U ///< Lowercase Letter [a-z]
#define _CX 0x0040U ///< Hexadecimal Digits [A-Fa-f]
-#define _C0 0x0080U
+#define _C0 0x0080U ///< Path Separator Characters, '/' and '\\'
#define _CS 0x0100U ///< Space Characters, ' ' in C locale
#define _CG 0x0200U ///< Graphic Characters
#define _CB 0x0400U ///< Blank Characters, ' ' and '\t' in C locale
diff --git a/StdLib/Include/sys/fcntl.h b/StdLib/Include/sys/fcntl.h index d41af5ce11..b91792f9f7 100644 --- a/StdLib/Include/sys/fcntl.h +++ b/StdLib/Include/sys/fcntl.h @@ -54,11 +54,11 @@ #include <sys/stat.h>
-/** File status flags used by open(2), fcntl(2).
+/** @{
+ File status flags used by open(2), fcntl(2).
They are also used (indirectly) in the kernel file structure f_flags,
which is a superset of the open/fcntl flags.
Open/fcntl flags begin with O_; kernel-internal flags begin with F.
-@{
**/
/* open-only flags */
#define O_RDONLY 0x00000000 ///< open for reading only
@@ -71,6 +71,11 @@ #define O_CREAT 0x00000200 ///< create if nonexistent
#define O_TRUNC 0x00000400 ///< truncate to zero length
#define O_EXCL 0x00000800 ///< error if already exists
+
+/* UEFI-specific open-only flags. */
+#define O_HIDDEN 0x00010000 ///< Hidden file attribute
+#define O_SYSTEM 0x00020000 ///< System file attribute
+#define O_ARCHIVE 0x00040000 ///< Archive file attribute
/// @}
//#define O_DIRECT 0x00080000 /* direct I/O hint */
@@ -81,7 +86,7 @@ * Constants used for fcntl(2)
*/
-/** command values. @{ **/
+/** @{ command values used for fcntl(2). **/
#define F_DUPFD 0 ///< duplicate file descriptor
#define F_GETFD 1 ///< get file descriptor flags
#define F_SETFD 2 ///< set file descriptor flags
@@ -99,13 +104,13 @@ /** file descriptor flags (F_GETFD, F_SETFD). **/
#define FD_CLOEXEC 1 ///< close-on-exec flag
-/** record locking flags (F_GETLK, F_SETLK, F_SETLKW). @{ **/
+/** @{ record locking flags (F_GETLK, F_SETLK, F_SETLKW). **/
#define F_RDLCK 1 ///< shared or read lock
#define F_UNLCK 2 ///< unlock
#define F_WRLCK 3 ///< exclusive or write lock
/// @}
-/** Constants for fcntl's passed to the underlying fs - like ioctl's. @{ **/
+/** @{ Constants for fcntl's passed to the underlying fs - like ioctl's. **/
#define F_PARAM_MASK 0xfff
#define F_PARAM_LEN(x) (((x) >> 16) & F_PARAM_MASK)
#define F_PARAM_MAX 4095
diff --git a/StdLib/Include/sys/filio.h b/StdLib/Include/sys/filio.h index 65f34bcb5c..e514c267a7 100644 --- a/StdLib/Include/sys/filio.h +++ b/StdLib/Include/sys/filio.h @@ -1,8 +1,16 @@ -/* $NetBSD: filio.h,v 1.10 2005/12/11 12:25:20 christos Exp $ */
+/** @file
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-/*-
* Copyright (c) 1982, 1986, 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
+ * The Regents of the University of California. All rights reserved.
* (c) UNIX System Laboratories, Inc.
* All or some portions of this file are derived from material licensed
* to the University of California by American Telephone and Telegraph
@@ -33,30 +41,21 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)filio.h 8.1 (Berkeley) 3/28/94
+ * @(#)filio.h 8.1 (Berkeley) 3/28/94
+ NetBSD: filio.h,v 1.10 2005/12/11 12:25:20 christos Exp
*/
-#ifndef _SYS_FILIO_H_
-#define _SYS_FILIO_H_
+#ifndef _SYS_FILIO_H_
+#define _SYS_FILIO_H_
#include <sys/ioccom.h>
-/* Generic file-descriptor ioctl's. */
-#define FIOCLEX _IO('f', 1) /* set close on exec on fd */
-#define FIONCLEX _IO('f', 2) /* remove close on exec */
-#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */
-#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */
-#define FIOASYNC _IOW('f', 125, int) /* set/clear async i/o */
-#define FIOSETOWN _IOW('f', 124, int) /* set owner */
-#define FIOGETOWN _IOR('f', 123, int) /* get owner */
-#define OFIOGETBMAP _IOWR('f', 122, uint32_t) /* get underlying block no. */
-#define FIOGETBMAP _IOWR('f', 122, daddr_t) /* get underlying block no. */
-#define FIONWRITE _IOR('f', 121, int) /* get # bytes outstanding
- * in send queue. */
-#define FIONSPACE _IOR('f', 120, int) /* get space in send queue. */
-
-
-/* Ugly symbol for compatibility with other operating systems */
-#define FIBMAP FIOGETBMAP
+typedef const struct timeval* ptimeval_t;
+
+/* File-descriptor ioctl's. */
+
+#define FIODLEX _IO ('f', 1) /* set Delete-on-Close */
+#define FIONDLEX _IO ('f', 2) /* clear Delete-on-Close */
+#define FIOSETIME _IOW ('f', 127, ptimeval_t) /* Set access and modification times */
#endif /* !_SYS_FILIO_H_ */
diff --git a/StdLib/Include/sys/stat.h b/StdLib/Include/sys/stat.h index f95385877a..6c5d5a8078 100644 --- a/StdLib/Include/sys/stat.h +++ b/StdLib/Include/sys/stat.h @@ -113,7 +113,7 @@ struct stat { #define S_IARCHIVE 0x02000000 // Archive Bit
#define S_IROFS 0x08000000 ///< Read Only File System
-#define S_EFIONLY 0xF0000000 ///< Flags only used by the EFI system calls.
+#define S_EFIONLY 0xFFF00000 ///< Flags only used by the EFI system calls.
#define S_EFISHIFT 20 // LS bit of the UEFI attributes
@@ -142,6 +142,10 @@ struct stat { #define ALLPERMS (S_IRWXU|S_IRWXG|S_IRWXO) ///< 0777
#define DEFFILEMODE (S_IRWXU|S_IRWXG|S_IRWXO) ///< 0777
+#define READ_PERMS (S_IRUSR | S_IRGRP | S_IROTH) ///< 0444
+#define WRITE_PERMS (S_IWUSR | S_IWGRP | S_IWOTH) ///< 0222
+#define EXEC_PERMS (S_IXUSR | S_IXGRP | S_IXOTH) ///< 0111
+
#define S_BLKSIZE 512 ///< block size used in the stat struct
/*
@@ -169,25 +173,29 @@ __BEGIN_DECLS #ifndef __STAT_SYSCALLS_DECLARED
#define __STAT_SYSCALLS_DECLARED
-/**
-**/
- extern int mkdir (const char *, mode_t);
+ /**
+ **/
+ mode_t umask (mode_t);
+
+ /**
+ **/
+ int mkdir (const char *, mode_t);
/**
**/
- extern int fstat (int, struct stat *);
+ int fstat (int, struct stat *);
/**
**/
- extern int lstat (const char *, struct stat *);
+ int lstat (const char *, struct stat *);
/**
**/
- extern int stat (const char *, struct stat *);
+ int stat (const char *, struct stat *);
/**
**/
- extern int chmod (const char *, mode_t);
+ int chmod (const char *, mode_t);
#endif // __STAT_SYSCALLS_DECLARED
__END_DECLS
diff --git a/StdLib/Include/sys/time.h b/StdLib/Include/sys/time.h index b8957f4c41..2b05b116b7 100644 --- a/StdLib/Include/sys/time.h +++ b/StdLib/Include/sys/time.h @@ -59,12 +59,10 @@ struct timeval { /*
* Structure defined by POSIX.1b to be like a timeval.
* This works within EFI since the times really are time_t.
- * Note that this is not exactly POSIX compliant since tv_nsec
- * is a UINT32 instead of the compliant long.
*/
struct timespec {
time_t tv_sec; /* seconds */
- UINT32 tv_nsec; /* and nanoseconds */
+ LONG32 tv_nsec; /* and nanoseconds */
};
#define TIMEVAL_TO_TIMESPEC(tv, ts) do { \
@@ -182,10 +180,14 @@ __BEGIN_DECLS /* Convert an EFI_TIME structure into a time_t value. */
time_t Efi2Time( EFI_TIME *EfiBDtime);
+/* Convert a time_t value into an EFI_TIME structure.
+ It is the caller's responsibility to free the returned structure.
+*/
+EFI_TIME * Time2Efi(time_t OTime);
+
/* Convert an EFI_TIME structure into a C Standard tm structure. */
void Efi2Tm( EFI_TIME *EfiBDtime, struct tm *NewTime);
-
-__END_DECLS
+void Tm2Efi( struct tm *BdTime, EFI_TIME *ETime);
/* BSD compatibility functions */
int gettimeofday (struct timeval *tp, void *ignore);
@@ -193,4 +195,6 @@ int gettimeofday (struct timeval *tp, void *ignore); int getitimer (int which, struct itimerval *value);
int setitimer (int which, const struct itimerval *value, struct itimerval *ovalue);
+__END_DECLS
+
#endif /* !_SYS_TIME_H_ */
diff --git a/StdLib/Include/sys/types.h b/StdLib/Include/sys/types.h index 408d74391a..54ae00836f 100644 --- a/StdLib/Include/sys/types.h +++ b/StdLib/Include/sys/types.h @@ -238,7 +238,7 @@ typedef int64_t dtime_t; /* on-disk time_t */ #endif
#if defined(_BSD_CLOCK_T_) && defined(_EFI_CLOCK_T)
- typedef _BSD_CLOCK_T_ clock_t;
+ typedef _EFI_CLOCK_T clock_t;
#undef _BSD_CLOCK_T_
#undef _EFI_CLOCK_T
#endif
@@ -256,7 +256,7 @@ typedef int64_t dtime_t; /* on-disk time_t */ #endif
#if defined(_BSD_TIME_T_) && defined(_EFI_TIME_T)
- typedef _BSD_TIME_T_ time_t;
+ typedef _EFI_TIME_T time_t;
#undef _BSD_TIME_T_
#undef _EFI_TIME_T
#endif
diff --git a/StdLib/Include/sys/unistd.h b/StdLib/Include/sys/unistd.h index a63d88df55..274e29f096 100644 --- a/StdLib/Include/sys/unistd.h +++ b/StdLib/Include/sys/unistd.h @@ -1,6 +1,14 @@ -/* $NetBSD: unistd.h,v 1.35 2006/08/14 18:17:48 rpaulo Exp $ */
+/** @file
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
@@ -29,15 +37,14 @@ * SUCH DAMAGE.
*
* @(#)unistd.h 8.2 (Berkeley) 1/7/94
- */
-
+ NetBSD: unistd.h,v 1.35 2006/08/14 18:17:48 rpaulo Exp
+**/
#ifndef _SYS_UNISTD_H_
#define _SYS_UNISTD_H_
#include <sys/featuretest.h>
/* compile-time symbolic constants */
-//#define _POSIX_JOB_CONTROL /* implementation supports job control */
/*
* According to POSIX 1003.1:
@@ -61,129 +68,27 @@ #define _POSIX2_VERSION 199212L
/* execution-time symbolic constants */
- /* chown requires appropriate privileges */
-//#define _POSIX_CHOWN_RESTRICTED 1
-// /* clock selection */
-//#define _POSIX_CLOCK_SELECTION -1
-// /* too-long path components generate errors */
-//#define _POSIX_NO_TRUNC 1
-// /* may disable terminal special characters */
-//#define _POSIX_VDISABLE ((unsigned char)'\377')
-// /* file synchronization is available */
-//#define _POSIX_FSYNC 1
-// /* synchronized I/O is available */
-//#define _POSIX_SYNCHRONIZED_IO 1
-// /* memory mapped files */
-//#define _POSIX_MAPPED_FILES 1
-// /* memory locking of whole address space */
-//#define _POSIX_MEMLOCK 1
-// /* memory locking address ranges */
-//#define _POSIX_MEMLOCK_RANGE 1
-// /* memory access protections */
-//#define _POSIX_MEMORY_PROTECTION 1
-// /* monotonic clock */
-//#define _POSIX_MONOTONIC_CLOCK 200112L
-// /* threads */
-//#define _POSIX_THREADS 200112L
-// /* semaphores */
-//#define _POSIX_SEMAPHORES 0
-// /* barriers */
-//#define _POSIX_BARRIERS 200112L
/* timers */
#define _POSIX_TIMERS 200112L
- /* spin locks */
-//#define _POSIX_SPIN_LOCKS 200112L
-// /* read/write locks */
-//#define _POSIX_READER_WRITER_LOCKS 200112L
-// /* XPG4.2 shared memory */
-//#define _XOPEN_SHM 0
+
+/* Always ensure that these are consistent with <fcntl.h>!
+ whence values for lseek(2).
+*/
+#ifndef SEEK_SET
+#define SEEK_SET 0 /**< set file offset to offset */
+#endif
+#ifndef SEEK_CUR
+#define SEEK_CUR 1 /**< set file offset to current plus offset */
+#endif
+#ifndef SEEK_END
+#define SEEK_END 2 /**< set file offset to EOF plus offset */
+#endif
/* whence values for lseek(2); renamed by POSIX 1003.1 */
#define L_SET SEEK_SET
#define L_INCR SEEK_CUR
#define L_XTND SEEK_END
-/*
- * fsync_range values.
- *
- * Note the following flag values were chosen to not overlap
- * values for SEEK_XXX flags. While not currently implemented,
- * it is possible to extend this call to respect SEEK_CUR and
- * SEEK_END offset addressing modes.
- */
-#define FDATASYNC 0x0010 /* sync data and minimal metadata */
-#define FFILESYNC 0x0020 /* sync data and metadata */
-#define FDISKSYNC 0x0040 /* flush disk caches after sync */
-
-/* configurable pathname variables; use as argument to pathconf(3) */
-#define _PC_LINK_MAX 1
-#define _PC_MAX_CANON 2
-#define _PC_MAX_INPUT 3
-#define _PC_NAME_MAX 4
-#define _PC_PATH_MAX 5
-#define _PC_PIPE_BUF 6
-#define _PC_CHOWN_RESTRICTED 7
-#define _PC_NO_TRUNC 8
-#define _PC_VDISABLE 9
-#define _PC_SYNC_IO 10
-#define _PC_FILESIZEBITS 11
-
-/* configurable system variables; use as argument to sysconf(3) */
-/*
- * XXX The value of _SC_CLK_TCK is embedded in <time.h>.
- * XXX The value of _SC_PAGESIZE is embedded in <sys/shm.h>.
- */
-#define _SC_ARG_MAX 1
-#define _SC_CHILD_MAX 2
-#define _O_SC_CLK_TCK 3 /* Old version, always 100 */
-#define _SC_NGROUPS_MAX 4
-#define _SC_OPEN_MAX 5
-#define _SC_JOB_CONTROL 6
-#define _SC_SAVED_IDS 7
-#define _SC_VERSION 8
-#define _SC_BC_BASE_MAX 9
-#define _SC_BC_DIM_MAX 10
-#define _SC_BC_SCALE_MAX 11
-#define _SC_BC_STRING_MAX 12
-#define _SC_COLL_WEIGHTS_MAX 13
-#define _SC_EXPR_NEST_MAX 14
-#define _SC_LINE_MAX 15
-#define _SC_RE_DUP_MAX 16
-#define _SC_2_VERSION 17
-#define _SC_2_C_BIND 18
-#define _SC_2_C_DEV 19
-#define _SC_2_CHAR_TERM 20
-#define _SC_2_FORT_DEV 21
-#define _SC_2_FORT_RUN 22
-#define _SC_2_LOCALEDEF 23
-#define _SC_2_SW_DEV 24
-#define _SC_2_UPE 25
-#define _SC_STREAM_MAX 26
-#define _SC_TZNAME_MAX 27
-#define _SC_PAGESIZE 28
-#define _SC_PAGE_SIZE _SC_PAGESIZE /* 1170 compatibility */
-#define _SC_FSYNC 29
-#define _SC_XOPEN_SHM 30
-#define _SC_SYNCHRONIZED_IO 31
-#define _SC_IOV_MAX 32
-#define _SC_MAPPED_FILES 33
-#define _SC_MEMLOCK 34
-#define _SC_MEMLOCK_RANGE 35
-#define _SC_MEMORY_PROTECTION 36
-#define _SC_LOGIN_NAME_MAX 37
-#define _SC_MONOTONIC_CLOCK 38
-#define _SC_CLK_TCK 39 /* New, variable version */
-#define _SC_ATEXIT_MAX 40
-#define _SC_THREADS 41
-#define _SC_SEMAPHORES 42
-#define _SC_BARRIERS 43
-#define _SC_TIMERS 44
-#define _SC_SPIN_LOCKS 45
-#define _SC_READER_WRITER_LOCKS 46
-#define _SC_GETGR_R_SIZE_MAX 47
-#define _SC_GETPW_R_SIZE_MAX 48
-#define _SC_CLOCK_SELECTION 49
-
/* configurable system strings */
#define _CS_PATH 1
diff --git a/StdLib/Include/unistd.h b/StdLib/Include/unistd.h index 4d738c64b6..b2fd92358a 100644 --- a/StdLib/Include/unistd.h +++ b/StdLib/Include/unistd.h @@ -25,6 +25,12 @@ #define F_TLOCK 2
#define F_TEST 3
+/* access function */
+#define F_OK 0 /* test for existence of file */
+#define X_OK 0x01 /* test for execute or search permission */
+#define W_OK 0x02 /* test for write permission */
+#define R_OK 0x04 /* test for read permission */
+
__BEGIN_DECLS
int dup(int);
@@ -41,6 +47,65 @@ int usleep(useconds_t); unsigned int sleep(unsigned int);
char *basename(char *path);
+#ifndef GETCWD_DECLARED
+ /** Gets the current working directory.
+
+ The getcwd() function shall place an absolute pathname of the current
+ working directory in the array pointed to by buf, and return buf. The
+ pathname copied to the array shall contain no components that are
+ symbolic links. The size argument is the size in bytes of the character
+ array pointed to by the buf argument.
+
+ @param[in,out] Buf The buffer to fill.
+ @param[in] BufSize The number of bytes in buffer.
+
+ @retval NULL The function failed.
+ @retval NULL Buf was NULL.
+ @retval NULL Size was 0.
+ @return buf The function completed successfully. See errno for info.
+ **/
+ char *getcwd(char *Buf, size_t BufSize);
+ #define GETCWD_DECLARED
+#endif
+
+#ifndef CHDIR_DECLARED
+ /** Change the current working directory.
+
+ The chdir() function shall cause the directory named by the pathname
+ pointed to by the path argument to become the current working directory;
+ that is, the starting point for path searches for pathnames not beginning
+ with '/'.
+
+ @param[in] Path The new path to set.
+
+ @todo Add non-shell CWD changing.
+ **/
+ int chdir(const char *Path);
+#define CHDIR_DECLARED
+#endif
+
+/** Determine accessibility of a file.
+ The access() function checks the file, named by the pathname pointed to by
+ the Path argument, for accessibility according to the bit pattern contained
+ in Mode.
+
+ The value of Mode is either the bitwise-inclusive OR of the access
+ permissions to be checked (R_OK, W_OK, X_OK) or the existence test (F_OK).
+
+ If Path ends in '/' or '\\', the target must be a directory, otherwise it doesn't matter.
+ A file is executable if it is NOT a directory and it ends in ".efi".
+
+ @param[in] Path Path or name of the file to be checked.
+ @param[in] Mode Access permissions to check for.
+
+ @retval 0 Successful completion.
+ @retval -1 File is not accessible with the given Mode. The error condition
+ is indicated by errno. Values of errno specific to the access
+ function include: EACCES, ENOENT, ENOTDIR, ENAMETOOLONG
+**/
+int access(const char *Path, int Mode);
+pid_t getpid(void);
+
// Networking
long gethostid(void);
int gethostname(char *, size_t);
@@ -77,7 +142,6 @@ gid_t getegid(void); uid_t geteuid(void);
gid_t getgid(void);
int getgroups(int, gid_t []);
-pid_t getpid(void);
pid_t getppid(void);
int link(const char *, const char *);
long pathconf(const char *, int);
diff --git a/StdLib/Include/utime.h b/StdLib/Include/utime.h new file mode 100644 index 0000000000..744881c15a --- /dev/null +++ b/StdLib/Include/utime.h @@ -0,0 +1,66 @@ +/** @file
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)utime.h 8.1 (Berkeley) 6/2/93
+ NetBSD: utime.h,v 1.8 2005/02/03 04:39:32 perry Exp
+ */
+
+#ifndef _UTIME_H_
+#define _UTIME_H_
+
+#include <sys/cdefs.h>
+#include <machine/ansi.h>
+#include <sys/time.h>
+
+#if defined(_BSD_TIME_T_) && defined(_EFI_TIME_T)
+typedef _EFI_TIME_T time_t;
+#undef _BSD_TIME_T_
+#undef _EFI_TIME_T
+#endif
+
+struct utimbuf {
+ time_t actime; /* Access time */
+ time_t modtime; /* Modification time */
+};
+
+__BEGIN_DECLS
+ int utime (const char *path, const struct utimbuf *times);
+ int utimes (const char *path, const struct timeval *times);
+__END_DECLS
+
+#endif /* !_UTIME_H_ */
diff --git a/StdLib/LibC/Ctype/CClass.c b/StdLib/LibC/Ctype/CClass.c index 1e1e0fdccb..b9658441ae 100644 --- a/StdLib/LibC/Ctype/CClass.c +++ b/StdLib/LibC/Ctype/CClass.c @@ -234,7 +234,7 @@ isblank( IN int c
)
{
- return (__isCClass( c, _CB));
+ return (__isCClass( c, (_CB)));
}
/** The isascii function tests that a character is one of the 128 7-bit ASCII characters.
@@ -251,3 +251,21 @@ isascii( {
return ((c >= 0) && (c < 128));
}
+
+/** Test whether a character is one of the characters used as a separator
+ between directory elements in a path.
+
+ Characters are '/', '\\'
+
+ This non-standard function is unique to this implementation.
+
+ @param[in] c The character to be tested.
+
+ @return Returns nonzero (true) if and only if the value of the parameter c
+ can be classified as specified in the description of the function.
+**/
+int
+isDirSep(int c)
+{
+ return (__isCClass( c, (_C0)));
+}
diff --git a/StdLib/LibC/Ctype/iCtype.c b/StdLib/LibC/Ctype/iCtype.c index 6b289bf2f2..b40a65d1ff 100644 --- a/StdLib/LibC/Ctype/iCtype.c +++ b/StdLib/LibC/Ctype/iCtype.c @@ -57,7 +57,7 @@ const UINT16 _C_CharClassTable[128] = { /* 24 '$' */ ( _CP | _CG ),
/* 25 '%' */ ( _CP | _CG ),
/* 26 '&' */ ( _CP | _CG ),
- /* 27 '\''*/ ( _CP | _CG ),
+ /* 27 '\''*/ ( _CP | _CG | _C0 ),
/* 28 '(' */ ( _CP | _CG ),
/* 29 ')' */ ( _CP | _CG ),
/* 2A '*' */ ( _CP | _CG ),
@@ -65,7 +65,7 @@ const UINT16 _C_CharClassTable[128] = { /* 2C ',' */ ( _CP | _CG ),
/* 2D '-' */ ( _CP | _CG ),
/* 2E '.' */ ( _CP | _CG ),
- /* 2F '/' */ ( _CP | _CG ),
+ /* 2F '/' */ ( _CP | _CG | _C0 ),
/* 30 '0' */ ( _CD | _CG ),
/* 31 '1' */ ( _CD | _CG ),
/* 32 '2' */ ( _CD | _CG ),
diff --git a/StdLib/LibC/Locale/setlocale.c b/StdLib/LibC/Locale/setlocale.c index 4d617d21da..2012f3c564 100644 --- a/StdLib/LibC/Locale/setlocale.c +++ b/StdLib/LibC/Locale/setlocale.c @@ -66,7 +66,7 @@ #include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/EfiSysCall.h>
+#include <unistd.h>
#include "rune.h"
#ifdef WITH_RUNE
#include "rune_local.h"
diff --git a/StdLib/LibC/Stdio/fdopen.c b/StdLib/LibC/Stdio/fdopen.c index 3a728951f6..4c6902396e 100644 --- a/StdLib/LibC/Stdio/fdopen.c +++ b/StdLib/LibC/Stdio/fdopen.c @@ -1,6 +1,14 @@ -/* $NetBSD: fdopen.c,v 1.14 2003/08/07 16:43:22 agc Exp $ */
+/** @file
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
@@ -30,16 +38,12 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- */
+
+ NetBSD: fdopen.c,v 1.14 2003/08/07 16:43:22 agc Exp
+ fdopen.c 8.1 (Berkeley) 6/4/93
+**/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)fdopen.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: fdopen.c,v 1.14 2003/08/07 16:43:22 agc Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <sys/types.h>
@@ -47,8 +51,8 @@ __RCSID("$NetBSD: fdopen.c,v 1.14 2003/08/07 16:43:22 agc Exp $"); #include <assert.h>
#include <errno.h>
#include <fcntl.h>
-#include <sys/EfiSysCall.h>
#include <stdio.h>
+#include <unistd.h>
#include "reentrant.h"
#include "local.h"
diff --git a/StdLib/LibC/Stdio/findfp.c b/StdLib/LibC/Stdio/findfp.c index b6495c3bcb..bc8bfe3d29 100644 --- a/StdLib/LibC/Stdio/findfp.c +++ b/StdLib/LibC/Stdio/findfp.c @@ -1,6 +1,14 @@ -/* $NetBSD: findfp.c,v 1.23 2006/10/07 21:40:46 thorpej Exp $ */
+/** @file
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
@@ -30,24 +38,20 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- */
+
+ NetBSD: findfp.c,v 1.23 2006/10/07 21:40:46 thorpej Exp
+ findfp.c 8.2 (Berkeley) 1/4/94
+**/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)findfp.c 8.2 (Berkeley) 1/4/94";
-#else
-__RCSID("$NetBSD: findfp.c,v 1.23 2006/10/07 21:40:46 thorpej Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <sys/param.h>
-#include <sys/EfiSysCall.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include "reentrant.h"
#include "local.h"
#include "glue.h"
diff --git a/StdLib/LibC/Stdio/fopen.c b/StdLib/LibC/Stdio/fopen.c index 4b3c14cd28..9fc0f6dd4c 100644 --- a/StdLib/LibC/Stdio/fopen.c +++ b/StdLib/LibC/Stdio/fopen.c @@ -1,7 +1,7 @@ /** @file
Implementation of fopen as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License that accompanies this
distribution. The full text of the license may be found at
@@ -50,9 +50,9 @@ #include <sys/stat.h>
#include <assert.h>
#include <fcntl.h>
-#include <sys/EfiSysCall.h>
#include <stdio.h>
#include <errno.h>
+#include <unistd.h>
#include "reentrant.h"
#include "local.h"
diff --git a/StdLib/LibC/Stdio/freopen.c b/StdLib/LibC/Stdio/freopen.c index 75a086b84b..58381e6d19 100644 --- a/StdLib/LibC/Stdio/freopen.c +++ b/StdLib/LibC/Stdio/freopen.c @@ -52,10 +52,10 @@ #include <assert.h>
#include <errno.h>
#include <fcntl.h>
-#include <sys/EfiSysCall.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
+#include <unistd.h>
#include "reentrant.h"
#include "local.h"
diff --git a/StdLib/LibC/Stdio/gettemp.c b/StdLib/LibC/Stdio/gettemp.c index 7b1c564c9a..0773340ad8 100644 --- a/StdLib/LibC/Stdio/gettemp.c +++ b/StdLib/LibC/Stdio/gettemp.c @@ -1,7 +1,7 @@ /** @file
Internal function to generate temporary file name for tmpnam.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License that accompanies this
distribution. The full text of the license may be found at
@@ -37,6 +37,7 @@ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
+ mktemp.c 8.1 (Berkeley) 6/4/93
NetBSD: gettemp.c,v 1.13 2003/12/05 00:57:36 uebayasi Exp
**/
#include <LibConfig.h>
@@ -48,13 +49,6 @@ #if !defined(HAVE_NBTOOL_CONFIG_H) || !defined(HAVE_MKSTEMP) || !defined(HAVE_MKDTEMP)
#include <sys/EfiCdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: gettemp.c,v 1.13 2003/12/05 00:57:36 uebayasi Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <sys/stat.h>
@@ -65,7 +59,7 @@ __RCSID("$NetBSD: gettemp.c,v 1.13 2003/12/05 00:57:36 uebayasi Exp $"); #include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
-#include <sys/EfiSysCall.h>
+#include <unistd.h>
#if HAVE_NBTOOL_CONFIG_H
#define GETTEMP gettemp
diff --git a/StdLib/LibC/Stdio/makebuf.c b/StdLib/LibC/Stdio/makebuf.c index 4e69be1275..1b5991489c 100644 --- a/StdLib/LibC/Stdio/makebuf.c +++ b/StdLib/LibC/Stdio/makebuf.c @@ -52,7 +52,7 @@ #include <assert.h>
#include <stdio.h>
#include <stdlib.h>
-#include <sys/EfiSysCall.h>
+#include <unistd.h>
#include "reentrant.h"
#include "local.h"
#include <MainData.h>
diff --git a/StdLib/LibC/Stdio/mktemp.c b/StdLib/LibC/Stdio/mktemp.c index 4c9e4752cc..a20eddaf99 100644 --- a/StdLib/LibC/Stdio/mktemp.c +++ b/StdLib/LibC/Stdio/mktemp.c @@ -1,7 +1,7 @@ /** @file
Internal function for tmpnam.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License that accompanies this
distribution. The full text of the license may be found at
@@ -46,7 +46,7 @@ mktemp.c 8.1 (Berkeley) 6/4/93 #include <errno.h>
#include <stdio.h>
#include <stdlib.h>
-#include <sys/EfiSysCall.h>
+#include <unistd.h>
#include "reentrant.h"
#include "local.h"
diff --git a/StdLib/LibC/Stdio/remove.c b/StdLib/LibC/Stdio/remove.c index 826471cde5..7f53f95be1 100644 --- a/StdLib/LibC/Stdio/remove.c +++ b/StdLib/LibC/Stdio/remove.c @@ -1,6 +1,14 @@ -/* $NetBSD: remove.c,v 1.13 2003/08/07 16:43:30 agc Exp $ */
+/** @file
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
@@ -30,16 +38,12 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- */
+
+ remove.c 8.1 (Berkeley) 6/4/93
+ NetBSD: remove.c,v 1.13 2003/08/07 16:43:30 agc Exp
+**/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)remove.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: remove.c,v 1.13 2003/08/07 16:43:30 agc Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <sys/stat.h>
@@ -47,7 +51,7 @@ __RCSID("$NetBSD: remove.c,v 1.13 2003/08/07 16:43:30 agc Exp $"); #include <assert.h>
#include <errno.h>
#include <stdio.h>
-#include <sys/EfiSysCall.h>
+#include <unistd.h>
int
remove(const char *file)
diff --git a/StdLib/LibC/Stdio/stdio.c b/StdLib/LibC/Stdio/stdio.c index de8963e574..7b5cc3862d 100644 --- a/StdLib/LibC/Stdio/stdio.c +++ b/StdLib/LibC/Stdio/stdio.c @@ -52,7 +52,7 @@ #include <errno.h>
#include <fcntl.h>
#include <stdio.h>
-#include <sys/EfiSysCall.h>
+#include <unistd.h>
#include "reentrant.h"
#include "local.h"
diff --git a/StdLib/LibC/Stdio/tempnam.c b/StdLib/LibC/Stdio/tempnam.c index f9df427c52..94d2655c8a 100644 --- a/StdLib/LibC/Stdio/tempnam.c +++ b/StdLib/LibC/Stdio/tempnam.c @@ -1,6 +1,14 @@ -/* $NetBSD: tempnam.c,v 1.19 2005/07/27 13:23:07 drochner Exp $ */
+/** @file
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
@@ -27,16 +35,12 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- */
+
+ tempnam.c 8.1 (Berkeley) 6/4/93
+ NetBSD: tempnam.c,v 1.19 2005/07/27 13:23:07 drochner Exp
+**/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)tempnam.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: tempnam.c,v 1.19 2005/07/27 13:23:07 drochner Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <sys/param.h>
@@ -44,7 +48,7 @@ __RCSID("$NetBSD: tempnam.c,v 1.19 2005/07/27 13:23:07 drochner Exp $"); #include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/EfiSysCall.h>
+#include <unistd.h>
#include <paths.h>
#include "reentrant.h"
#include "local.h"
diff --git a/StdLib/LibC/Stdio/tmpfile.c b/StdLib/LibC/Stdio/tmpfile.c index 97040d58f2..d93787684b 100644 --- a/StdLib/LibC/Stdio/tmpfile.c +++ b/StdLib/LibC/Stdio/tmpfile.c @@ -1,6 +1,14 @@ -/* $NetBSD: tmpfile.c,v 1.11 2003/08/07 16:43:33 agc Exp $ */
+/** @file
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
@@ -30,26 +38,22 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- */
+
+ tmpfile.c 8.1 (Berkeley) 6/4/93
+ NetBSD: tmpfile.c,v 1.11 2003/08/07 16:43:33 agc Exp
+**/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)tmpfile.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: tmpfile.c,v 1.11 2003/08/07 16:43:33 agc Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <sys/types.h>
-#include <sys/EfiSysCall.h>
#include <signal.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <paths.h>
+#include <unistd.h>
#define TRAILER "tmp.XXXX"
diff --git a/StdLib/LibC/Stdio/tmpnam.c b/StdLib/LibC/Stdio/tmpnam.c index 74dd77325a..95c6edd04b 100644 --- a/StdLib/LibC/Stdio/tmpnam.c +++ b/StdLib/LibC/Stdio/tmpnam.c @@ -1,11 +1,11 @@ /** @file
Implementation of tmpnam as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License that accompanies this
distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -50,7 +50,7 @@ #include <sys/types.h>
#include <paths.h>
#include <stdio.h>
-#include <sys/EfiSysCall.h>
+#include <unistd.h>
#include "reentrant.h"
#include "local.h"
diff --git a/StdLib/LibC/Time/TimeEfi.c b/StdLib/LibC/Time/TimeEfi.c index 8c033fd7d9..50f2deec05 100644 --- a/StdLib/LibC/Time/TimeEfi.c +++ b/StdLib/LibC/Time/TimeEfi.c @@ -19,9 +19,16 @@ #include "tzfile.h"
#include <MainData.h>
-/* Convert an EFI_TIME structure into a C Standard tm structure. */
+/** Convert an EFI_TIME structure into a C Standard tm structure.
+
+ @param[in] ET Pointer to the EFI_TIME structure to convert.
+ @param[out] BT Pointer to the tm structure to receive the converted time.
+*/
void
-Efi2Tm( EFI_TIME *ET, struct tm *BT)
+Efi2Tm(
+ IN EFI_TIME *ET,
+ OUT struct tm *BT
+ )
{
// Convert EFI time to broken-down time.
BT->tm_year = ET->Year - TM_YEAR_BASE;
@@ -36,11 +43,68 @@ Efi2Tm( EFI_TIME *ET, struct tm *BT) BT->tm_Nano = ET->Nanosecond;
}
-/* Convert an EFI_TIME structure into a time_t value. */
+/** Convert an EFI_TIME structure into a time_t value.
+
+ @param[in] EfiBDtime Pointer to the EFI_TIME structure to convert.
+
+ @return The EFI_TIME converted into a time_t value.
+*/
time_t
-Efi2Time( EFI_TIME *EfiBDtime)
+Efi2Time(
+ IN EFI_TIME *EfiBDtime
+ )
{
Efi2Tm( EfiBDtime, &gMD->BDTime);
return mktime( &gMD->BDTime);
}
+
+/** Convert a C Standard tm structure into an EFI_TIME structure.
+
+ @param[in] BT Pointer to the tm structure to convert.
+ @param[out] ET Pointer to an EFI_TIME structure to receive the converted time.
+*/
+void
+Tm2Efi(
+ IN struct tm *BT,
+ OUT EFI_TIME *ET
+ )
+{
+ ET->Year = (UINT16)BT->tm_year + TM_YEAR_BASE;
+ ET->Month = (UINT8)BT->tm_mon + 1;
+ ET->Day = (UINT8)BT->tm_mday;
+ ET->Hour = (UINT8)BT->tm_hour;
+ ET->Minute = (UINT8)BT->tm_min;
+ ET->Second = (UINT8)BT->tm_sec;
+ ET->Nanosecond = (UINT32)BT->tm_Nano;
+ ET->TimeZone = (INT16)BT->tm_zoneoff;
+ ET->Daylight = (UINT8)BT->tm_daylight;
+}
+
+/** Convert a time_t value into an EFI_TIME structure.
+
+ @param[in] CalTime Calendar time as a time_t value.
+
+ @return Returns a newly malloced EFI_TIME structure containing
+ the converted calendar time.
+
+ @post It is the responsibility of the caller to free the
+ returned structure before the application exits.
+*/
+EFI_TIME*
+Time2Efi(
+ IN time_t CalTime
+ )
+{
+ struct tm *IT;
+ EFI_TIME *ET = NULL;
+
+ IT = gmtime(&CalTime);
+ if(IT != NULL) {
+ ET = malloc(sizeof(EFI_TIME));
+ if(ET != NULL) {
+ Tm2Efi(IT, ET);
+ }
+ }
+ return ET;
+}
diff --git a/StdLib/LibC/Time/ZoneProc.c b/StdLib/LibC/Time/ZoneProc.c index a7b589b7df..309d7b3527 100644 --- a/StdLib/LibC/Time/ZoneProc.c +++ b/StdLib/LibC/Time/ZoneProc.c @@ -1,7 +1,7 @@ /** @file
Time Zone processing.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
@@ -19,7 +19,6 @@ NetBSD: localtime.c,v 1.39 2006/03/22 14:01:30 christos Exp
**/
#include <LibConfig.h>
-#include <sys/EfiSysCall.h>
#include <ctype.h>
#include <fcntl.h>
@@ -27,6 +26,7 @@ #include <stdlib.h>
#include <string.h>
#include <time.h>
+#include <unistd.h>
#include "tzfile.h"
#include "TimeVals.h"
diff --git a/StdLib/LibC/Time/itimer.c b/StdLib/LibC/Time/itimer.c index d6f6ab44c0..00712b8247 100644 --- a/StdLib/LibC/Time/itimer.c +++ b/StdLib/LibC/Time/itimer.c @@ -11,12 +11,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <LibConfig.h>
-#include <sys/EfiSysCall.h>
#include <sys/time.h>
#include <time.h>
#include <errno.h>
#include <sys/signal.h>
#include <signal.h>
+#include <unistd.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UefiLib.h>
@@ -274,4 +274,4 @@ int getitimer( }
return 0;
-}
\ No newline at end of file +}
diff --git a/StdLib/LibC/Uefi/Devices/Console/daConsole.c b/StdLib/LibC/Uefi/Devices/Console/daConsole.c index 600fb073c4..e9983e9933 100644 --- a/StdLib/LibC/Uefi/Devices/Console/daConsole.c +++ b/StdLib/LibC/Uefi/Devices/Console/daConsole.c @@ -21,13 +21,13 @@ #include <Protocol/SimpleTextOut.h>
#include <LibConfig.h>
-#include <sys/EfiSysCall.h>
#include <errno.h>
#include <wctype.h>
#include <wchar.h>
#include <stdarg.h>
#include <sys/fcntl.h>
+#include <unistd.h>
#include <kfile.h>
#include <Device/Device.h>
#include <MainData.h>
diff --git a/StdLib/LibC/Uefi/Devices/UefiShell/daShell.c b/StdLib/LibC/Uefi/Devices/UefiShell/daShell.c index de14ef31c5..861765e6bc 100644 --- a/StdLib/LibC/Uefi/Devices/UefiShell/daShell.c +++ b/StdLib/LibC/Uefi/Devices/UefiShell/daShell.c @@ -21,7 +21,6 @@ #include <Library/ShellLib.h>
#include <LibConfig.h>
-#include <sys/EfiSysCall.h>
#include <errno.h>
#include <string.h>
@@ -30,12 +29,21 @@ #include <wctype.h>
#include <wchar.h>
#include <sys/fcntl.h>
+#include <sys/filio.h>
#include <sys/syslimits.h>
+#include <unistd.h>
#include <kfile.h>
#include <Device/Device.h>
#include <MainData.h>
#include <Efi/SysEfi.h>
+/** EFI Shell specific operations for close().
+
+ @param[in] Fp Pointer to a file descriptor structure.
+
+ @retval 0 Successful completion.
+ @retval -1 Operation failed. Further information is specified by errno.
+**/
static
int
EFIAPI
@@ -50,6 +58,13 @@ da_ShellClose( return 0;
}
+/** EFI Shell specific operations for deleting a file or directory.
+
+ @param[in] filp Pointer to a file descriptor structure.
+
+ @retval 0 Successful completion.
+ @retval -1 Operation failed. Further information is specified by errno.
+**/
static
int
EFIAPI
@@ -68,6 +83,14 @@ da_ShellDelete( return 0;
}
+/** EFI Shell specific operations for setting the position within a file.
+
+ @param[in] filp Pointer to a file descriptor structure.
+ @param[in] offset Relative position to move to.
+ @param[in] whence Specifies the location offset is relative to: Beginning, Current, End.
+
+ @return Returns the new file position or EOF if the seek failed.
+**/
static
off_t
EFIAPI
@@ -126,6 +149,9 @@ da_ShellSeek( The directory is closed after it is created.
+ @param[in] path The directory to be created.
+ @param[in] perms Access permissions for the new directory.
+
@retval 0 The directory was created successfully.
@retval -1 An error occurred and an error code is stored in errno.
**/
@@ -137,6 +163,7 @@ da_ShellMkdir( __mode_t perms
)
{
+ UINT64 TempAttr;
SHELL_FILE_HANDLE FileHandle;
RETURN_STATUS Status;
EFI_FILE_INFO *FileInfo;
@@ -152,7 +179,8 @@ da_ShellMkdir( FileInfo = ShellGetFileInfo( FileHandle);
Status = RETURN_ABORTED; // In case ShellGetFileInfo() failed
if(FileInfo != NULL) {
- FileInfo->Attribute = Omode2EFI(perms);
+ TempAttr = FileInfo->Attribute & (EFI_FILE_RESERVED | EFI_FILE_DIRECTORY);
+ FileInfo->Attribute = TempAttr | Omode2EFI(perms);
Status = ShellSetFileInfo( FileHandle, FileInfo);
FreePool(FileInfo);
if(Status == RETURN_SUCCESS) {
@@ -168,6 +196,16 @@ da_ShellMkdir( return retval;
}
+/** EFI Shell specific operations for reading from a file.
+
+ @param[in] filp Pointer to a file descriptor structure.
+ @param[in] offset Offset into the file to begin reading at, or NULL.
+ @param[in] BufferSize Number of bytes in Buffer. Max number of bytes to read.
+ @param[in] Buffer Pointer to a buffer to receive the read data.
+
+ @return Returns the number of bytes successfully read,
+ or -1 if the operation failed. Further information is specified by errno.
+**/
static
ssize_t
EFIAPI
@@ -209,6 +247,16 @@ da_ShellRead( return BufSize;
}
+/** EFI Shell specific operations for writing to a file.
+
+ @param[in] filp Pointer to a file descriptor structure.
+ @param[in] offset Offset into the file to begin writing at, or NULL.
+ @param[in] BufferSize Number of bytes in Buffer. Max number of bytes to write.
+ @param[in] Buffer Pointer to a buffer containing the data to be written.
+
+ @return Returns the number of bytes successfully written,
+ or -1 if the operation failed. Further information is specified by errno.
+**/
static
ssize_t
EFIAPI
@@ -261,6 +309,15 @@ da_ShellWrite( return BufSize;
}
+/** EFI Shell specific operations for getting information about an open file.
+
+ @param[in] filp Pointer to a file descriptor structure.
+ @param[out] statbuf Buffer in which to store the file status.
+ @param[in] Something This parameter is not used by this device.
+
+ @retval 0 Successful completion.
+ @retval -1 Operation failed. Further information is specified by errno.
+**/
static
int
EFIAPI
@@ -314,6 +371,15 @@ da_ShellStat( return (Status == RETURN_SUCCESS)? 0 : -1;
}
+/** EFI Shell specific operations for low-level control of a file or device.
+
+ @param[in] filp Pointer to a file descriptor structure.
+ @param[in] cmd The command this ioctl is to perform.
+ @param[in,out] argp Zero or more arguments as needed by the command.
+
+ @retval 0 Successful completion.
+ @retval -1 Operation failed. Further information is specified by errno.
+**/
static
int
EFIAPI
@@ -323,10 +389,70 @@ da_ShellIoctl( va_list argp
)
{
- return -EPERM;
+ EFI_FILE_INFO *FileInfo = NULL;
+ SHELL_FILE_HANDLE FileHandle;
+ RETURN_STATUS Status = RETURN_SUCCESS;
+ int retval = 0;
+
+ FileHandle = (SHELL_FILE_HANDLE)filp->devdata;
+
+ FileInfo = ShellGetFileInfo( FileHandle);
+
+ if(FileInfo != NULL) {
+ if( cmd == (ULONGN)FIOSETIME) {
+ struct timeval *TV;
+ EFI_TIME *ET;
+ int mod = 0;
+
+ TV = va_arg(argp, struct timeval*);
+ if(TV[0].tv_sec != 0) {
+ ET = Time2Efi(TV[0].tv_sec);
+ if(ET != NULL) {
+ (void) memcpy(&FileInfo->LastAccessTime, ET, sizeof(EFI_TIME));
+ FileInfo->LastAccessTime.Nanosecond = TV[0].tv_usec * 1000;
+ free(ET);
+ ++mod;
+ }
+ }
+ if(TV[1].tv_sec != 0) {
+ ET = Time2Efi(TV[1].tv_sec);
+ if(ET != NULL) {
+ (void) memcpy(&FileInfo->ModificationTime, ET, sizeof(EFI_TIME));
+ FileInfo->ModificationTime.Nanosecond = TV[1].tv_usec * 1000;
+ free(ET);
+ ++mod;
+ }
+ }
+ /* Set access and modification times */
+ Status = ShellSetFileInfo(FileHandle, FileInfo);
+ errno = EFI2errno(Status);
+ }
+ }
+ else {
+ Status = RETURN_DEVICE_ERROR;
+ errno = EIO;
+ }
+ if(RETURN_ERROR(Status)) {
+ retval = -1;
+ }
+ EFIerrno = Status;
+
+ if(FileInfo != NULL) {
+ FreePool(FileInfo); // Release the buffer allocated by the GetInfo function
+ }
+ return retval;
}
-/** Open an abstract Shell File.
+/** EFI Shell specific operations for opening a file or directory.
+
+ @param[in] DevNode Pointer to a device descriptor
+ @param[in] filp Pointer to a file descriptor structure.
+ @param[in] DevInstance Not used by this device.
+ @param[in] Path File-system path to the file or directory.
+ @param[in] MPath Device or Map name on which Path resides.
+
+ @return Returns a file descriptor for the newly opened file,
+ or -1 if the Operation failed. Further information is specified by errno.
**/
int
EFIAPI
@@ -447,14 +573,19 @@ da_ShellOpen( }
#include <sys/poll.h>
-/* Returns a bit mask describing which operations could be completed immediately.
+/** Returns a bit mask describing which operations could be completed immediately.
For now, assume the file system, via the shell, is always ready.
(POLLIN | POLLRDNORM) The file system is ready to be read.
(POLLOUT) The file system is ready for output.
-*/
+ @param[in] filp Pointer to a file descriptor structure.
+ @param[in] events Bit mask describing which operations to check.
+
+ @return The returned value is a bit mask describing which operations
+ could be completed immediately, without blocking.
+**/
static
short
EFIAPI
@@ -488,6 +619,14 @@ da_ShellPoll( return (retval & (events | POLL_RETONLY));
}
+/** EFI Shell specific operations for renaming a file.
+
+ @param[in] from Name of the file to be renamed.
+ @param[in] to New name for the file.
+
+ @retval 0 Successful completion.
+ @retval -1 Operation failed. Further information is specified by errno.
+**/
static
int
EFIAPI
@@ -553,6 +692,13 @@ da_ShellRename( return -1;
}
+/** EFI Shell specific operations for deleting directories.
+
+ @param[in] filp Pointer to a file descriptor structure.
+
+ @retval 0 Successful completion.
+ @retval -1 Operation failed. Further information is specified by errno.
+**/
static
int
EFIAPI
@@ -562,10 +708,12 @@ da_ShellRmdir( {
SHELL_FILE_HANDLE FileHandle;
RETURN_STATUS Status = RETURN_SUCCESS;
- EFI_FILE_INFO *FileInfo = NULL;
+ EFI_FILE_INFO *FileInfo;
+ int OldErrno;
int Count = 0;
BOOLEAN NoFile = FALSE;
+ OldErrno = errno; // Save the original value
errno = 0; // Make it easier to see if we have an error later
FileHandle = (SHELL_FILE_HANDLE)filp->devdata;
@@ -576,8 +724,8 @@ da_ShellRmdir( errno = ENOTDIR;
}
else {
- // See if the directory has any entries other than ".." and ".".
FreePool(FileInfo); // Free up the buffer from ShellGetFileInfo()
+ // See if the directory has any entries other than ".." and ".".
Status = ShellFindFirstFile( FileHandle, &FileInfo);
if(Status == RETURN_SUCCESS) {
++Count;
@@ -593,15 +741,22 @@ da_ShellRmdir( Count = 99;
}
}
- FreePool(FileInfo); // Free buffer from ShellFindFirstFile()
+ /* Count == 99 and FileInfo is allocated if ShellFindNextFile failed.
+ ShellFindNextFile has freed FileInfo itself if it sets NoFile TRUE.
+ */
+ if((! NoFile) || (Count == 99)) {
+ free(FileInfo); // Free buffer from ShellFindFirstFile()
+ }
if(Count < 3) {
// Directory is empty
Status = ShellDeleteFile( &FileHandle);
if(Status == RETURN_SUCCESS) {
EFIerrno = RETURN_SUCCESS;
+ errno = OldErrno; // Restore the original value
return 0;
/* ######## SUCCESSFUL RETURN ######## */
}
+ /* FileInfo is freed and FileHandle closed. */
}
else {
if(Count == 99) {
@@ -617,6 +772,7 @@ da_ShellRmdir( else {
errno = EIO;
}
+ ShellCloseFile( &FileHandle);
EFIerrno = Status;
if(errno == 0) {
errno = EFI2errno( Status );
@@ -628,6 +784,13 @@ da_ShellRmdir( Allocate the instance structure and populate it with the information for
the device.
+
+ @param[in] ImageHandle This application's image handle.
+ @param[in] SystemTable Pointer to the UEFI System Table.
+
+ @retval RETURN_SUCCESS Successful completion.
+ @retval RETURN_OUT_OF_RESOURCES Failed to allocate memory for new device.
+ @retval RETURN_INVALID_PARAMETER A default device has already been created.
**/
RETURN_STATUS
EFIAPI
@@ -669,6 +832,13 @@ __ctor_DevShell( return Status;
}
+/** Destructor for previously constructed EFI Shell device instances.
+
+ @param[in] ImageHandle This application's image handle.
+ @param[in] SystemTable Pointer to the UEFI System Table.
+
+ @retval 0 Successful completion is always returned.
+**/
RETURN_STATUS
EFIAPI
__dtor_DevShell(
diff --git a/StdLib/LibC/Uefi/StubFunctions.c b/StdLib/LibC/Uefi/StubFunctions.c index 1462c3ff38..806cf4ac2b 100644 --- a/StdLib/LibC/Uefi/StubFunctions.c +++ b/StdLib/LibC/Uefi/StubFunctions.c @@ -11,6 +11,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
+#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#include <sys/featuretest.h>
#include <namespace.h>
@@ -25,7 +26,8 @@ getpwuid (uid_t uid) return NULL;
}
-char *getlogin (void)
+char *
+getlogin (void)
{
errno = EPERM;
return NULL;
@@ -38,40 +40,53 @@ getpwnam (const char *name) return NULL;
}
-uid_t getuid (void)
+uid_t
+getuid (void)
{
return 0;
}
-pid_t fork (void)
+pid_t
+getpid(void)
+{
+ return 0;
+}
+
+pid_t
+fork (void)
{
errno = EPERM;
return (-1);
}
-int chmod (const char *c, mode_t m)
+int
+chmod (const char *c, mode_t m)
{
errno = EPERM;
return (-1);
}
-pid_t wait(int *stat_loc) {
+pid_t
+wait(int *stat_loc) {
return 0;
}
-FILE *popen (const char *cmd, const char *type)
+FILE *
+popen (const char *cmd, const char *type)
{
errno = EPERM;
return NULL;
}
-int pclose (FILE *stream)
+int
+pclose (FILE *stream)
{
errno = EPERM;
return -1;
}
-int access (const char *path, int amode)
+mode_t
+umask(mode_t cmask)
{
- return 0;
+ return (mode_t)0;
}
diff --git a/StdLib/LibC/Uefi/SysCalls.c b/StdLib/LibC/Uefi/SysCalls.c index b5079e2c3a..90d7277f86 100644 --- a/StdLib/LibC/Uefi/SysCalls.c +++ b/StdLib/LibC/Uefi/SysCalls.c @@ -31,12 +31,13 @@ #include <sys/fcntl.h>
#include <sys/stat.h>
#include <sys/syslimits.h>
+#include <sys/filio.h>
#include <Efi/SysEfi.h>
+#include <unistd.h>
#include <kfile.h>
#include <Device/Device.h>
#include <MainData.h>
-#include <extern.h> // Library/include/extern.h: Private to implementation
-#include <sys/EfiSysCall.h>
+#include <extern.h>
/* EFI versions of BSD system calls used in stdio */
@@ -136,6 +137,13 @@ isatty (int fd) return retval;
}
+/** Determine if file descriptor fd is a duplicate of some other fd.
+
+ @param[in] fd The file descriptor to check.
+
+ @retval TRUE fd is a duplicate of another fd.
+ @retval FALSE fd is unique.
+**/
static BOOLEAN
IsDupFd( int fd)
{
@@ -161,6 +169,14 @@ IsDupFd( int fd) return Ret;
}
+/** Close a file and set its fd to the specified state.
+
+ @param[in] fd The file descriptor to close.
+ @param[in] NewState State to set the fd to after the file is closed.
+
+ @retval 0 The operation completed successfully.
+ @retval -1 The operation failed. Further information is in errno.
+**/
static int
_closeX (int fd, int NewState)
{
@@ -199,19 +215,18 @@ _closeX (int fd, int NewState) return retval;
}
-/** The close() function shall deallocate the file descriptor indicated by fd.
+/** The close() function deallocates the file descriptor indicated by fd.
To deallocate means to make the file descriptor available for return by
subsequent calls to open() or other functions that allocate file
descriptors. All outstanding record locks owned by the process on the file
- associated with the file descriptor shall be removed (that is, unlocked).
+ associated with the file descriptor are removed (that is, unlocked).
- @return Upon successful completion, 0 shall be returned; otherwise,
- -1 shall be returned and errno set to indicate the error.
+ @retval 0 Successful completion.
+ @retval -1 An error occurred and errno is set to identify the error.
**/
int
close (int fd)
{
- //Print(L"Closing fd %d\n", fd);
return _closeX(fd, 0);
}
@@ -348,7 +363,7 @@ fcntl (int fildes, int cmd, ...) errno = EINVAL;
}
break;
- //case F_SETFD:
+
case F_SETFL:
retval = MyFd->Oflags; // Get original value
temp = va_arg(p3, int);
@@ -356,7 +371,7 @@ fcntl (int fildes, int cmd, ...) temp |= retval & O_SETMASK;
MyFd->Oflags = temp; // Set new value
break;
- //case F_SETFL:
+
case F_SETFD:
retval = MyFd->f_iflags;
break;
@@ -365,11 +380,9 @@ fcntl (int fildes, int cmd, ...) // MyFd->SocProc = va_arg(p3, int);
// break;
case F_GETFD:
- //retval = MyFd->Oflags;
retval = MyFd->f_iflags;
break;
case F_GETFL:
- //retval = MyFd->f_iflags;
retval = MyFd->Oflags;
break;
//case F_GETOWN:
@@ -520,7 +533,7 @@ mkdir (const char *path, __mode_t perms) wchar_t *NewPath;
DeviceNode *Node;
char *GenI;
- RETURN_STATUS Status;
+ RETURN_STATUS Status;
int Instance = 0;
int retval = 0;
@@ -860,6 +873,8 @@ rmdir( filp = &gMD->fdarray[fd];
retval = filp->f_ops->fo_rmdir(filp);
+ filp->f_iflags = 0; // Close this FD
+ filp->RefCount = 0; // No one using this FD
}
return retval;
}
@@ -962,8 +977,22 @@ ioctl( if(ValidateFD( fd, VALID_OPEN)) {
filp = &gMD->fdarray[fd];
+
+ if(request == FIODLEX) {
+ /* set Delete-on-Close */
+ filp->f_iflags |= FIF_DELCLOSE;
+ retval = 0;
+ }
+ else if(request == FIONDLEX) {
+ /* clear Delete-on-Close */
+ filp->f_iflags &= ~FIF_DELCLOSE;
+ retval = 0;
+ }
+ else {
+ /* All other requests. */
retval = filp->f_ops->fo_ioctl(filp, request, argp);
}
+ }
else {
errno = EBADF;
}
@@ -1101,18 +1130,21 @@ write (int fd, const void *buf, size_t nbyte) /** Gets the current working directory.
The getcwd() function shall place an absolute pathname of the current
- working directory in the array pointed to by buf, and return buf. The
- pathname copied to the array shall contain no components that are
- symbolic links. The size argument is the size in bytes of the character
- array pointed to by the buf argument.
+ working directory in the array pointed to by buf, and return buf.The
+ size argument is the size in bytes of the character array pointed to
+ by the buf argument.
@param[in,out] buf The buffer to fill.
@param[in] size The number of bytes in buffer.
- @retval NULL The function failed.
- @retval NULL Buf was NULL.
- @retval NULL Size was 0.
- @return buf The function completed successfully. See errno for info.
+ @retval NULL The function failed. The value in errno provides
+ further information about the cause of the failure.
+ Values for errno are:
+ - EINVAL: buf is NULL or size is zero.
+ - ENOENT: directory does not exist.
+ - ERANGE: buf size is too small to hold CWD
+
+ @retval buf The function completed successfully.
**/
char
*getcwd (char *buf, size_t size)
@@ -1126,14 +1158,13 @@ char Cwd = ShellGetCurrentDir(NULL);
if (Cwd == NULL) {
- errno = EACCES;
+ errno = ENOENT;
return NULL;
}
if (size < ((StrLen (Cwd) + 1) * sizeof (CHAR8))) {
errno = ERANGE;
return (NULL);
}
-
return (UnicodeStrToAsciiStr(Cwd, buf));
}
@@ -1146,7 +1177,14 @@ char @param[in] path The new path to set.
- @todo Add non-shell CWD changing.
+ @retval 0 Operation completed successfully.
+ @retval -1 Function failed. The value in errno provides more
+ information on the cause of failure:
+ - EPERM: Operation not supported with this Shell version.
+ - ENOMEM: Unable to allocate memory.
+ - ENOENT: Target directory does not exist.
+
+ @todo Add non-NEW-shell CWD changing.
**/
int
chdir (const char *path)
@@ -1155,6 +1193,8 @@ chdir (const char *path) EFI_STATUS Status;
CHAR16 *UnicodePath;
+ /* Old Shell does not support Set Current Dir. */
+ if(gEfiShellProtocol != NULL) {
Cwd = ShellGetCurrentDir(NULL);
if (Cwd != NULL) {
/* We have shell support */
@@ -1167,15 +1207,15 @@ chdir (const char *path) Status = gEfiShellProtocol->SetCurDir(NULL, UnicodePath);
FreePool(UnicodePath);
if (EFI_ERROR(Status)) {
- errno = EACCES;
+ errno = ENOENT;
return -1;
} else {
return 0;
}
}
-
+ }
/* Add here for non-shell */
- errno = EACCES;
+ errno = EPERM;
return -1;
}
@@ -1189,3 +1229,33 @@ pid_t getpgrp(void) return ((pid_t)(UINTN)(gImageHandle));
}
+/** Set file access and modification times.
+
+ @param[in] path
+ @param[in] times
+
+ @return
+**/
+int
+utimes(
+ const char *path,
+ const struct timeval *times
+ )
+{
+ struct __filedes *filp;
+ va_list ap;
+ int fd;
+ int retval = -1;
+
+ va_start(ap, path);
+ fd = open(path, O_RDWR, 0);
+ if(fd >= 0) {
+ filp = &gMD->fdarray[fd];
+ retval = filp->f_ops->fo_ioctl( filp, FIOSETIME, ap);
+ close(fd);
+ }
+ va_end(ap);
+ return retval;
+
+}
+
diff --git a/StdLib/LibC/Uefi/Uefi.inf b/StdLib/LibC/Uefi/Uefi.inf index f17a26eea2..71bcb37f02 100644 --- a/StdLib/LibC/Uefi/Uefi.inf +++ b/StdLib/LibC/Uefi/Uefi.inf @@ -52,4 +52,5 @@ LibLocale
LibString
LibTime
+ LibGen
DevUtility
diff --git a/StdLib/LibC/Uefi/Xform.c b/StdLib/LibC/Uefi/Xform.c index 6b15da3563..ecf51d6b0f 100644 --- a/StdLib/LibC/Uefi/Xform.c +++ b/StdLib/LibC/Uefi/Xform.c @@ -57,8 +57,9 @@ Oflags2EFI( int oflags ) return flags;
}
-/* Transform the permissions flags from the open() call into the
- Attributes bits needed by UEFI.
+/* Transform the permissions flags into their equivalent UEFI File Attribute bits.
+ This transformation is most frequently used when translating attributes for use
+ by the UEFI EFI_FILE_PROTOCOL.SetInfo() function.
The UEFI File attributes are:
// ******************************************************
@@ -72,27 +73,40 @@ Oflags2EFI( int oflags ) #define EFI_FILE_ARCHIVE 0x0000000000000020
#define EFI_FILE_VALID_ATTR 0x0000000000000037
- The input permission flags consist of two groups:
- ( S_IRUSR | S_IRGRP | S_IROTH ) -- S_ACC_READ
- ( S_IWUSR | S_IWGRP | S_IWOTH ) -- S_ACC_WRITE
-
- The only thing we can set, at this point, is whether or not
- this is a SYSTEM file. If the group and other bits are
- zero and the user bits are non-zero then set SYSTEM. Otherwise
- the attributes are zero.
-
- The attributes can be set later using fcntl().
+ The input permission flags consist of the following flags:
+ O_RDONLY -- open for reading only
+ O_WRONLY -- open for writing only
+ O_RDWR -- open for reading and writing
+ O_ACCMODE -- mask for above modes
+ O_NONBLOCK -- no delay
+ O_APPEND -- set append mode
+ O_CREAT -- create if nonexistent
+ O_TRUNC -- truncate to zero length
+ O_EXCL -- error if already exists
+ O_HIDDEN -- Hidden file attribute
+ O_SYSTEM -- System file attribute
+ O_ARCHIVE -- Archive file attribute
*/
UINT64
Omode2EFI( int mode)
{
UINT64 flags = 0;
- if((mode & (S_IRWXG | S_IRWXO)) == 0) {
- if((mode & S_IRWXU) != 0) {
- // Only user permissions so set system
- flags = EFI_FILE_SYSTEM;
+ /* File is Read-Only. */
+ if((mode & O_ACCMODE) == 0) {
+ flags = EFI_FILE_READ_ONLY;
+ }
+ /* Set the Hidden attribute. */
+ if((mode & O_HIDDEN) != 0) {
+ flags |= EFI_FILE_HIDDEN;
+ }
+ /* Set the System attribute. */
+ if((mode & O_SYSTEM) != 0) {
+ flags |= EFI_FILE_SYSTEM;
}
+ /* Set the Archive attribute. */
+ if((mode & O_ARCHIVE) != 0) {
+ flags |= EFI_FILE_ARCHIVE;
}
return flags;
}
diff --git a/StdLib/PosixLib/Gen/LibGen.inf b/StdLib/PosixLib/Gen/LibGen.inf index 0a2ab188fd..5a54686f6e 100644 --- a/StdLib/PosixLib/Gen/LibGen.inf +++ b/StdLib/PosixLib/Gen/LibGen.inf @@ -31,6 +31,8 @@ opendir.c
closedir.c
readdir.c
+ access.c
+ utime.c
[Packages]
MdePkg/MdePkg.dec
diff --git a/StdLib/PosixLib/Gen/access.c b/StdLib/PosixLib/Gen/access.c new file mode 100644 index 0000000000..3031e4f942 --- /dev/null +++ b/StdLib/PosixLib/Gen/access.c @@ -0,0 +1,118 @@ +/** @file
+ Implementation of the Posix access() function.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/syslimits.h>
+
+/** Save some typing later on. */
+#define GOOD_MODE (F_OK | X_OK | W_OK | R_OK)
+
+/** Determine accessibility of a file.
+ The access() function checks the file, named by the pathname pointed to by
+ the Path argument, for accessibility according to the bit pattern contained
+ in Mode.
+
+ The value of Mode is either the bitwise-inclusive OR of the access
+ permissions to be checked (R_OK, W_OK, X_OK) or the existence test (F_OK).
+
+ If Path ends in '/' or '\\', the target must be a directory, otherwise it doesn't matter.
+ A file is executable if it is NOT a directory and it ends in ".efi".
+
+ @param[in] Path Path or name of the file to be checked.
+ @param[in] Mode Access permissions to check for.
+
+ @retval 0 Successful completion.
+ @retval -1 File is not accessible with the given Mode. The error condition
+ is indicated by errno. Values of errno specific to the access
+ function include: EACCES, ENOENT, ENOTDIR, ENAMETOOLONG
+**/
+int
+access(
+ const char *Path,
+ int Mode
+ )
+{
+ struct stat FileStat;
+ int retval = -1;
+ size_t PLength;
+ uint32_t WantDir;
+ uint32_t DirMatch;
+
+ if((Path == NULL) || ((Mode & ~GOOD_MODE) != 0)) {
+ errno = EINVAL;
+ }
+ else {
+ PLength = strlen(Path);
+ if(PLength > PATH_MAX) {
+ errno = ENAMETOOLONG;
+ }
+ else {
+ retval = stat(Path, &FileStat);
+ if(retval == 0) {
+ /* Path exists. FileStat now holds valid information. */
+ WantDir = isDirSep(Path[PLength - 1]); // Does Path end in '/' or '\\' ?
+ DirMatch = (! WantDir && (! S_ISDIR(FileStat.st_mode)));
+
+ /* Test each permission individually. */
+ do {
+ if(Mode == F_OK) { /* Existence test. */
+ if(DirMatch) { /* This is a directory or file as desired. */
+ retval = 0;
+ }
+ else {
+ /* Indicate why we failed the test. */
+ errno = (WantDir) ? ENOTDIR : EISDIR;
+ }
+ break; /* F_OK does not combine with any other tests. */
+ }
+ if(Mode & R_OK) {
+ if((FileStat.st_mode & READ_PERMS) == 0) {
+ /* No read permissions.
+ For UEFI, everything should have READ permissions.
+ */
+ errno = EDOOFUS; /* Programming Error. */
+ break;
+ }
+ }
+ if(Mode & W_OK) {
+ if((FileStat.st_mode & WRITE_PERMS) == 0) {
+ /* No write permissions. */
+ errno = EACCES; /* Writing is not OK. */
+ break;
+ }
+ }
+ if(Mode & X_OK) {
+ /* In EDK II, executable files end in ".efi" */
+ if(strcmp(&Path[PLength-4], ".efi") != 0) {
+ /* File is not an executable. */
+ errno = EACCES;
+ break;
+ }
+ }
+ retval = 0;
+ } while(FALSE);
+ }
+ else {
+ /* File or path does not exist. */
+ errno = ENOENT;
+ }
+ }
+ }
+ return retval;
+}
diff --git a/StdLib/PosixLib/Gen/dirname.c b/StdLib/PosixLib/Gen/dirname.c index 7fb4d39a0f..eb924d435c 100644 --- a/StdLib/PosixLib/Gen/dirname.c +++ b/StdLib/PosixLib/Gen/dirname.c @@ -1,5 +1,14 @@ /** @file
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
* Copyright (c) 1997, 2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
@@ -30,19 +39,17 @@ NetBSD: dirname.c,v 1.10 2008/05/10 22:39:40 christos Exp
*/
#include <LibConfig.h>
-
#include <sys/cdefs.h>
-//#include "namespace.h"
-//#include <libgen.h>
#include <limits.h>
+#include <ctype.h>
#include <string.h>
#ifdef __weak_alias
__weak_alias(dirname,_dirname)
#endif
-#if !HAVE_DIRNAME
+#ifdef HAVE_DIRNAME
char *
dirname(char *path)
{
@@ -60,24 +67,34 @@ dirname(char *path) /* Strip trailing slashes, if any. */
lastp = path + strlen(path) - 1;
- while (lastp != path && *lastp == '/')
+ while (lastp != path && isDirSep(*lastp))
lastp--;
/* Terminate path at the last occurence of '/'. */
do {
- if (*lastp == '/') {
+ if (isDirSep(*lastp)) {
/* Strip trailing slashes, if any. */
- while (lastp != path && *lastp == '/')
+ while (lastp != path && isDirSep(*lastp))
lastp--;
- /* ...and copy the result into the result buffer. */
+ /* ...and copy the result into the result buffer.
+ We make sure that there will be room for the terminating NUL
+ and for a final '/', if necessary.
+ */
len = (lastp - path) + 1 /* last char */;
- if (len > (PATH_MAX - 1))
- len = PATH_MAX - 1;
+ if (len > (PATH_MAX - 2))
+ len = PATH_MAX - 2;
memcpy(result, path, len);
+ if(*lastp == ':') { /* Have we stripped off all except the Volume name? */
+ if(isDirSep(lastp[1])) { /* Was ...":/"... so we want the root of the volume. */
+ result[len++] = '/';
+ }
+ else {
+ result[len++] = '.';
+ }
+ }
result[len] = '\0';
-
return (result);
}
} while (--lastp >= path);
diff --git a/StdLib/PosixLib/Gen/readdir.c b/StdLib/PosixLib/Gen/readdir.c index b8ad0af2a3..13c4eaec07 100644 --- a/StdLib/PosixLib/Gen/readdir.c +++ b/StdLib/PosixLib/Gen/readdir.c @@ -54,8 +54,6 @@ #include <string.h>
#include <unistd.h>
-#include <sys/EfiSysCall.h>
-
/*
* get next entry in a directory.
*/
diff --git a/StdLib/PosixLib/Gen/utime.c b/StdLib/PosixLib/Gen/utime.c new file mode 100644 index 0000000000..9cb8b5b50b --- /dev/null +++ b/StdLib/PosixLib/Gen/utime.c @@ -0,0 +1,73 @@ +/** @file
+ Set file access and modification times.
+
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+ NetBSD: utime.c,v 1.12 2003/08/07 16:42:59 agc Exp
+ utime.c 8.1 (Berkeley) 6/4/93
+ */
+#include <LibConfig.h>
+#include <sys/EfiCdefs.h>
+
+#include "namespace.h"
+#include <sys/time.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stddef.h>
+#include <utime.h>
+
+int
+utime(
+ const char *path,
+ const struct utimbuf *times
+ )
+{
+ struct timeval tv[2], *tvp;
+
+ _DIAGASSERT(path != NULL);
+
+ if (times == (struct utimbuf *) NULL)
+ tvp = NULL;
+ else {
+ tv[0].tv_sec = times->actime;
+ tv[1].tv_sec = times->modtime;
+ tv[0].tv_usec = tv[1].tv_usec = 0;
+ tvp = tv;
+ }
+ return (utimes(path, tvp));
+}
|