Home | History | Annotate | Download | only in Include
      1 /** @file
      2 
      3   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
      4   This program and the accompanying materials are licensed and made available under
      5   the terms and conditions of the BSD License that accompanies this distribution.
      6   The full text of the license may be found at
      7   http://opensource.org/licenses/bsd-license.
      8 
      9   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     10   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     11 
     12 **/
     13 #ifndef _UNISTD_H_
     14 #define _UNISTD_H_
     15 
     16 //#include <machine/ansi.h>
     17 //#include <machine/int_types.h>
     18 //#include <sys/featuretest.h>
     19 //#include <sys/types.h>
     20 #include  <sys/unistd.h>
     21 #include  <sys/EfiSysCall.h>
     22 
     23 #define F_ULOCK   0
     24 #define F_LOCK    1
     25 #define F_TLOCK   2
     26 #define F_TEST    3
     27 
     28 /* access function */
     29 #define F_OK      0     /* test for existence of file */
     30 #define X_OK      0x01  /* test for execute or search permission */
     31 #define W_OK      0x02  /* test for write permission */
     32 #define R_OK      0x04  /* test for read permission */
     33 
     34 
     35 __BEGIN_DECLS
     36 int             dup(int);
     37 int             rename(const char *, const char *);
     38 
     39 /* Functions implemented for compatibility. */
     40 int             getopt(int, char * const [], const char *);
     41 extern   char  *optarg;     /* getopt(3) external variables */
     42 extern   int    optind;
     43 pid_t           getpgrp(void);
     44 pid_t           tcgetpgrp(int);
     45 char           *getpass(const char *);
     46 int             usleep(useconds_t);
     47 unsigned int    sleep(unsigned int);
     48 char           *basename(char *path);
     49 
     50 #ifndef GETCWD_DECLARED
     51   /** Gets the current working directory.
     52 
     53   The getcwd() function shall place an absolute pathname of the current
     54   working directory in the array pointed to by buf, and return buf. The
     55   pathname copied to the array shall contain no components that are
     56   symbolic links. The size argument is the size in bytes of the character
     57   array pointed to by the buf argument.
     58 
     59   @param[in,out] Buf        The buffer to fill.
     60   @param[in]     BufSize    The number of bytes in buffer.
     61 
     62   @retval NULL          The function failed.
     63   @retval NULL          Buf was NULL.
     64   @retval NULL          Size was 0.
     65   @return buf           The function completed successfully. See errno for info.
     66   **/
     67   char           *getcwd(char *Buf, size_t BufSize);
     68   #define GETCWD_DECLARED
     69 #endif
     70 
     71 #ifndef CHDIR_DECLARED
     72   /** Change the current working directory.
     73 
     74   The chdir() function shall cause the directory named by the pathname
     75   pointed to by the path argument to become the current working directory;
     76   that is, the starting point for path searches for pathnames not beginning
     77   with '/'.
     78 
     79   @param[in] Path   The new path to set.
     80 
     81   @todo Add non-shell CWD changing.
     82   **/
     83   int       chdir(const char *Path);
     84 #define CHDIR_DECLARED
     85 #endif
     86 
     87 /** Determine accessibility of a file.
     88     The access() function checks the file, named by the pathname pointed to by
     89     the Path argument, for accessibility according to the bit pattern contained
     90     in Mode.
     91 
     92     The value of Mode is either the bitwise-inclusive OR of the access
     93     permissions to be checked (R_OK, W_OK, X_OK) or the existence test (F_OK).
     94 
     95     If Path ends in '/' or '\\', the target must be a directory, otherwise it doesn't matter.
     96     A file is executable if it is NOT a directory and it ends in ".efi".
     97 
     98     @param[in]    Path    Path or name of the file to be checked.
     99     @param[in]    Mode    Access permissions to check for.
    100 
    101     @retval   0   Successful completion.
    102     @retval  -1   File is not accessible with the given Mode.  The error condition
    103                   is indicated by errno.  Values of errno specific to the access
    104                   function include: EACCES, ENOENT, ENOTDIR, ENAMETOOLONG
    105 **/
    106 int             access(const char *Path, int Mode);
    107 pid_t           getpid(void);
    108 
    109 // Networking
    110 long            gethostid(void);
    111 int             gethostname(char *, size_t);
    112 int             getdomainname(char *, size_t);
    113 int             setdomainname(const char *, size_t);
    114 int             sethostid(long);
    115 int             sethostname(const char *, size_t);
    116 
    117 /*  Stub functions implemented for porting ease.
    118     These functions always fail or return NULL.
    119 */
    120 __aconst char  *getlogin(void);
    121 pid_t           fork(void);
    122 uid_t           getuid(void);
    123 
    124 // For Future implementation
    125 ssize_t         pread(int, void *, size_t, off_t);
    126 ssize_t         pwrite(int, const void *, size_t, off_t);
    127 int             syscall(int, ...);
    128 
    129 #if 0   // The following functions are not implemented
    130 __dead   void   _exit(int) __attribute__((__noreturn__));
    131 unsigned int    alarm(unsigned int);
    132 int             chown(const char *, uid_t, gid_t);
    133 size_t          confstr(int, char *, size_t);
    134 int             execl(const char *, const char *, ...);
    135 int             execle(const char *, const char *, ...);
    136 int             execlp(const char *, const char *, ...);
    137 int             execv(const char *, char * const *);
    138 int             execve(const char *, char * const *, char * const *);
    139 int             execvp(const char *, char * const *);
    140 long            fpathconf(int, int);
    141 gid_t           getegid(void);
    142 uid_t           geteuid(void);
    143 gid_t           getgid(void);
    144 int             getgroups(int, gid_t []);
    145 pid_t           getppid(void);
    146 int             link(const char *, const char *);
    147 long            pathconf(const char *, int);
    148 int             pause(void);
    149 int             pipe(int *);
    150 int             setgid(gid_t);
    151 int             setpgid(pid_t, pid_t);
    152 pid_t           setsid(void);
    153 int             setuid(uid_t);
    154 long            sysconf(int);
    155 
    156 int             tcsetpgrp(int, pid_t);
    157 __aconst char  *ttyname(int);
    158 
    159 extern   int    opterr;
    160 extern   int    optopt;
    161 extern   int    optreset;
    162 extern   char  *suboptarg;
    163 
    164 int             setegid(gid_t);
    165 int             seteuid(uid_t);
    166 int             fdatasync(int);
    167 int             fsync(int);
    168 int             ttyname_r(int, char *, size_t);
    169 int             chroot(const char *);
    170 int             nice(int);
    171 __aconst char *crypt(const char *, const char *);
    172 int             encrypt(char *, int);
    173 pid_t           getsid(pid_t);
    174 
    175 #ifndef intptr_t
    176 typedef __intptr_t  intptr_t;
    177 #define intptr_t  __intptr_t
    178 #endif
    179 
    180 int             brk(void *);
    181 int             fchdir(int);
    182 int             fchown(int, uid_t, gid_t);
    183 int             getdtablesize(void);
    184 __pure int      getpagesize(void);    /* legacy */
    185 pid_t           getpgid(pid_t);
    186 int             lchown(const char *, uid_t, gid_t);
    187 int             lockf(int, int, off_t);
    188 ssize_t         readlink(const char * __restrict, char * __restrict, size_t);
    189 void           *sbrk(intptr_t);
    190 int             setregid(gid_t, gid_t);
    191 int             setreuid(uid_t, uid_t);
    192 void            swab(const void *, void *, size_t);
    193 int             symlink(const char *, const char *);
    194 void            sync(void);
    195 useconds_t      ualarm(useconds_t, useconds_t);
    196 pid_t           vfork(void) __RENAME(__vfork14);
    197 
    198 /*
    199  * Implementation-defined extensions
    200  */
    201 int             acct(const char *);
    202 int             closefrom(int);
    203 int             des_cipher(const char *, char *, long, int);
    204 int             des_setkey(const char *);
    205 void            endusershell(void);
    206 int             exect(const char *, char * const *, char * const *);
    207 int             fchroot(int);
    208 int             fsync_range(int, int, off_t, off_t);
    209 int             getgrouplist(const char *, gid_t, gid_t *, int *);
    210 int             getgroupmembership(const char *, gid_t, gid_t *, int, int *);
    211 mode_t          getmode(const void *, mode_t);
    212 int             getsubopt(char **, char * const *, char **);
    213 __aconst char  *getusershell(void);
    214 int             initgroups(const char *, gid_t);
    215 int             iruserok(uint32_t, int, const char *, const char *);
    216 int             issetugid(void);
    217 int             nfssvc(int, void *);
    218 int             profil(char *, size_t, u_long, u_int);
    219 void            psignal(unsigned int, const char *);
    220 int             rcmd(char **, int, const char *, const char *, const char *, int *);
    221 int             revoke(const char *);
    222 int             rresvport(int *);
    223 int             ruserok(const char *, int, const char *, const char *);
    224 int             setgroups(int, const gid_t *);
    225 int             setlogin(const char *);
    226 void           *setmode(const char *);
    227 int             setrgid(gid_t);
    228 int             setruid(uid_t);
    229 void            setusershell(void);
    230 void            strmode(mode_t, char *);
    231 __aconst char  *strsignal(int);
    232 int             swapctl(int, void *, int);
    233 quad_t          __syscall(quad_t, ...);
    234 int             undelete(const char *);
    235 int             rcmd_af(char **, int, const char *, const char *, const char *, int *, int);
    236 int             rresvport_af(int *, int);
    237 int             iruserok_sa(const void *, int, int, const char *, const char *);
    238 #endif  /* Unimplemented functions. */
    239 
    240 __END_DECLS
    241 
    242 #endif /* !_UNISTD_H_ */
    243