\r
Concept derived from NetBSD's unistd.h file.\r
\r
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials are licensed and made available under\r
the terms and conditions of the BSD License that accompanies this distribution.\r
The full text of the license may be found at\r
#include <sys/EfiCdefs.h>\r
#include <sys/types.h>\r
\r
-struct stat; // Structure declared in <sys/stat.h>\r
+struct stat; /* Structure declared in <sys/stat.h> */\r
\r
#define STDIN_FILENO 0 /* standard input file descriptor */\r
#define STDOUT_FILENO 1 /* standard output file descriptor */\r
#define W_OK 0x02 /* test for write permission */\r
#define R_OK 0x04 /* test for read permission */\r
\r
-/* whence values for lseek(2) */\r
-#define SEEK_SET 0 /* set file offset to offset */\r
-#define SEEK_CUR 1 /* set file offset to current plus offset */\r
-#define SEEK_END 2 /* set file offset to EOF plus offset */\r
+/* whence values for lseek(2)\r
+ Always ensure that these are consistent with <stdio.h> and <unistd.h>!\r
+*/\r
+#ifndef SEEK_SET\r
+ #define SEEK_SET 0 /* set file offset to offset */\r
+#endif\r
+#ifndef SEEK_CUR\r
+ #define SEEK_CUR 1 /* set file offset to current plus offset */\r
+#endif\r
+#ifndef SEEK_END\r
+ #define SEEK_END 2 /* set file offset to EOF plus offset */\r
+#endif\r
+\r
+// Parameters for the ValidateFD function.\r
+#define VALID_OPEN 1\r
+#define VALID_CLOSED 0\r
+#define VALID_DONT_CARE -1\r
\r
__BEGIN_DECLS\r
\r
/* EFI versions of BSD system calls used in stdio */\r
-extern int close (int fd);\r
-extern ssize_t read (int fd, void *buf, size_t n);\r
-extern ssize_t write (int fd, const void *buf, size_t n);\r
-extern int unlink (const char *name);\r
-extern int dup2 (int, int);\r
-extern int rmdir (const char *);\r
-extern int isatty (int);\r
+int close (int fd);\r
+ssize_t read (int fd, void *buf, size_t n);\r
+ssize_t write (int fd, const void *buf, size_t n);\r
+int unlink (const char *name);\r
+int dup2 (int, int);\r
+int rmdir (const char *);\r
+int isatty (int);\r
\r
/* These system calls are also declared in sys/fcntl.h */\r
#ifndef __FCNTL_SYSCALLS_DECLARED\r
#define __FCNTL_SYSCALLS_DECLARED\r
- extern int open (const char *name, int oflags, int mode);\r
- extern int creat (const char *, mode_t);\r
- extern int fcntl (int, int, ...);\r
+ int open (const char *name, int oflags, int mode);\r
+ int creat (const char *, mode_t);\r
+ int fcntl (int, int, ...);\r
#endif // __FCNTL_SYSCALLS_DECLARED\r
\r
/* These system calls are also declared in stat.h */\r
#ifndef __STAT_SYSCALLS_DECLARED\r
#define __STAT_SYSCALLS_DECLARED\r
- extern int mkdir (const char *, mode_t);\r
- extern int fstat (int, struct stat *);\r
- extern int lstat (const char *, struct stat *);\r
- extern int stat (const char *, void *);\r
-// extern int chmod (const char *, mode_t);\r
+ int mkdir (const char *, mode_t);\r
+ int fstat (int, struct stat *);\r
+ int lstat (const char *, struct stat *);\r
+ int stat (const char *, void *);\r
+// int chmod (const char *, mode_t);\r
#endif // __STAT_SYSCALLS_DECLARED\r
\r
// These are also declared in sys/types.h\r
#ifndef __OFF_T_SYSCALLS_DECLARED\r
#define __OFF_T_SYSCALLS_DECLARED\r
- extern off_t lseek (int, off_t, int);\r
- extern int truncate (const char *, off_t);\r
- extern int ftruncate (int, off_t); // IEEE Std 1003.1b-93\r
+ off_t lseek (int, off_t, int);\r
+ int truncate (const char *, off_t);\r
+ int ftruncate (int, off_t); // IEEE Std 1003.1b-93\r
#endif /* __OFF_T_SYSCALLS_DECLARED */\r
\r
+/* EFI-specific Functions. */\r
+int DeleteOnClose(int fd); /* Mark an open file to be deleted when closed. */\r
+\r
+/* Find and reserve a free File Descriptor.\r
+\r
+ Returns the first free File Descriptor greater than or equal to the,\r
+ already validated, fd specified by Minfd.\r
+\r
+ @return Returns -1 if there are no free FDs. Otherwise returns the\r
+ found fd.\r
+*/\r
+int FindFreeFD (int MinFd);\r
+\r
+/* Validate that fd refers to a valid file descriptor.\r
+ IsOpen is interpreted as follows:\r
+ - Positive fd must be OPEN\r
+ - Zero fd must be CLOSED\r
+ - Negative fd may be OPEN or CLOSED\r
+\r
+ @retval TRUE fd is VALID\r
+ @retval FALSE fd is INVALID\r
+*/\r
+BOOLEAN ValidateFD (int fd, int IsOpen);\r
+\r
/* These system calls don't YET have EFI implementations. */\r
-extern int access (const char *path, int amode);\r
-extern int chdir (const char *);\r
-extern char *getcwd (char *, size_t);\r
-extern int reboot (int, char *);\r
+int access (const char *path, int amode);\r
+int chdir (const char *);\r
+char *getcwd (char *, size_t);\r
+int reboot (int, char *);\r
\r
__END_DECLS\r
\r