summaryrefslogtreecommitdiff
path: root/StdLib/Include
diff options
context:
space:
mode:
authordarylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524>2011-11-30 00:52:45 +0000
committerdarylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524>2011-11-30 00:52:45 +0000
commit0c1992fbccd139e9d3bb730c19a79847c6a5a246 (patch)
tree39ea4e848572274ead5dddc7095c14ca1898b9f2 /StdLib/Include
parent8f04ca1a8f3828da0041f96c5cb9f597b3d3e614 (diff)
downloadedk2-0c1992fbccd139e9d3bb730c19a79847c6a5a246.zip
edk2-0c1992fbccd139e9d3bb730c19a79847c6a5a246.tar.gz
edk2-0c1992fbccd139e9d3bb730c19a79847c6a5a246.tar.bz2
StdLib: Add isDirSep character classification macro and function. Implement several Posix functions and clean up EfiSysCall.h. Align file mode handling with UEFI file protocol flags.
Include/ctype.h: Function declaration and Macro definition of isDirSep Include/unistd.h: Declarations added from EfiSysCall.h Include/utime.h: New file. For the Posix utime() function. Include/sys/_ctype.h: Update character class bit maps. Include/sys/EfiSysCall.h: Move declarations to unistd.h Include/sys/fcntl.h: Improve comments. Add UEFI-specific macros. Include/sys/filio.h: Remove declarations for unsupported file ioctls. Include/sys/stat.h: Fix flags. Add macros and declarations. Include/sys/time.h: Add declarations for new functions Tm2Efi() and Time2Efi(). Include/sys/types.h: Use EFI-specific instead of BSD-specific definitions for typedefs. Include/sys/unistd.h: Delete inappropriate content. Guard macro definitions. LibC/Locale/setlocale.c LibC/Stdio/{fdopen.c, findfp.c, fopen.c, freopen.c, gettemp.c, makebuf.c, mktemp.c, remove.c, stdio.c, tempnam.c, tmpfile.c, tmpnam.c} LibC/Time/{itimer.c, ZoneProc.c} LibC/Uefi/SysCalls.c LibC/Uefi/Devices/Console/daConsole.c LibC/Uefi/Devices/UefiShell/daShell.c PosixLib/Gen/readdir.c Include unistd.h instead of EfiSysCall.h LibC/Ctype/CClass.c: Character classification function implementation for isDirSep. LibC/Ctype/iCtype.c: Update character classification and case conversion tables. LibC/Time/TimeEfi.c: Improve comments. Implement new functions Tm2Efi() and Time2Efi(). LibC/Uefi/StubFunctions.c: Add missing include. Cosmetic changes to declarations. LibC/Uefi/SysCalls.c: Add support function for utime(). LibC/Uefi/Uefi.inf: Add LibGen library class dependency. LibC/Uefi/Xform.c: Enhance Omode2EFI(). LibC/Uefi/Devices/UefiShell/daShell.c: Enhance da_ShellMkdir. Implement da_ShellIoctl to set file times. PosixLib/Gen/access.c: New file. Implement the access() function. PosixLib/Gen/dirname.c: Enhance to use isDirSep and differentiate between the device, path, and filename components of UEFI Shell-style paths. PosixLib/Gen/utime.c: New file. Implement the utime() function. PosixLib/Gen/LibGen.inf: Change MODULE_TYPE. Add new files. Signed-off-by: darylm503 Reviewed-by: geekboy15a Reviewed-by: jljusten Reviewed-by: Rahul Khana Reviewed-by: leegrosenbaum git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12800 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'StdLib/Include')
-rw-r--r--StdLib/Include/ctype.h15
-rw-r--r--StdLib/Include/sys/EfiSysCall.h148
-rw-r--r--StdLib/Include/sys/_ctype.h6
-rw-r--r--StdLib/Include/sys/fcntl.h15
-rw-r--r--StdLib/Include/sys/filio.h45
-rw-r--r--StdLib/Include/sys/stat.h24
-rw-r--r--StdLib/Include/sys/time.h14
-rw-r--r--StdLib/Include/sys/types.h4
-rw-r--r--StdLib/Include/sys/unistd.h145
-rw-r--r--StdLib/Include/unistd.h66
-rw-r--r--StdLib/Include/utime.h66
11 files changed, 285 insertions, 263 deletions
diff --git a/StdLib/Include/ctype.h b/StdLib/Include/ctype.h
index fb0e2fd..d35367f 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 1d01328..cbaf1d1 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 6c2b327..cb06ec0 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 d41af5c..b91792f 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 65f34bc..e514c26 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 f953858..6c5d5a8 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 b8957f4..2b05b11 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 408d743..54ae008 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 a63d88d..274e29f 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 4d738c6..b2fd923 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 0000000..744881c
--- /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_ */